Skip to content

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

fix code review performance drop

geekanad0ac940936e
diff --git a/metagpt/actions/write_code.py b/metagpt/actions/write_code.py
index a2501db2a..b759f4e2a 100644
--- a/metagpt/actions/write_code.py
+++ b/metagpt/actions/write_code.py
@@ -115,7 +115,7 @@ class WriteCode(Action):
if test_doc:
test_detail = RunCodeResult.loads(test_doc.content)
logs = test_detail.stderr
- code_context = await self._get_codes(coding_context.task_doc)
+ code_context = await self.get_codes(coding_context.task_doc, exclude=self.context.filename)
prompt = PROMPT_TEMPLATE.format(
design=coding_context.design_doc.content,
tasks=coding_context.task_doc.content if coding_context.task_doc else "",
@@ -133,7 +133,7 @@ class WriteCode(Action):
return coding_context
@staticmethod
- async def _get_codes(task_doc) -> str:
+ async def get_codes(task_doc, exclude) -> str:
if not task_doc:
return ""
if not task_doc.content:
@@ -143,6 +143,8 @@ class WriteCode(Action):
codes = []
src_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.src_workspace)
for filename in code_filenames:
+ if filename == exclude:
+ continue
doc = await src_file_repo.get(filename=filename)
if not doc:
continue
diff --git a/metagpt/actions/write_code_review.py b/metagpt/actions/write_code_review.py
index e0a538fc8..75313fea5 100644
--- a/metagpt/actions/write_code_review.py
+++ b/metagpt/actions/write_code_review.py
@@ -10,6 +10,7 @@
from tenacity import retry, stop_after_attempt, wait_random_exponential
+from metagpt.actions import WriteCode
from metagpt.actions.action import Action
from metagpt.config import CONFIG
from metagpt.logs import logger
@@ -109,11 +110,12 @@ class WriteCodeReview(Action):
for i in range(k):
format_example = FORMAT_EXAMPLE.format(filename=self.context.code_doc.filename)
task_content = self.context.task_doc.content if self.context.task_doc else ""
+ code_context = await WriteCode.get_codes(self.context.task_doc, exclude=self.context.filename)
context = "\n----------\n".join(
[
"```text\n" + self.context.design_doc.content + "```\n",
"```text\n" + task_content + "```\n",
- "```python\n" + self.context.code_doc.content + "```\n",
+ "```python\n" + code_context + "```\n",
]
)
prompt = PROMPT_TEMPLATE.format(