🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
refine code
geekan1060292cbf76
diff --git a/metagpt/strategy/tot.py b/metagpt/strategy/tot.pyindex 4f33698bf..e67d272c7 100644--- a/metagpt/strategy/tot.py+++ b/metagpt/strategy/tot.py@@ -2,6 +2,8 @@# @Date : 12/23/2023 4:51 PM# @Author : stellahong ([email protected])# @Desc :+from __future__ import annotations+import asynciofrom typing import Any, List@@ -31,7 +33,7 @@ Output a list of jsons following the format:class ThoughtSolverBase(BaseModel):model_config = ConfigDict(arbitrary_types_allowed=True)- thought_tree: str = ""+ thought_tree: ThoughtTree | None = Nonellm: BaseLLM = Field(default_factory=LLM, exclude=True)config: ThoughtSolverConfig = Field(default_factory=ThoughtSolverConfig)@@ -60,7 +62,7 @@ class ThoughtSolverBase(BaseModel):current_state=current_state, **{"n_generate_sample": self.config.n_generate_sample})rsp = await self.llm.aask(msg=state_prompt + "\n" + OUTPUT_FORMAT)- thoughts = CodeParser.parse_code(block=None, text=rsp)+ thoughts = CodeParser.parse_code(block="", text=rsp)thoughts = eval(thoughts)# fixme 避免不跟随,生成过多nodes# valid_thoughts = [_node for idx, _node in enumerate(thoughts) if idx < self.n_generate_sample]@@ -97,15 +99,16 @@ class ThoughtSolverBase(BaseModel):Returns:List[ThoughtNode]: List of selected nodes."""- # selection+ # nodes to be selected+ nodes = []if self.config.method_select == MethodSelect.SAMPLE:raise NotImplementedErrorelif self.config.method_select == MethodSelect.GREEDY:- select_nodes = sorted(thought_nodes, key=lambda x: x.value, reverse=True)[: self.config.n_select_sample]+ nodes = sorted(thought_nodes, key=lambda x: x.value, reverse=True)[: self.config.n_select_sample]for node in thought_nodes:- if node not in select_nodes:+ if node not in nodes:node.parent = None # 从树中删除节点- return select_nodes+ return nodesdef update_solution(self):"""