mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-05 14:55:18 +02:00
update action name
This commit is contained in:
parent
a48ccfdcf9
commit
bd3b4dc8c0
3 changed files with 19 additions and 18 deletions
|
|
@ -211,11 +211,11 @@ class WriteCodeReview(Action):
|
|||
return self.i_context
|
||||
|
||||
|
||||
@register_tool(tags=["CodeReview"], include_functions=["run"])
|
||||
class RewriteCode(Action):
|
||||
"""Accordding design doc and task doc to review the code, to make the complete and correct code."""
|
||||
@register_tool(include_functions=["run"])
|
||||
class ReviewAndRewriteCode(Action):
|
||||
"""According to the design and task documents, review the code to ensure it is complete and correct."""
|
||||
|
||||
name: str = "RewriteCode"
|
||||
name: str = "ReviewAndRewriteCode"
|
||||
|
||||
async def run(
|
||||
self, code_path: str, design_doc_input: str = "", task_doc_input: str = "", code_review_k_times: int = 2
|
||||
|
|
@ -223,7 +223,7 @@ class RewriteCode(Action):
|
|||
"""Reviews the provided code based on the accompanying design and task documentation, return the complete and correct code.
|
||||
|
||||
Read the code from `code_path`, and write the final code to `code_path`.
|
||||
If there is no `design_doc_input` or `task_doc_input`, it will return and do nothing.
|
||||
If both `design_doc_input` and `task_doc_input are absent`, it will return and do nothing.
|
||||
|
||||
Args:
|
||||
code_path (str): The file path of the code snippet to be reviewed. This should be a string containing the path to the source code file.
|
||||
|
|
@ -236,21 +236,22 @@ class RewriteCode(Action):
|
|||
|
||||
Example Usage:
|
||||
# Example of how to call the run method with a code snippet and documentation
|
||||
await RewriteCode().run(
|
||||
await ReviewAndRewriteCode().run(
|
||||
code_path="/tmp/game.js",
|
||||
design_doc_input="/tmp/design_doc.json",
|
||||
task_doc_input='{"Required packages":["No third-party dependencies required"], ...}'
|
||||
design_doc_input="/tmp/system_design.json",
|
||||
task_doc_input="/tmp/project_task_list.json"
|
||||
)
|
||||
"""
|
||||
|
||||
if not design_doc_input or not task_doc_input:
|
||||
if not design_doc_input and not task_doc_input:
|
||||
logger.info("Both design_doc_input and task_doc_input are absent, ReviewAndRewriteCode will do nothing.")
|
||||
return
|
||||
|
||||
code, design_doc, task_doc = await asyncio.gather(
|
||||
aread(code_path), self._try_aread(design_doc_input), self._try_aread(task_doc_input)
|
||||
)
|
||||
code_doc = self._create_code_doc(code_path=code_path, code=code)
|
||||
reviewer = WriteCodeReview(i_context=CodingContext(filename=code_doc.filename))
|
||||
review_action = WriteCodeReview(i_context=CodingContext(filename=code_doc.filename))
|
||||
|
||||
context = "\n".join(
|
||||
[
|
||||
|
|
@ -265,7 +266,7 @@ class RewriteCode(Action):
|
|||
format_example=FORMAT_EXAMPLE.format(filename=code_path),
|
||||
)
|
||||
logger.info(f"The {i+1}th time to CodeReview: {code_path}.")
|
||||
result, rewrited_code = await reviewer.write_code_review_and_rewrite(
|
||||
result, rewrited_code = await review_action.write_code_review_and_rewrite(
|
||||
context_prompt, cr_prompt, doc=code_doc
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ EXTRA_INSTRUCTION = """
|
|||
4. Each time you write a code in your response, write with the Editor directly without preparing a repetitive code block beforehand.
|
||||
5. Take on ONE task and write ONE code file in each response. DON'T attempt all tasks in one response.
|
||||
6. When not specified, you should write files in a folder named "src". If you know the project path, then write in a "src" folder under the project path.
|
||||
7. When provided system design or project schedule, read them first, then adhere to them in your implementation, especially in the programming language, package, or framework. You MUST implement all code files prescribed in the system design or project schedule. You can create a plan first with each task corresponding to implementing one code file.
|
||||
7. When provided system design or project schedule, you MUST read them first before making a plan, then adhere to them in your implementation, especially in the programming language, package, or framework. You MUST implement all code files prescribed in the system design or project schedule. You can create a plan first with each task corresponding to implementing one code file.
|
||||
8. Write at most one file per task, do your best to implement THE ONLY ONE FILE. CAREFULLY CHECK THAT YOU DONT MISS ANY NECESSARY CLASS/FUNCTION IN THIS FILE.
|
||||
9. COMPLETE CODE: Your code will be part of the entire project, so please implement complete, reliable, reusable code snippets.
|
||||
10. When provided system design, YOU MUST FOLLOW "Data structures and interfaces". DONT CHANGE ANY DESIGN. Do not use public member functions that do not exist in your design.
|
||||
11. Write out EVERY CODE DETAIL, DON'T LEAVE TODO.
|
||||
12. To modify code in a file, read the entire file, make changes, and update the file with the complete code.
|
||||
13. Only with a system design, at the end of the plan, add a CodeReview Task for each file; for example, if there are three files, add three CodeReview Tasks.
|
||||
13. Only when a system design or a project schedule is provided, at the end of the plan, add a ReviewAndRewriteCode Task for each file; for example, if there are three files, add three ReviewAndRewriteCode Tasks.
|
||||
"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from metagpt.actions.write_code_review import RewriteCode
|
||||
from metagpt.actions.write_code_review import ReviewAndRewriteCode
|
||||
from metagpt.prompts.di.engineer2 import ENGINEER2_INSTRUCTION
|
||||
from metagpt.roles.di.role_zero import RoleZero
|
||||
|
||||
|
|
@ -11,14 +11,14 @@ class Engineer2(RoleZero):
|
|||
goal: str = "Take on game, app, and web development"
|
||||
instruction: str = ENGINEER2_INSTRUCTION
|
||||
|
||||
tools: str = ["Plan", "Editor:write,read", "RoleZero", "RewriteCode"]
|
||||
tools: str = ["Plan", "Editor:write,read", "RoleZero", "ReviewAndRewriteCode"]
|
||||
|
||||
def _update_tool_execution(self):
|
||||
rewrite_code = RewriteCode()
|
||||
review = ReviewAndRewriteCode()
|
||||
|
||||
self.tool_execution_map.update(
|
||||
{
|
||||
"RewriteCode.run": rewrite_code.run,
|
||||
"RewriteCode": rewrite_code.run,
|
||||
"ReviewAndRewriteCode.run": review.run,
|
||||
"ReviewAndRewriteCode": review.run,
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue