mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
update: cr增加兜底提示
This commit is contained in:
parent
4e82d86166
commit
35075134c2
3 changed files with 14 additions and 2 deletions
|
|
@ -18,7 +18,7 @@ from metagpt.ext.cr.utils.cleaner import (
|
|||
from metagpt.ext.cr.utils.schema import Point
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.common import parse_json_code_block
|
||||
from metagpt.utils.report import EditorReporter
|
||||
from metagpt.utils.report import EditorReporter, ThoughtReporter
|
||||
|
||||
CODE_REVIEW_PROMPT_TEMPLATE = """
|
||||
NOTICE
|
||||
|
|
@ -175,13 +175,16 @@ class CodeReview(Action):
|
|||
|
||||
async def cr_by_points(self, patch: PatchSet, points: list[Point]):
|
||||
comments = []
|
||||
valid_patch_count = 0
|
||||
for patched_file in patch:
|
||||
if not patched_file:
|
||||
continue
|
||||
if patched_file.path.endswith(".py"):
|
||||
points = [p for p in points if p.language == "Python"]
|
||||
valid_patch_count += 1
|
||||
elif patched_file.path.endswith(".java"):
|
||||
points = [p for p in points if p.language == "Java"]
|
||||
valid_patch_count += 1
|
||||
else:
|
||||
continue
|
||||
group_points = [points[i : i + 3] for i in range(0, len(points), 3)]
|
||||
|
|
@ -198,6 +201,10 @@ class CodeReview(Action):
|
|||
c["commented_file"] = patched_file_path
|
||||
comments.extend(comments_batch)
|
||||
|
||||
if valid_patch_count == 0:
|
||||
await ThoughtReporter().async_report(value={"type": "limit", "classify": "language"})
|
||||
raise ValueError("Only code reviews for Python and Java languages are supported.")
|
||||
|
||||
return comments
|
||||
|
||||
async def run(self, patch: PatchSet, points: list[Point], output_file: str):
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from metagpt.prompts.di.engineer2 import (
|
|||
from metagpt.roles.di.role_zero import RoleZero
|
||||
from metagpt.schema import UserMessage
|
||||
from metagpt.strategy.experience_retriever import ENGINEER_EXAMPLE
|
||||
from metagpt.tools.libs.cr import CodeReview
|
||||
from metagpt.tools.libs.terminal import Terminal
|
||||
from metagpt.tools.tool_registry import register_tool
|
||||
from metagpt.utils.common import CodeParser, awrite
|
||||
|
|
@ -28,14 +29,17 @@ class Engineer2(RoleZero):
|
|||
|
||||
terminal: Terminal = Field(default_factory=Terminal, exclude=True)
|
||||
|
||||
tools: list[str] = ["Plan", "Editor:read", "RoleZero", "Terminal:run_command", "Engineer2"]
|
||||
tools: list[str] = ["Plan", "Editor:read", "RoleZero", "Terminal:run_command", "Engineer2", "SearchEnhancedQA", "CodeReview"]
|
||||
|
||||
def _update_tool_execution(self):
|
||||
# validate = ValidateAndRewriteCode()
|
||||
cr = CodeReview()
|
||||
self.tool_execution_map.update(
|
||||
{
|
||||
"Terminal.run_command": self.terminal.run_command,
|
||||
"Engineer2.write_new_code": self.write_new_code,
|
||||
"CodeReview.review": cr.review,
|
||||
"CodeReview.fix": cr.fix,
|
||||
# "ValidateAndRewriteCode.run": validate.run,
|
||||
# "ValidateAndRewriteCode": validate.run,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class CodeReview:
|
|||
"""
|
||||
patch = await self._get_patch_content(patch_path)
|
||||
point_file = point_file if point_file else Path(metagpt.ext.cr.__file__).parent / "points.json"
|
||||
await EditorReporter().async_report(str(point_file), "path")
|
||||
async with aiofiles.open(point_file, "rb") as f:
|
||||
cr_point_content = await f.read()
|
||||
cr_points = [Point(**i) for i in json.loads(cr_point_content)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue