Skip to content

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

update: fix cr comment

zhanglei28108bb37815
diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py
index 7f9f37ca2..6df7b01ff 100644
--- a/metagpt/prompts/di/role_zero.py
+++ b/metagpt/prompts/di/role_zero.py
@@ -49,9 +49,8 @@ Some text indicating your thoughts, such as how you should update the plan statu
...
]
```
-"""
-
+"""
JSON_REPAIR_PROMPT = """
## json data
{json_data}
diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py
index 39b44ccf3..e4c81278b 100644
--- a/metagpt/roles/di/role_zero.py
+++ b/metagpt/roles/di/role_zero.py
@@ -139,7 +139,8 @@ class RoleZero(Role):
return await super()._act()
try:
- commands = json.loads(repair_llm_raw_output(output=CodeParser.parse_code(block=None, lang="json", text=self.command_rsp), req_keys=[None], repair_type=RepairType.JSON))
+ self.command_rsp = CodeParser.parse_code(block=None, lang="json", text=self.command_rsp)
+ commands = json.loads(repair_llm_raw_output(output=self.command_rsp, req_keys=[None], repair_type=RepairType.JSON))
except json.JSONDecodeError as e:
self.command_rsp = await self.llm.aask(msg=JSON_REPAIR_PROMPT.format(json_data=self.command_rsp))
commands = json.loads(CodeParser.parse_code(block=None, lang="json", text=self.command_rsp))
@@ -150,11 +151,10 @@ class RoleZero(Role):
self.rc.memory.add(error_msg)
return error_msg
+ # 为了对LLM不按格式生成进行容错
if isinstance(commands, dict):
- if "commands" in commands:
- commands = commands["commands"]
- else:
- commands = [commands]
+ commands = commands["commands"] if "commands" in commands else [commands]
+
outputs = await self._run_commands(commands)
self.rc.memory.add(UserMessage(content=outputs))
return AIMessage(