diff --git a/metagpt/environment/mgx/mgx_env.py b/metagpt/environment/mgx/mgx_env.py
index 33160cfd8..69f80c2ff 100644
--- a/metagpt/environment/mgx/mgx_env.py
+++ b/metagpt/environment/mgx/mgx_env.py
@@ -27,7 +27,7 @@ class MGXEnv(Environment):
def publish_message(self, message: Message, user_defined_recipient: str = "", publicer: str = "") -> bool:
"""let the team leader take over message publishing"""
- tl = self.get_role("Tim") # TeamLeader's name is Tim
+ tl = self.get_role("Mike") # TeamLeader's name is Mike
if user_defined_recipient:
# human user's direct chat message to a certain role
diff --git a/metagpt/ext/cr/actions/code_review.py b/metagpt/ext/cr/actions/code_review.py
index 5586567fa..2cbeeb3ee 100644
--- a/metagpt/ext/cr/actions/code_review.py
+++ b/metagpt/ext/cr/actions/code_review.py
@@ -57,7 +57,7 @@ Just print the PR Patch comments in json format like **Output Format**.
"""
CODE_REVIEW_COMFIRM_SYSTEM_PROMPT = """
-You are a professional engineer with Java stack, and good at code review comment result judgement.
+You are a professional engineer with {code_language} stack, and good at code review comment result judgement.
"""
CODE_REVIEW_COMFIRM_TEMPLATE = """
@@ -132,13 +132,20 @@ class CodeReview(Action):
code = get_code_block_from_patch(
patch, str(max(1, int(code_start_line) - 5)), str(int(code_end_line) + 5)
)
+ code_language = "Java"
+ code_file_ext = cmt.get("commented_file", ".java").split(".")[-1]
+ if code_file_ext == ".java":
+ code_language = "Java"
+ elif code_file_ext == ".py":
+ code_language = "Python"
prompt = CODE_REVIEW_COMFIRM_TEMPLATE.format(
code=code,
comment=cmt.get("comment"),
desc=point.text,
example=point.yes_example + "\n" + point.no_example,
)
- resp = await self.llm.aask(prompt, system_msgs=[CODE_REVIEW_COMFIRM_SYSTEM_PROMPT])
+ system_prompt = [CODE_REVIEW_COMFIRM_SYSTEM_PROMPT.format(code_language=code_language)]
+ resp = await self.llm.aask(prompt, system_msgs=system_prompt)
if "True" in resp or "true" in resp:
new_comments.append(cmt)
logger.info(f"original comments num: {len(comments)}, confirmed comments num: {len(new_comments)}")
@@ -163,7 +170,11 @@ class CodeReview(Action):
prompt = CODE_REVIEW_PROMPT_TEMPLATE.format(patch=str(patched_file), points=points_str)
resp = await self.llm.aask(prompt)
json_str = parse_json_code_block(resp)[0]
- comments += json.loads(json_str)
+ comment = json.loads(json_str)
+ patched_file_path = patched_file.path
+ for c in comment:
+ c["commented_file"] = patched_file_path
+ comments += comment
return comments
diff --git a/metagpt/ext/cr/actions/modify_code.py b/metagpt/ext/cr/actions/modify_code.py
index 33a368463..2c54cdbae 100644
--- a/metagpt/ext/cr/actions/modify_code.py
+++ b/metagpt/ext/cr/actions/modify_code.py
@@ -81,17 +81,18 @@ class ModifyCode(Action):
}
resp = None
for patched_file in patch:
- patch_target_file_name = str(patched_file.target_file).split("/", maxsplit=1)[-1]
- if patch_target_file_name not in grouped_comments:
+ patch_target_file_name = str(patched_file.path).split("/")[-1]
+ if patched_file.path not in grouped_comments:
continue
comments_prompt = ""
index = 1
- for grouped_comment in grouped_comments[patch_target_file_name]:
+ for grouped_comment in grouped_comments[patched_file.path]:
comments_prompt += f"""
{grouped_comment}
\n
"""
+ index += 1
prompt = MODIFY_CODE_PROMPT.format(patch=patched_file, comments=comments_prompt)
output_dir = (
Path(output_dir)
diff --git a/metagpt/ext/cr/points.json b/metagpt/ext/cr/points.json
index b0497cb7b..5455d3865 100644
--- a/metagpt/ext/cr/points.json
+++ b/metagpt/ext/cr/points.json
@@ -1,664 +1,656 @@
[
- {
- "id": 1,
- "text": "避免未使用的临时变量",
- "language": "java",
- "detail": "缺陷类型:避免未使用的临时变量;对应Fixer:UnusedLocalVariableFixer;修复方案:删除未使用的临时变量",
- "yes_example": "### 被判定为\"避免未使用的临时变量\"的例子\n<例子1>\npublic String initCreationForm(Map model) {\n\t\tOwner owner = new Owner();\n\t\tmodel.put(\"owner\", owner);\n\t\tint unusedVar = 10;\n\t\treturn VIEWS_OWNER_CREATE_OR_UPDATE_FORM;\n\t}\n上述代码中unusedVar变量未被使用,所以这个被判定为\"避免未使用的临时变量\"\n例子1>\n<例子2>\nint unusedVariable = 10;\nSystem.out.println(\"Hello, World!\");\n这段代码的变量\"unusedVariable\"未被使用或者引用,所以这个不能判定为\"避免未使用的临时变量\"\n例子2>",
- "no_example": "### 不能被判定为\"避免未使用的临时变量\"的例子\n<例子1>\npublic void setTransientVariablesLocal(Map transientVariables) {\nthrow new UnsupportedOperationException(\"No execution active, no variables can be set\");\n}\n这段代码的\"transientVariables\"是函数参数而不是临时变量,虽然transientVariables没有被使用或者引用,但是这个也不能判定为\"避免未使用的临时变量\"\n例子1>\n\n<例子2>\npublic class TriggerCmd extends NeedsActiveExecutionCmd