mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
Update
This commit is contained in:
parent
8f1cf58af2
commit
fd432fa132
2 changed files with 12 additions and 54 deletions
|
|
@ -8,7 +8,7 @@ from typing import List
|
|||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.llm import LLM
|
||||
|
||||
from examples.ags.w_action_node.operator_an import GENERATE_NODE, GENERATE_CODE_NODE, REVIEW_NODE, REVISE_NODE, ENSEMBLE_NODE
|
||||
from examples.ags.w_action_node.operator_an import GenerateOp, GenerateCodeOp, ReviewOp, ReviseOp, EnsembleOp
|
||||
from examples.ags.w_action_node.prompt import GENERATE_PROMPT, GENERATE_CODE_PROMPT, REVIEW_PROMPT, REVISE_PROMPT, ENSEMBLE_PROMPT
|
||||
|
||||
class Operator:
|
||||
|
|
@ -25,7 +25,7 @@ class Generate(Operator):
|
|||
|
||||
async def __call__(self, problem_description):
|
||||
prompt = GENERATE_PROMPT.format(problem_description=problem_description)
|
||||
node = await GENERATE_NODE.fill(context=prompt, llm=self.llm)
|
||||
node = await ActionNode.from_pydantic(GenerateOp).fill(context=prompt, llm=self.llm)
|
||||
response = node.instruct_content.model_dump()
|
||||
return response
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class GenerateCode(Operator):
|
|||
|
||||
async def __call__(self, problem_description):
|
||||
prompt = GENERATE_CODE_PROMPT.format(problem_description=problem_description)
|
||||
node = await GENERATE_CODE_NODE.fill(context=prompt, llm=self.llm)
|
||||
node = await ActionNode.from_pydantic(GenerateCodeOp).fill(context=prompt, llm=self.llm)
|
||||
response = node.instruct_content.model_dump()
|
||||
return response
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ class Review(Operator):
|
|||
|
||||
async def __call__(self, problem_description, solution):
|
||||
prompt = REVIEW_PROMPT.format(problem_description=problem_description, solution=solution, criteria=self.criteria)
|
||||
node = await REVIEW_NODE.fill(context=prompt, llm=self.llm)
|
||||
node = await ActionNode.from_pydantic(ReviewOp).fill(context=prompt, llm=self.llm)
|
||||
response = node.instruct_content.model_dump()
|
||||
return response
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ class Revise(Operator):
|
|||
|
||||
async def __call__(self, problem_description, solution, feedback):
|
||||
prompt = REVISE_PROMPT.format(problem_description=problem_description, solution=solution, feedback=feedback)
|
||||
node = await REVISE_NODE.fill(context=prompt, llm=self.llm)
|
||||
node = await ActionNode.from_pydantic(ReviseOp).fill(context=prompt, llm=self.llm)
|
||||
response = node.instruct_content.model_dump()
|
||||
return response
|
||||
|
||||
|
|
@ -73,6 +73,6 @@ class Ensemble(Operator):
|
|||
for solution in solutions:
|
||||
solution_text += solution + "\n"
|
||||
prompt = ENSEMBLE_PROMPT.format(solutions=solution_text, problem_description=problem_description)
|
||||
node = await ENSEMBLE_NODE.fill(context=prompt, llm=self.llm)
|
||||
node = await ActionNode.from_pydantic(EnsembleOp).fill(context=prompt, llm=self.llm)
|
||||
response = node.instruct_content.model_dump()
|
||||
return response
|
||||
|
|
@ -6,60 +6,18 @@
|
|||
from pydantic import BaseModel, Field
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
|
||||
SOLUTION = ActionNode(
|
||||
key="solution",
|
||||
expected_type=str,
|
||||
instruction="Your Solution for this problem",
|
||||
example=""
|
||||
)
|
||||
|
||||
CODE_SOLUTION = ActionNode(
|
||||
key="code_solution",
|
||||
expected_type=str,
|
||||
instruction="Your Code Solution for this problem",
|
||||
example=""
|
||||
)
|
||||
|
||||
REVIEW_RESULT = ActionNode(
|
||||
key="review_result",
|
||||
expected_type=bool,
|
||||
instruction="The Review Result (Bool). If you think this solution looks good for you, return 'true'; If not, return 'false'",
|
||||
example=""
|
||||
)
|
||||
|
||||
FEEDBACK = ActionNode(
|
||||
key="feedback",
|
||||
expected_type=str,
|
||||
instruction="Your FeedBack for this problem based on the criteria. If the review result is true, you can put it 'nothing here'.",
|
||||
example=""
|
||||
)
|
||||
|
||||
GENERATE_NODE = ActionNode.from_children("Generate", [SOLUTION])
|
||||
GENERATE_CODE_NODE = ActionNode.from_children("GenerateCode", [CODE_SOLUTION])
|
||||
REVIEW_NODE = ActionNode.from_children("Review", [REVIEW_RESULT, FEEDBACK])
|
||||
REVISE_NODE = ActionNode.from_children("Revise", [SOLUTION])
|
||||
ENSEMBLE_NODE = ActionNode.from_children("Ensemble", [SOLUTION])
|
||||
|
||||
class Generate(BaseModel):
|
||||
class GenerateOp(BaseModel):
|
||||
solution: str = Field(default="", description="Your Solution for this problem")
|
||||
|
||||
class GenerateCode(BaseModel):
|
||||
class GenerateCodeOp(BaseModel):
|
||||
code_solution: str = Field(default="", description="Your Code Solution for this problem")
|
||||
|
||||
class Review(BaseModel):
|
||||
class ReviewOp(BaseModel):
|
||||
review_result: bool = Field(default=False, description="The Review Result (Bool). If you think this solution looks good for you, return 'true'; If not, return 'false'")
|
||||
feedback: str = Field(default="", description="Your FeedBack for this problem based on the criteria. If the review result is true, you can put it 'nothing here'.")
|
||||
|
||||
class Revise(BaseModel):
|
||||
revised_solution: str = Field(default="", description="Revised solution for this problem")
|
||||
class ReviseOp(BaseModel):
|
||||
revised_solution: str = Field(default="", description="Based on the feedback, revised solution for this problem")
|
||||
|
||||
class Ensemble(BaseModel):
|
||||
class EnsembleOp(BaseModel):
|
||||
final_solution: str = Field(default="", description="Final ensemble solution for this problem")
|
||||
|
||||
|
||||
|
||||
|
||||
# 接下来我将给予你两段代码,请你按照我的要求对其进行改写
|
||||
# 第一段代码是一个利用子ActionNode通过From_children方法实现的多个Node聚合
|
||||
# 第二段代码是一个利用Pydantic与From_pydantic方法实现的Node
|
||||
# 现在,我希望你能够通过From Pydantic方法,通过第二段代码的风格,完成我第一段代码中的GENERATE -> ENSEMBLE 五个Node的实现,每一个实现都应该像是第二段代码中的一个Class一样
|
||||
Loading…
Add table
Add a link
Reference in a new issue