fix code review performance drop

This commit is contained in:
geekan
2023-12-14 23:54:09 +08:00
parent 84357651e5
commit ad0ac94093
2 changed files with 7 additions and 3 deletions
+4 -2
View File
@@ -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
+3 -1
View File
@@ -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(