add example to engineer

This commit is contained in:
hongjiongteng 2024-06-24 21:22:43 +08:00
parent 9454c4dfd6
commit 5d0e99bb5d
3 changed files with 117 additions and 1 deletions

View file

@ -10,7 +10,7 @@ EXTRA_INSTRUCTION = """
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, ensuring that no line numbers are included in the final write.
13. When a system design or project schedule is provided, at the end of the plan, add a Special Task for each file; for example, if there are three files, add three Special Tasks. For each Special Task, just call ReviewAndRewriteCode.run.
13. When a system design or project schedule is provided, at the end of the plan, add a CodeRview Task for each file; for example, if there are three files, add three CodeRview Tasks. For each CodeRview Task, just call ReviewAndRewriteCode.run.
"""

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from metagpt.actions.write_code_review import ReviewAndRewriteCode
from metagpt.prompts.di.engineer2 import ENGINEER2_INSTRUCTION
from metagpt.roles.di.role_zero import RoleZero
from metagpt.strategy.experience_retriever import ENGINEER_EXAMPLE
class Engineer2(RoleZero):
@ -22,3 +23,6 @@ class Engineer2(RoleZero):
"ReviewAndRewriteCode": review.run,
}
)
def _retrieve_experience(self) -> str:
return ENGINEER_EXAMPLE

View file

@ -336,3 +336,115 @@ editor.read(path="./main.py")
- If no specific file is provided, search the symbol in the whole codebase to locate the issue.
- If no specific symbol is provided, directly open and read the file to diagnose the problem.
"""
ENGINEER_EXAMPLE = """
## example 1
User Requirement: Please implement the core game logic for the 2048 game, including tile movements, merging logic, score tracking, and keyboard interaction. Refer to the project schedule located at '/tmp/project_schedule.json' and the system design document at '/tmp/system_design.json' for detailed information.
Explanation: I will first need to read the system design document and the project schedule to understand the specific requirements and architecture outlined for the game development.
```json
[
{
"command_name": "Editor.read",
"args": {
"path": "/tmp/docs/project_schedule.json"
}
},
{
"command_name": "Editor.read",
"args": {
"path": "/tmp/docs/system_design.json"
}
}
]
```
## example 2
To achieve the goal of writing a 2048 game using JavaScript and HTML without any frameworks, I will create a plan consisting of three tasks, each corresponding to the creation of one of the required files: `index.html`, `style.css`, and `script.js`. Following the completion of these tasks, I will add a code review task for each file to ensure the implementation aligns with the provided system design and project schedule documents.
Here's the plan:
1. **Task 1**: Create `index.html` - This file will contain the HTML structure necessary for the game's UI.
2. **Task 2**: Create `style.css` - This file will define the CSS styles to make the game visually appealing and responsive.
3. **Task 3**: Create `script.js` - This file will contain the JavaScript code for the game logic and UI interactions.
4. **Code Review Tasks**: Review each file to ensure they meet the project requirements and adhere to the system design.
Let's start by appending the first task to the plan.
```json
[
{
"command_name": "Plan.append_task",
"args": {
"task_id": "1",
"dependent_task_ids": [],
"instruction": "Create the index.html file with the basic HTML structure for the 2048 game.",
"assignee": "Alex"
}
},
{
"command_name": "Plan.append_task",
"args": {
"task_id": "2",
"dependent_task_ids": ["1"],
"instruction": "Create the style.css file with the necessary CSS to style the 2048 game.",
"assignee": "Alex"
}
},
{
"command_name": "Plan.append_task",
"args": {
"task_id": "3",
"dependent_task_ids": ["1", "2"],
"instruction": "Create the script.js file containing the JavaScript logic for the 2048 game.",
"assignee": "Alex"
}
},
{
"command_name": "Plan.append_task",
"args": {
"task_id": "4",
"dependent_task_ids": ["1"],
"instruction": "Use ReviewAndRewriteCode to review the code in index.html to ensure it meets the design specifications.",
"assignee": "Alex"
}
},
{
"command_name": "Plan.append_task",
"args": {
"task_id": "5",
"dependent_task_ids": ["2"],
"instruction": "Use ReviewAndRewriteCode to review the code in style.css to ensure it meets the design specifications.",
"assignee": "Alex"
}
},
{
"command_name": "Plan.append_task",
"args": {
"task_id": "6",
"dependent_task_ids": ["3"],
"instruction": "Use ReviewAndRewriteCode to review the code in script.js to ensure it meets the design specifications. ",
"assignee": "Alex"
}
}
]
```
## example 3
I will now review the code in `script.js`.
Explanation: to review the code, call ReviewAndRewriteCode.run.
```json
[
{
"command_name": "ReviewAndRewriteCode.run",
"args": {
"code_path": "/tmp/src/script.js",
"system_design_input": "/tmp/docs/system_design.json",
"project_schedule_input": "/tmp/docs/project_schedule.json",
"code_review_k_times": 2
}
}
]
```
"""