Skip to content

Commit 3d4d036

Browse files
authored
Merge pull request #1559 from geekan/mgx_ops
MG 1.0 first version, will be further optimized
2 parents df9bc18 + 9d456f3 commit 3d4d036

File tree

337 files changed

+22901
-1364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

337 files changed

+22901
-1364
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ examples/graph_store.json
162162
examples/image__vector_store.json
163163
examples/index_store.json
164164
.chroma
165+
.chroma_exp_data
166+
.role_memory_data
165167
*~$*
166168
workspace/*
167169
tmp
@@ -189,6 +191,7 @@ cov.xml
189191
*-structure.json
190192
*.dot
191193
.python-version
194+
tests/data/requirements/*.jpg
192195
*.csv
193196
metagpt/ext/sela/results/*
194197
.chainlit/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM nikolaik/python-nodejs:python3.9-nodejs20-slim
33

44
# Install Debian software needed by MetaGPT and clean up in one RUN command to reduce image size
55
RUN apt update &&\
6-
apt install -y libgomp1 git chromium fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends &&\
6+
apt install -y libgomp1 git chromium fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends file &&\
77
apt clean && rm -rf /var/lib/apt/lists/*
88

99
# Install Mermaid CLI globally

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pip install --upgrade metagpt
7777
# or `git clone https://github.com/geekan/MetaGPT && cd MetaGPT && pip install --upgrade -e .`
7878
```
7979

80+
**Install [node](https://nodejs.org/en/download) and [pnpm](https://pnpm.io/installation#using-npm) before actual use.**
81+
8082
For detailed installation guidance, please refer to [cli_install](https://docs.deepwisdom.ai/main/en/guide/get_started/installation.html#install-stable-version)
8183
or [docker_install](https://docs.deepwisdom.ai/main/en/guide/get_started/installation.html#install-with-docker)
8284

config/config2.example.yaml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,37 @@ embedding:
2020
embed_batch_size: 100
2121
dimensions: # output dimension of embedding model
2222

23+
# Role's custom configuration
24+
roles:
25+
- role: "ProductManager" # role's className or role's role_id
26+
llm:
27+
api_type: "openai" # or azure / ollama / open_llm etc. Check LLMType for more options
28+
base_url: "YOUR_BASE_URL"
29+
api_key: "YOUR_API_KEY"
30+
proxy: "YOUR_PROXY" # for LLM API requests
31+
model: "gpt-4-turbo-1106"
32+
- role: "Architect"
33+
llm:
34+
api_type: "openai" # or azure / ollama / open_llm etc. Check LLMType for more options
35+
base_url: "YOUR_BASE_URL"
36+
api_key: "YOUR_API_KEY"
37+
proxy: "YOUR_PROXY" # for LLM API requests
38+
model: "gpt-35-turbo"
39+
- role: "ProjectManager"
40+
llm:
41+
api_type: "azure"
42+
base_url: "YOUR_BASE_URL"
43+
api_key: "YOUR_API_KEY"
44+
api_version: "YOUR_API_VERSION"
45+
model: "gpt-4-1106"
46+
- role: "Engineer"
47+
llm:
48+
api_type: "azure"
49+
base_url: "YOUR_BASE_URL"
50+
api_key: "YOUR_API_KEY"
51+
api_version: "YOUR_API_VERSION"
52+
model: "gpt-35-turbo-1106"
53+
2354
repair_llm_output: true # when the output is not a valid json, try to repair it
2455

2556
proxy: "YOUR_PROXY" # for tools like requests, playwright, selenium, etc.
@@ -50,6 +81,21 @@ s3:
5081
secure: false
5182
bucket: "test"
5283

84+
exp_pool:
85+
enabled: false
86+
enable_read: false
87+
enable_write: false
88+
persist_path: .chroma_exp_data # The directory.
89+
retrieval_type: bm25 # Default is `bm25`, can be set to `chroma` for vector storage, which requires setting up embedding.
90+
use_llm_ranker: true # Default is `true`, it will use LLM Reranker to get better result.
91+
collection_name: experience_pool # When `retrieval_type` is `chroma`, `collection_name` is the collection name in chromadb.
92+
93+
role_zero:
94+
enable_longterm_memory: false # Whether to use long-term memory. Default is `false`.
95+
longterm_memory_persist_path: .role_memory_data # The directory to save data.
96+
memory_k: 200 # The capacity of short-term memory.
97+
similarity_top_k: 5 # The number of long-term memories to retrieve.
98+
use_llm_ranker: false # Whether to use LLM Reranker to get better result. Default is `false`.
5399

54100
azure_tts_subscription_key: "YOUR_SUBSCRIPTION_KEY"
55101
azure_tts_region: "eastus"
@@ -81,5 +127,3 @@ models:
81127
# # timeout: 600 # Optional. If set to 0, default value is 300.
82128
# # Details: https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/
83129
# pricing_plan: "" # Optional. Use for Azure LLM when its model name is not the same as OpenAI's
84-
85-
agentops_api_key: "YOUR_AGENTOPS_API_KEY" # get key from https://app.agentops.ai/settings/projects

config/vault.example.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Usage:
2+
# 1. Get value.
3+
# >>> from metagpt.tools.libs.env import get_env
4+
# >>> access_token = await get_env(key="access_token", app_name="github")
5+
# >>> print(access_token)
6+
# YOUR_ACCESS_TOKEN
7+
#
8+
# 2. Get description for LLM understanding.
9+
# >>> from metagpt.tools.libs.env import get_env_description
10+
# >>> descriptions = await get_env_description
11+
# >>> for k, desc in descriptions.items():
12+
# >>> print(f"{key}:{desc}")
13+
# await get_env(key="access_token", app_name="github"):Get github access token
14+
# await get_env(key="access_token", app_name="gitlab"):Get gitlab access token
15+
# ...
16+
17+
vault:
18+
github:
19+
values:
20+
access_token: "YOUR_ACCESS_TOKEN"
21+
descriptions:
22+
access_token: "Get github access token"
23+
gitlab:
24+
values:
25+
access_token: "YOUR_ACCESS_TOKEN"
26+
descriptions:
27+
access_token: "Get gitlab access token"
28+
iflytek_tts:
29+
values:
30+
api_id: "YOUR_APP_ID"
31+
api_key: "YOUR_API_KEY"
32+
api_secret: "YOUR_API_SECRET"
33+
descriptions:
34+
api_id: "Get the API ID of IFlyTek Text to Speech"
35+
api_key: "Get the API KEY of IFlyTek Text to Speech"
36+
api_secret: "Get the API SECRET of IFlyTek Text to Speech"
37+
azure_tts:
38+
values:
39+
subscription_key: "YOUR_SUBSCRIPTION_KEY"
40+
region: "YOUR_REGION"
41+
descriptions:
42+
subscription_key: "Get the subscription key of Azure Text to Speech."
43+
region: "Get the region of Azure Text to Speech."
44+
default: # All key-value pairs whose app name is an empty string are placed below
45+
values:
46+
proxy: "YOUR_PROXY"
47+
descriptions:
48+
proxy: "Get proxy for tools like requests, playwright, selenium, etc."

examples/cr.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import fire
2+
3+
from metagpt.roles.di.engineer2 import Engineer2
4+
from metagpt.tools.libs.cr import CodeReview
5+
6+
7+
async def main(msg):
8+
role = Engineer2(tools=["Plan", "Editor:write,read", "RoleZero", "ValidateAndRewriteCode", "CodeReview"])
9+
cr = CodeReview()
10+
role.tool_execution_map.update({"CodeReview.review": cr.review, "CodeReview.fix": cr.fix})
11+
await role.run(msg)
12+
13+
14+
if __name__ == "__main__":
15+
fire.Fire(main)

examples/data/di/dog.jpg

14.7 KB
Loading
32.6 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"req": [
4+
{
5+
"role": "user",
6+
"content": "\n# Current Plan\n{'goal': \"Please write a 1048 game using JavaScript and HTML code without using any frameworks, user can play with keyboard. Refer to the system design located at '/tmp/system_design.json' and the project schedule at '/tmp/project_schedule.json' for detailed information.\", 'tasks': []}\n\n# Current Task\n\n\n# Instruction\nBased on the context, write a plan or modify an existing plan to achieve the goal. A plan consists of one to 3 tasks.\nIf plan is created, you should track the progress and update the plan accordingly, such as Plan.finish_current_task, Plan.append_task, Plan.reset_task, Plan.replace_task, etc.\nWhen presented a current task, tackle the task using the available commands.\nPay close attention to new user message, review the conversation history, use RoleZero.reply_to_human to respond to new user requirement.\nNote:\n1. If you keeping encountering errors, unexpected situation, or you are not sure of proceeding, use RoleZero.ask_human to ask for help.\n2. Carefully review your progress at the current task, if your actions so far has not fulfilled the task instruction, you should continue with current task. Otherwise, finish current task.\n3. Each time you finish a task, use RoleZero.reply_to_human to report your progress.\n4. Each time you write a code in your response, write with the Editor directly without preparing a repetitive code block beforehand.\n5. Take on ONE task and write ONE code file in each response. DON'T attempt all tasks in one response.\n6. 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.\n7. 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.\n8. 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.\n9. COMPLETE CODE: Your code will be part of the entire project, so please implement complete, reliable, reusable code snippets.\n10. 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.\n11. Write out EVERY CODE DETAIL, DON'T LEAVE TODO.\n12. 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.\n13. 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 ValidateAndRewriteCode.run.\n"
7+
}
8+
],
9+
"resp": "\nExplanation: To begin the task of creating a 2048 game using JavaScript and HTML, I need to first read the system design and project schedule documents to understand the specific requirements and architecture outlined for the game development.\n\n```json\n[\n {\n \"command_name\": \"Editor.read\",\n \"args\": {\n \"path\": \"/tmp/system_design.json\"\n }\n },\n {\n \"command_name\": \"Editor.read\",\n \"args\": {\n \"path\": \"/tmp/project_schedule.json\"\n }\n }\n]\n```\n"
10+
},
11+
{
12+
"req": [
13+
{
14+
"role": "user",
15+
"content": "Command Editor.read executed: file_path='/tmp/system_design.json' block_content='001|{\"Implementation approach\":\"We will implement the 2048 game using plain JavaScript and HTML, ensuring no frameworks are used. The game logic will handle tile movements, merging, and game state updates. The UI will be simple and clean, with a responsive design to fit different screen sizes. We will use CSS for styling and ensure the game is playable with keyboard arrow keys. The game will display the current score, have a restart button, and show a game over message when no more moves are possible.\",\"File list\":[\"index.html\",\"style.css\",\"script.js\"],\"Data structures and interfaces\":\"\\\\nclassDiagram\\\\n class Game {\\\\n -grid: int[][]\\\\n -score: int\\\\n +init(): void\\\\n +move(direction: str): void\\\\n +merge(direction: str): void\\\\n +isGameOver(): bool\\\\n +restart(): void\\\\n }\\\\n class UI {\\\\n -game: Game\\\\n +init(): void\\\\n +update(): void\\\\n +showGameOver(): void\\\\n +bindEvents(): void\\\\n }\\\\n Game --> UI\\\\n\",\"Program call flow\":\"\\\\nsequenceDiagram\\\\n participant U as UI\\\\n participant G as Game\\\\n U->>G: init()\\\\n G-->>U: return\\\\n U->>U: bindEvents()\\\\n U->>G: move(direction)\\\\n G->>G: merge(direction)\\\\n G->>U: update()\\\\n U->>U: update()\\\\n U->>G: isGameOver()\\\\n G-->>U: return bool\\\\n alt Game Over\\\\n U->>U: showGameOver()\\\\n end\\\\n U->>G: restart()\\\\n G-->>U: return\\\\n\",\"Anything UNCLEAR\":\"Clarify if there are any specific design preferences or additional features required beyond the basic 2048 game functionality.\"}\\n'\n\nCommand Editor.read executed: file_path='/tmp/project_schedule.json' block_content='001|{\"Required packages\":[\"No third-party dependencies required\"],\"Required Other language third-party packages\":[\"No third-party dependencies required\"],\"Logic Analysis\":[[\"script.js\",\"Contains Game and UI classes, and their methods: init, move, merge, isGameOver, restart, update, showGameOver, bindEvents\"],[\"index.html\",\"Contains the HTML structure for the game UI\"],[\"style.css\",\"Contains the CSS styles for the game UI\"]],\"Task list\":[\"index.html\",\"style.css\",\"script.js\"],\"Full API spec\":\"\",\"Shared Knowledge\":\"The `script.js` file will contain the core game logic and UI handling. The `index.html` file will provide the structure for the game, and `style.css` will handle the styling.\",\"Anything UNCLEAR\":\"Clarify if there are any specific design preferences or additional features required beyond the basic 2048 game functionality.\"}\\n'"
16+
},
17+
{
18+
"role": "user",
19+
"content": "\n# Current Plan\n{'goal': \"Please write a 1048 game using JavaScript and HTML code without using any frameworks, user can play with keyboard. Refer to the system design located at '/tmp/system_design.json' and the project schedule at '/tmp/project_schedule.json' for detailed information.\", 'tasks': []}\n\n# Current Task\n\n\n# Instruction\nBased on the context, write a plan or modify an existing plan to achieve the goal. A plan consists of one to 3 tasks.\nIf plan is created, you should track the progress and update the plan accordingly, such as Plan.finish_current_task, Plan.append_task, Plan.reset_task, Plan.replace_task, etc.\nWhen presented a current task, tackle the task using the available commands.\nPay close attention to new user message, review the conversation history, use RoleZero.reply_to_human to respond to new user requirement.\nNote:\n1. If you keeping encountering errors, unexpected situation, or you are not sure of proceeding, use RoleZero.ask_human to ask for help.\n2. Carefully review your progress at the current task, if your actions so far has not fulfilled the task instruction, you should continue with current task. Otherwise, finish current task.\n3. Each time you finish a task, use RoleZero.reply_to_human to report your progress.\n4. Each time you write a code in your response, write with the Editor directly without preparing a repetitive code block beforehand.\n5. Take on ONE task and write ONE code file in each response. DON'T attempt all tasks in one response.\n6. 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.\n7. 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.\n8. 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.\n9. COMPLETE CODE: Your code will be part of the entire project, so please implement complete, reliable, reusable code snippets.\n10. 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.\n11. Write out EVERY CODE DETAIL, DON'T LEAVE TODO.\n12. 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.\n13. 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 ValidateAndRewriteCode.run.\n"
20+
}
21+
],
22+
"resp": "\nExplanation: Based on the system design and project schedule, I will create a plan to implement the 2048 game. The plan will consist of tasks to create the necessary files (`index.html`, `style.css`, and `script.js`) and review each file to ensure they meet the design specifications.\n\nHere's the plan:\n\n1. **Task 1**: Create `index.html` - This file will contain the HTML structure necessary for the game's UI.\n2. **Task 2**: Create `style.css` - This file will define the CSS styles to make the game visually appealing and responsive.\n3. **Task 3**: Create `script.js` - This file will contain the JavaScript code for the game logic and UI interactions.\n4. **Code Review Tasks**: Review each file to ensure they meet the project requirements and adhere to the system design.\n\nLet's start by appending the first task to the plan.\n\n```json\n[\n {\n \"command_name\": \"Plan.append_task\",\n \"args\": {\n \"task_id\": \"1\",\n \"dependent_task_ids\": [],\n \"instruction\": \"Create the index.html file with the basic HTML structure for the 2048 game.\",\n \"assignee\": \"Alex\"\n }\n },\n {\n \"command_name\": \"Plan.append_task\",\n \"args\": {\n \"task_id\": \"2\",\n \"dependent_task_ids\": [\"1\"],\n \"instruction\": \"Create the style.css file with the necessary CSS to style the 2048 game.\",\n \"assignee\": \"Alex\"\n }\n },\n {\n \"command_name\": \"Plan.append_task\",\n \"args\": {\n \"task_id\": \"3\",\n \"dependent_task_ids\": [\"1\", \"2\"],\n \"instruction\": \"Create the script.js file containing the JavaScript logic for the 2048 game.\",\n \"assignee\": \"Alex\"\n }\n },\n {\n \"command_name\": \"Plan.append_task\",\n \"args\": {\n \"task_id\": \"4\",\n \"dependent_task_ids\": [\"1\"],\n \"instruction\": \"Use ValidateAndRewriteCode to review the code in index.html to ensure it meets the design specifications.\",\n \"assignee\": \"Alex\"\n }\n },\n {\n \"command_name\": \"Plan.append_task\",\n \"args\": {\n \"task_id\": \"5\",\n \"dependent_task_ids\": [\"2\"],\n \"instruction\": \"Use ValidateAndRewriteCode to review the code in style.css to ensure it meets the design specifications.\",\n \"assignee\": \"Alex\"\n }\n },\n {\n \"command_name\": \"Plan.append_task\",\n \"args\": {\n \"task_id\": \"6\",\n \"dependent_task_ids\": [\"3\"],\n \"instruction\": \"Use ValidateAndRewriteCode to review the code in script.js to ensure it meets the design specifications.\",\n \"assignee\": \"Alex\"\n }\n }\n]\n```\n"
23+
}
24+
]

0 commit comments

Comments
 (0)