write_new_code_fail

This commit is contained in:
黄伟韬 2024-09-12 15:52:14 +08:00
parent 4dd51dedb7
commit e0a104dd05
3 changed files with 13 additions and 3 deletions

View file

@ -103,6 +103,9 @@ WRITE_CODE_PROMPT = """
# Plan Status
{plan_status}
# Current Coding File
{file_path}
# Further Instruction
{instruction}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import re
from pathlib import Path
from pydantic import Field
@ -14,7 +15,7 @@ from metagpt.prompts.di.engineer2 import (
WRITE_CODE_SYSTEM_PROMPT,
)
from metagpt.roles.di.role_zero import RoleZero
from metagpt.schema import UserMessage
from metagpt.schema import AIMessage, UserMessage
from metagpt.strategy.experience_retriever import ENGINEER_EXAMPLE
from metagpt.tools.libs.cr import CodeReview
from metagpt.tools.libs.git import git_create_pull
@ -117,10 +118,16 @@ class Engineer2(RoleZero):
plan_status, _ = self._get_plan_status()
prompt = WRITE_CODE_PROMPT.format(
user_requirement=self.planner.plan.goal,
file_path=path,
plan_status=plan_status,
instruction=instruction,
)
context = self.llm.format_msg(self.rc.memory.get(self.memory_k) + [UserMessage(content=prompt)])
# Remove the json command in last message.
memory = self.rc.memory.get(self.memory_k)
pattern = r"```json.*?\s+(.*)\n```"
last_memory_content = re.sub(pattern, "", memory[-1].content, flags=re.DOTALL)
memory = memory[:-1] + [AIMessage(content=last_memory_content)]
context = self.llm.format_msg(memory + [UserMessage(content=prompt)])
async with EditorReporter(enable_llm_stream=True) as reporter:
await reporter.async_report({"type": "code", "filename": Path(path).name, "src_path": path}, "meta")

View file

@ -430,7 +430,7 @@ class RoleZero(Role):
for index, cmd in enumerate(commands)
if index == index_of_first_exclusive or cmd["command_name"] not in self.exclusive_tool_commands
]
command_rsp = "```json\n" + json.dumps(commands, indent=4, ensure_ascii=False) + "\n```json"
command_rsp = "```json\n" + json.dumps(commands, indent=4, ensure_ascii=False) + "\n```"
logger.info(
"exclusive command more than one in current command list. change the command list.\n" + command_rsp
)