Skip to content

Commit

Permalink
Patched /tmp/tmpetcgbeuw/metagpt/actions/action_node.py
Browse files Browse the repository at this point in the history
  • Loading branch information
patched.codes[bot] committed Oct 21, 2024
1 parent 4f564bd commit 373259b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions metagpt/actions/action_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ def _to_dict(self, format_func=None, mode="auto", exclude=None) -> Dict:
return node_value

def update_instruct_content(self, incre_data: dict[str, Any]):
assert self.instruct_content
try:
if not self.instruct_content:
raise ValueError("instruct_content must exist")
except ValueError as e:
# Handle error, log, or return
return
origin_sc_dict = self.instruct_content.model_dump()
origin_sc_dict.update(incre_data)
output_class = self.create_class()
Expand Down Expand Up @@ -592,16 +597,20 @@ async def simple_review(self, review_mode: ReviewMode = ReviewMode.AUTO):

async def review(self, strgy: str = "simple", review_mode: ReviewMode = ReviewMode.AUTO):
"""only give the review comment of each exist and mismatch key
:param strgy: simple/complex
- simple: run only once
- complex: run each node
"""
if not hasattr(self, "llm"):
raise RuntimeError("use `review` after `fill`")
assert review_mode in ReviewMode
assert self.instruct_content, 'review only support with `schema != "raw"`'


if review_mode not in ReviewMode:
raise ValueError("Invalid review mode")

if not self.instruct_content:
raise ValueError('review only support with `schema != "raw"`')

if strgy == "simple":
review_comments = await self.simple_review(review_mode)
elif strgy == "complex":
Expand All @@ -610,7 +619,7 @@ async def review(self, strgy: str = "simple", review_mode: ReviewMode = ReviewMo
for _, child in self.children.items():
child_review_comment = await child.simple_review(review_mode)
review_comments.update(child_review_comment)

return review_comments

async def human_revise(self) -> dict[str, str]:
Expand Down Expand Up @@ -679,16 +688,20 @@ async def simple_revise(self, revise_mode: ReviseMode = ReviseMode.AUTO) -> dict

async def revise(self, strgy: str = "simple", revise_mode: ReviseMode = ReviseMode.AUTO) -> dict[str, str]:
"""revise the content of ActionNode and update the instruct_content
:param strgy: simple/complex
- simple: run only once
- complex: run each node
"""
if not hasattr(self, "llm"):
raise RuntimeError("use `revise` after `fill`")
assert revise_mode in ReviseMode
assert self.instruct_content, 'revise only support with `schema != "raw"`'


if revise_mode not in ReviseMode:
raise ValueError("Invalid revise mode")

if not self.instruct_content:
raise ValueError("revise only support with `schema != \"raw\"`")

if strgy == "simple":
revise_contents = await self.simple_revise(revise_mode)
elif strgy == "complex":
Expand All @@ -698,7 +711,7 @@ async def revise(self, strgy: str = "simple", revise_mode: ReviseMode = ReviseMo
child_revise_content = await child.simple_revise(revise_mode)
revise_contents.update(child_revise_content)
self.update_instruct_content(revise_contents)

return revise_contents

@classmethod
Expand Down

0 comments on commit 373259b

Please sign in to comment.