🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: merge gitlab:mgx_ops
莘权 马5a001a501d17
diff --cc metagpt/actions/write_code.pyindex 7f225d469,dc8a6dee5..da25fe621--- a/metagpt/actions/write_code.py+++ b/metagpt/actions/write_code.py@@@ -157,11 -150,10 +157,11 @@@ class WriteCode(Action)code = await self.write_code(prompt)if not coding_context.code_doc:# avoid root_path pydantic ValidationError if use WriteCode alone- root_path = self.context.src_workspace if self.context.src_workspace else ""- coding_context.code_doc = Document(filename=coding_context.filename, root_path=str(root_path))+ coding_context.code_doc = Document(+ filename=coding_context.filename, root_path=str(self.repo.src_relative_path)+ )coding_context.code_doc.content = code- await reporter.async_report(self.repo.workdir / coding_context.code_doc.root_relative_path, "path")+ await reporter.async_report(coding_context.code_doc, "document")return coding_context@staticmethoddiff --cc metagpt/actions/write_code_review.pyindex 3912095df,1b9f9554b..ad99de2dd--- a/metagpt/actions/write_code_review.py+++ b/metagpt/actions/write_code_review.py@@@ -14,10 -13,11 +14,11 @@@ from tenacity import retry, stop_after_from metagpt.actions import WriteCodefrom metagpt.actions.action import Action-from metagpt.const import REQUIREMENT_FILENAMEfrom metagpt.logs import logger-from metagpt.schema import CodingContext+from metagpt.schema import CodingContext, Documentfrom metagpt.utils.common import CodeParser+from metagpt.utils.project_repo import ProjectRepo+ from metagpt.utils.report import EditorReporterPROMPT_TEMPLATE = """# System@@@ -127,20 -127,23 +128,27 @@@ oclass WriteCodeReview(Action):name: str = "WriteCodeReview"i_context: CodingContext = Field(default_factory=CodingContext)+ repo: Optional[ProjectRepo] = Field(default=None, exclude=True)+ input_args: Optional[BaseModel] = Field(default=None, exclude=True)@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))- async def write_code_review_and_rewrite(self, context_prompt, cr_prompt, filename):+ async def write_code_review_and_rewrite(self, context_prompt, cr_prompt, doc):+ filename = doc.filenamecr_rsp = await self._aask(context_prompt + cr_prompt)result = CodeParser.parse_block("Code Review Result", cr_rsp)if "LGTM" in result:return result, None# if LBTM, rewrite code- rewrite_prompt = f"{context_prompt}\n{cr_rsp}\n{REWRITE_CODE_TEMPLATE.format(filename=filename)}"- code_rsp = await self._aask(rewrite_prompt)- code = CodeParser.parse_code(text=code_rsp)+ async with EditorReporter(enable_llm_stream=True) as reporter:- await reporter.async_report({"type": "code", "filename": filename, "src_path": doc.root_relative_path}, "meta")++ await reporter.async_report(++ {"type": "code", "filename": filename, "src_path": doc.root_relative_path}, "meta"++ )+ rewrite_prompt = f"{context_prompt}\n{cr_rsp}\n{REWRITE_CODE_TEMPLATE.format(filename=filename)}"+ code_rsp = await self._aask(rewrite_prompt)+ code = CodeParser.parse_code(text=code_rsp)+ doc.content = code+ await reporter.async_report(doc, "document")return result, codeasync def run(self, *args, **kwargs) -> CodingContext: