Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Merge pull request #648 from eukub/concat-to-fstrings

Guess643450388a0d
diff --cc metagpt/actions/action_node.py
index 27dde5a8c,e44e5e96e..31e4cc0fc
--- a/metagpt/actions/action_node.py
+++ b/metagpt/actions/action_node.py
@@@ -340,13 -195,10 +340,10 @@@ class ActionNode
def tagging(self, text, schema, tag="") -> str:
if not tag:
return text
- if schema == "json":
- return f"[{tag}]\n" + text + f"\n[/{tag}]"
- else: # markdown
- return f"[{tag}]\n" + text + f"\n[/{tag}]"
+ return f"[{tag}]\n{text}\n[/{tag}]"
- def _compile_f(self, schema, mode, tag, format_func, kv_sep) -> str:
- nodes = self.to_dict(format_func=format_func, mode=mode)
+ def _compile_f(self, schema, mode, tag, format_func, kv_sep, exclude=None) -> str:
+ nodes = self.to_dict(format_func=format_func, mode=mode, exclude=exclude)
text = self.compile_to(nodes, schema, kv_sep)
return self.tagging(text, schema, tag)
@@@ -375,23 -227,12 +372,23 @@@
schema="markdown": 编译context, example(markdown), instruction(markdown), constraint, action
"""
if schema == "raw":
- return context + "\n\n## Actions\n" + LANGUAGE_CONSTRAINT + "\n" + self.instruction
+ return f"{context}\n\n## Actions\n{LANGUAGE_CONSTRAINT}\n{self.instruction}"
+ ### 直接使用 pydantic BaseModel 生成 instruction 与 example,仅限 JSON
+ # child_class = self._create_children_class()
+ # node_schema = child_class.model_json_schema()
+ # defaults = {
+ # k: str(v)
+ # for k, v in child_class.model_fields.items()
+ # if k not in exclude
+ # }
+ # instruction = node_schema
+ # example = json.dumps(defaults, indent=4)
+
# FIXME: json instruction会带来格式问题,如:"Project name": "web_2048 # 项目名称使用下划线",
# compile example暂时不支持markdown
- instruction = self.compile_instruction(schema="markdown", mode=mode)
- example = self.compile_example(schema=schema, tag=TAG, mode=mode)
+ instruction = self.compile_instruction(schema="markdown", mode=mode, exclude=exclude)
+ example = self.compile_example(schema=schema, tag=TAG, mode=mode, exclude=exclude)
# nodes = ", ".join(self.to_dict(mode=mode).keys())
constraints = [LANGUAGE_CONSTRAINT, FORMAT_CONSTRAINT]
constraint = "\n".join(constraints)