opt engineer2

This commit is contained in:
hongjiongteng 2024-06-19 23:41:09 +08:00
parent 47df4c09ba
commit 942a6d61bb
3 changed files with 11 additions and 5 deletions

View file

@ -7,6 +7,7 @@ from metagpt.actions.write_code_review import (
PROMPT_TEMPLATE,
REWRITE_CODE_TEMPLATE,
)
from metagpt.logs import logger
from metagpt.tools.tool_registry import register_tool
from metagpt.utils.common import CodeParser, aread, awrite
@ -21,6 +22,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` or `task_doc`, 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.
@ -39,6 +41,9 @@ class RewriteCode(Action):
task_doc='{"Required packages":["No third-party dependencies required"],"..."}'
)
"""
if not design_doc or not task_doc:
return
code = await aread(code_path)
context = "\n".join(
@ -48,11 +53,12 @@ class RewriteCode(Action):
]
)
for _ in range(code_review_k_times):
for i in range(code_review_k_times):
context_prompt = PROMPT_TEMPLATE.format(context=context, code=code, filename=code_path)
cr_prompt = EXAMPLE_AND_INSTRUCTION.format(
format_example=FORMAT_EXAMPLE.format(filename=code_path),
)
logger.info(f"The {i+1}th time to CodeReview: {code_path}.")
result, rewrited_code = await self.write_code_review_and_rewrite(
context_prompt, cr_prompt, filename=code_path
)

View file

@ -9,9 +9,9 @@ EXTRA_INSTRUCTION = """
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. Do not use Editor to find start_line and end_line, just rewrite the file with the all complete code.
13. Revise task is to use RewriteCode.run to correct code.
14. At the end of the plan, add a Revise task for each file; for example, if there are three files, add three Revise tasks.
12. To modify code in a file, read the entire file, make changes, and use Editor.write instead of Editor.write_content to update the file with the complete code.
13. Revise task is to use RewriteCode.run to correct code, must pass the content of system design and project schedule instead of just file path of them.
14. Only When provided system design, at the end of the plan, add a Revise task for each file; for example, if there are three files, add three Revise tasks.
"""

View file

@ -20,7 +20,7 @@ Note:
3. If the requirement contains both DATA-RELATED part mentioned in 1 and software development part mentioned in 2, you should decompose the software development part and assign them to different team members based on their expertise, and assign the DATA-RELATED part to Data Analyst David directly.
4. If the requirement is a common-sense, logical, or math problem, you should respond directly without assigning any task to team members.
5. If you think the requirement is not clear or ambiguous, you should ask the user for clarification immediately. Assign tasks only after all info is clear.
6. It is helpful for Engineer to have both the system design and the project schedule for writing the code, so include paths of both files (if available) when publishing message to Engineer.
6. It is helpful for Engineer to have both the system design and the project schedule for writing the code, so include paths of both files (if available) and remind Engineer to definitely read them when publishing message to Engineer.
"""
FINISH_CURRENT_TASK_CMD = """