🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: merge geekan:env_refactor
莘权 马c24b3fff1b78
diff --cc metagpt/actions/action_node.pyindex ae40913e0,b1fbdaae9..f5009f345--- a/metagpt/actions/action_node.py+++ b/metagpt/actions/action_node.py@@@ -108,6 -110,16 +110,16 @@@ class ActionNode"""获得子ActionNode的字典,以key索引"""return {k: (v.expected_type, ...) for k, v in self.children.items()}+ def get_self_mapping(self) -> Dict[str, Type]:+ """get self key: type mapping"""+ return {self.key: (self.expected_type, ...)}++ def get_mapping(self, mode="children") -> Dict[str, Type]:+ """get key: type mapping under mode"""- if mode == "children" or (mode=="auto" and self.children):++ if mode == "children" or (mode == "auto" and self.children):+ return self.get_children_mapping()+ return self.get_self_mapping()+@classmethoddef create_model_class(cls, class_name: str, mapping: Dict[str, Type]):"""基于pydantic v1的模型动态生成,用来检验结果类型正确性"""@@@ -227,12 -239,11 +239,12 @@@mode="root": NotImplemented"""- # FIXME: json instruction会带来 "Project name": "web_2048 # 项目名称使用下划线",+ # FIXME: json instruction会带来格式问题,如:"Project name": "web_2048 # 项目名称使用下划线",self.instruction = self.compile_instruction(to="markdown", mode=mode)self.example = self.compile_example(to=to, tag="CONTENT", mode=mode)- prompt = template.format(context=context, example=self.example, instruction=self.instruction,- constraint=CONSTRAINT)+ prompt = template.format(+ context=context, example=self.example, instruction=self.instruction, constraint=CONSTRAINT+ )return prompt@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))@@@ -282,6 -301,38 +302,38 @@@self.instruct_content = output.instruct_contentreturn self+ async def fill(self, context, llm, to="json", mode="auto", strgy="simple"):- """ Fill the node(s) with mode.++ """Fill the node(s) with mode.++ :param context: Everything we should know when filling node.+ :param llm: Large Language Model with pre-defined system message.+ :param to: json/markdown, determine example and output format.+ - json: it's easy to open source LLM with json format+ - markdown: when generating code, markdown is always better+ :param mode: auto/children/root+ - auto: automated fill children's nodes and gather outputs, if no children, fill itself+ - children: fill children's nodes and gather outputs+ - root: fill root's node and gather output+ :param strgy: simple/complex+ - simple: run only once+ - complex: run each node+ :return: self+ """+ self.set_llm(llm)+ self.set_context(context)++ if strgy == "simple":+ return await self.simple_fill(to, mode)+ elif strgy == "complex":+ # 这里隐式假设了拥有children+ tmp = {}+ for _, i in self.children.items():+ child = await i.simple_fill(to, mode)+ tmp.update(child.instruct_content.dict())+ cls = self.create_children_class()+ self.instruct_content = cls(**tmp)+ return self+def action_node_from_tuple_example():# 示例:列表中包含元组diff --cc metagpt/actions/write_prd_an.pyindex 849150f6c,cbcf920b9..2c81bdb6e--- a/metagpt/actions/write_prd_an.py+++ b/metagpt/actions/write_prd_an.py@@@ -13,9 -13,16 +13,16 @@@ LANGUAGE = ActionNodekey="Language",expected_type=str,instruction="Provide the language used in the project, typically matching the user's requirement language.",- example="en_us"+ example="en_us",)+ PROGRAMMING_LANGUAGE = ActionNode(+ key="Programming Language",+ expected_type=str,+ instruction="Python/JavaScript or other mainstream programming language.",- example="Python"++ example="Python",+ )+ORIGINAL_REQUIREMENTS = ActionNode(key="Original Requirements",expected_type=str,