16
.coveragerc
|
|
@ -1,16 +0,0 @@
|
|||
[run]
|
||||
omit =
|
||||
*/site-packages/* \
|
||||
*\__init__.py
|
||||
[report]
|
||||
# Regexes for lines to exclude from consideration
|
||||
exclude_lines =
|
||||
"""
|
||||
'''
|
||||
pragma: no cover
|
||||
def __repr__
|
||||
if self.debug:
|
||||
raise AssertionError
|
||||
raise NotImplementedError
|
||||
except Exception as e:
|
||||
if __name__ == .__main__.:
|
||||
39
.devcontainer/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Dev container
|
||||
|
||||
This project includes a [dev container](https://containers.dev/), which lets you use a container as a full-featured dev environment.
|
||||
|
||||
You can use the dev container configuration in this folder to build and start running MetaGPT locally! For more, refer to the main README under the home directory.
|
||||
You can use it in [GitHub Codespaces](https://github.com/features/codespaces) or the [VS Code Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
|
||||
|
||||
## GitHub Codespaces
|
||||
<a href="https://codespaces.new/geekan/MetaGPT"><img src="https://github.com/codespaces/badge.svg" alt="Open in GitHub Codespaces"></a>
|
||||
|
||||
You may use the button above to open this repo in a Codespace
|
||||
|
||||
For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
|
||||
|
||||
## VS Code Dev Containers
|
||||
<a href="https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/geekan/MetaGPT"><img src="https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode" alt="Open in Dev Containers"></a>
|
||||
|
||||
Note: If you click this link you will open the main repo and not your local cloned repo, you can use this link and replace with your username and cloned repo name:
|
||||
https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/geekan/MetaGPT
|
||||
|
||||
|
||||
If you already have VS Code and Docker installed, you can use the button above to get started. This will cause VS Code to automatically install the Dev Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
|
||||
|
||||
You can also follow these steps to open this repo in a container using the VS Code Dev Containers extension:
|
||||
|
||||
1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
|
||||
|
||||
2. Open a locally cloned copy of the code:
|
||||
|
||||
- Fork and Clone this repository to your local filesystem.
|
||||
- Press <kbd>F1</kbd> and select the **Dev Containers: Open Folder in Container...** command.
|
||||
- Select the cloned copy of this folder, wait for the container to start, and try things out!
|
||||
|
||||
You can learn more in the [Dev Containers documentation](https://code.visualstudio.com/docs/devcontainers/containers).
|
||||
|
||||
## Tips and tricks
|
||||
|
||||
* If you are working with the same repository folder in a container and Windows, you'll want consistent line endings (otherwise you may see hundreds of changes in the SCM view). The `.gitattributes` file in the root of this repo will disable line ending conversion and should prevent this. See [tips and tricks](https://code.visualstudio.com/docs/devcontainers/tips-and-tricks#_resolving-git-line-ending-issues-in-containers-resulting-in-many-modified-files) for more info.
|
||||
* If you'd like to review the contents of the image used in this dev container, you can check it out in the [devcontainers/images](https://github.com/devcontainers/images/tree/main/src/python) repo.
|
||||
27
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/python
|
||||
{
|
||||
"name": "Python 3",
|
||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||
"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
// "features": {},
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
// Configure properties specific to VS Code.
|
||||
"vscode": {
|
||||
"settings": {},
|
||||
"extensions": [
|
||||
"streetsidesoftware.code-spell-checker"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
"postCreateCommand": "./.devcontainer/postCreateCommand.sh"
|
||||
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
}
|
||||
31
.devcontainer/docker-compose.yaml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
version: '3'
|
||||
services:
|
||||
metagpt:
|
||||
build:
|
||||
dockerfile: Dockerfile
|
||||
context: ..
|
||||
volumes:
|
||||
# Update this to wherever you want VS Code to mount the folder of your project
|
||||
- ..:/workspaces:cached
|
||||
networks:
|
||||
- metagpt-network
|
||||
# environment:
|
||||
# MONGO_ROOT_USERNAME: root
|
||||
# MONGO_ROOT_PASSWORD: example123
|
||||
# depends_on:
|
||||
# - mongo
|
||||
# mongo:
|
||||
# image: mongo
|
||||
# restart: unless-stopped
|
||||
# environment:
|
||||
# MONGO_INITDB_ROOT_USERNAME: root
|
||||
# MONGO_INITDB_ROOT_PASSWORD: example123
|
||||
# ports:
|
||||
# - "27017:27017"
|
||||
# networks:
|
||||
# - metagpt-network
|
||||
|
||||
networks:
|
||||
metagpt-network:
|
||||
driver: bridge
|
||||
|
||||
7
.devcontainer/postCreateCommand.sh
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Step 1: Ensure that NPM is installed on your system. Then install mermaid-js.
|
||||
npm --version
|
||||
sudo npm install -g @mermaid-js/mermaid-cli
|
||||
|
||||
# Step 2: Ensure that Python 3.9+ is installed on your system. You can check this by using:
|
||||
python --version
|
||||
pip install -e.
|
||||
7
.dockerignore
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
workspace
|
||||
tmp
|
||||
build
|
||||
workspace
|
||||
dist
|
||||
data
|
||||
geckodriver.log
|
||||
2
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*.html linguist-detectable=false
|
||||
|
||||
9
.gitignore
vendored
|
|
@ -148,11 +148,11 @@ allure-results
|
|||
.DS_Store
|
||||
.vscode
|
||||
|
||||
|
||||
*.txt
|
||||
scripts/set_env.sh
|
||||
log.txt
|
||||
docs/scripts/set_env.sh
|
||||
key.yaml
|
||||
output.json
|
||||
data
|
||||
data/output_add.json
|
||||
data.ms
|
||||
examples/nb/
|
||||
|
|
@ -161,3 +161,6 @@ examples/nb/
|
|||
workspace/*
|
||||
*.mmd
|
||||
tmp
|
||||
output.wav
|
||||
metagpt/roles/idea_agent.py
|
||||
.aider*
|
||||
|
|
|
|||
27
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
default_stages: [ commit ]
|
||||
|
||||
# Install
|
||||
# 1. pip install pre-commit
|
||||
# 2. pre-commit install(the first time you download the repo, it will be cached for future use)
|
||||
repos:
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.11.5
|
||||
hooks:
|
||||
- id: isort
|
||||
args: ['--profile', 'black']
|
||||
exclude: >-
|
||||
(?x)^(
|
||||
.*__init__\.py$
|
||||
)
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.0.284
|
||||
hooks:
|
||||
- id: ruff
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
args: ['--line-length', '120']
|
||||
25
Dockerfile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Use a base image with Python3.9 and Nodejs20 slim version
|
||||
FROM nikolaik/python-nodejs:python3.9-nodejs20-slim
|
||||
|
||||
# Install Debian software needed by MetaGPT and clean up in one RUN command to reduce image size
|
||||
RUN apt update &&\
|
||||
apt install -y git chromium fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends &&\
|
||||
apt clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Mermaid CLI globally
|
||||
ENV CHROME_BIN="/usr/bin/chromium" \
|
||||
PUPPETEER_CONFIG="/app/metagpt/config/puppeteer-config.json"\
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
|
||||
RUN npm install -g @mermaid-js/mermaid-cli &&\
|
||||
npm cache clean --force
|
||||
|
||||
# Install Python dependencies and install MetaGPT
|
||||
COPY . /app/metagpt
|
||||
WORKDIR /app/metagpt
|
||||
RUN mkdir workspace &&\
|
||||
pip install --no-cache-dir -r requirements.txt &&\
|
||||
pip install -e.
|
||||
|
||||
# Running with an infinite loop using the tail command
|
||||
CMD ["sh", "-c", "tail -f /dev/null"]
|
||||
|
||||
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License
|
||||
|
||||
Copyright (c) Chenglin Wu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
318
README.md
|
|
@ -1,59 +1,209 @@
|
|||
# MetaGPT: The Multi-Role Meta Programming Framework
|
||||
# MetaGPT: The Multi-Agent Framework
|
||||
|
||||
[English](./README.md) / [中文](./README_CN.md)
|
||||
<p align="center">
|
||||
<a href=""><img src="docs/resources/MetaGPT-new-log.png" alt="MetaGPT logo: Enable GPT to work in software company, collaborating to tackle more complex tasks." width="150px"></a>
|
||||
</p>
|
||||
|
||||
## Objective
|
||||
<p align="center">
|
||||
<b>Assign different roles to GPTs to form a collaborative software entity for complex tasks.</b>
|
||||
</p>
|
||||
|
||||
1. Our ultimate goal is to enable GPT to train, fine-tune, and ultimately, utilize itself, aiming to achieve a level of **self-evolution.**
|
||||
1. Once GPT can optimize itself, it will have the capacity to continually improve its own performance without the constant need for manual tuning. This kind of self-evolution enables an **autonomous cycle of growth** where the AI can identify areas for its own improvement, make necessary adjustments, and implement those changes to better achieve its objectives. **It could potentially lead to an exponential growth in the system's capabilities.**
|
||||
2. Currently, we have managed to enable GPT to work in teams, collaborating to tackle more complex tasks.
|
||||
1. For instance, `startup.py` consists of **product manager / architect / project manager / engineer**, it provides the full process of a **software company.**
|
||||
2. The team can cooperate and generate **user stories / competetive analysis / requirements / data structures / apis / files etc.**
|
||||
<p align="center">
|
||||
<a href="docs/README_CN.md"><img src="https://img.shields.io/badge/文档-中文版-blue.svg" alt="CN doc"></a>
|
||||
<a href="README.md"><img src="https://img.shields.io/badge/document-English-blue.svg" alt="EN doc"></a>
|
||||
<a href="docs/README_JA.md"><img src="https://img.shields.io/badge/ドキュメント-日本語-blue.svg" alt="JA doc"></a>
|
||||
<a href="https://discord.gg/wCp6Q3fsAk"><img src="https://img.shields.io/badge/Discord-Join-blue?logo=discord&logoColor=white&color=blue" alt="Discord Follow"></a>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
|
||||
<a href="docs/ROADMAP.md"><img src="https://img.shields.io/badge/ROADMAP-路线图-blue" alt="roadmap"></a>
|
||||
<a href="https://twitter.com/MetaGPT_"><img src="https://img.shields.io/twitter/follow/MetaGPT?style=social" alt="Twitter Follow"></a>
|
||||
</p>
|
||||
|
||||
### Philosophy
|
||||
<p align="center">
|
||||
<a href="https://airtable.com/appInfdG0eJ9J4NNL/shrEd9DrwVE3jX6oz"><img src="https://img.shields.io/badge/AgentStore-Waitlist-ffc107?logoColor=white" alt="AgentStore Waitlist"></a>
|
||||
<a href="https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/geekan/MetaGPT"><img src="https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode" alt="Open in Dev Containers"></a>
|
||||
<a href="https://codespaces.new/geekan/MetaGPT"><img src="https://img.shields.io/badge/Github_Codespace-Open-blue?logo=github" alt="Open in GitHub Codespaces"></a>
|
||||
<a href="https://huggingface.co/spaces/deepwisdom/MetaGPT" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20-Hugging%20Face-blue?color=blue&logoColor=white" /></a>
|
||||
</p>
|
||||
|
||||
The core assets of a software company are three: Executable Code, SOP (Standard Operating Procedures), and Team.
|
||||
There is a formula:
|
||||
1. MetaGPT takes a **one line requirement** as input and outputs **user stories / competitive analysis / requirements / data structures / APIs / documents, etc.**
|
||||
2. Internally, MetaGPT includes **product managers / architects / project managers / engineers.** It provides the entire process of a **software company along with carefully orchestrated SOPs.**
|
||||
1. `Code = SOP(Team)` is the core philosophy. We materialize SOP and apply it to teams composed of LLMs.
|
||||
|
||||

|
||||
|
||||
<p align="center">Software Company Multi-Role Schematic (Gradually Implementing)</p>
|
||||
|
||||
## MetaGPT's Abilities
|
||||
|
||||
|
||||
https://github.com/geekan/MetaGPT/assets/34952977/34345016-5d13-489d-b9f9-b82ace413419
|
||||
|
||||
```
|
||||
Executable Code = SOP(Team)
|
||||
```
|
||||
|
||||
We have practiced this process and expressed the SOP in the form of code,
|
||||
and the team itself only used large language models.
|
||||
|
||||
## Examples (fully generated by GPT-4)
|
||||
|
||||
1. Each column here is a requirement of using the command `python startup.py <requirement>`.
|
||||
2. By default, an investment of three dollars is made for each example and the program stops once this amount is depleted.
|
||||
1. It requires around **$0.2** (GPT-4 api's costs) to generate one example with analysis and design.
|
||||
2. It requires around **$2.0** (GPT-4 api's costs) to generate one example with a full project.
|
||||
For example, if you type `python startup.py "Design a RecSys like Toutiao"`, you would get many outputs, one of them is data & api design
|
||||
|
||||

|
||||
|
||||
It costs approximately **$0.2** (in GPT-4 API fees) to generate one example with analysis and design, and around **$2.0** for a full project.
|
||||
|
||||
|
||||
| | Design an MLOps/LLMOps framework that supports GPT-4 and other LLMs | Design a game like Candy Crush Saga | Design a RecSys like Toutiao | Design a roguelike game like NetHack | Design a search algorithm framework | Design a minimal pomodoro timer |
|
||||
|----------------------|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Competitive Analysis |  |  |  |  |  |  |
|
||||
| Data & API Design |  |  |  |  |  |  |
|
||||
| Sequence Flow |  |  |  |  |  |  |
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Step 1: Ensure that Python 3.9+ is installed on your system. You can check this by using:
|
||||
python --version
|
||||
### Installation Video Guide
|
||||
|
||||
# Step 2: Ensure that NPM is installed on your system. You can check this by using:
|
||||
- [Matthew Berman: How To Install MetaGPT - Build A Startup With One Prompt!!](https://youtu.be/uT75J_KG_aY)
|
||||
|
||||
### Traditional Installation
|
||||
|
||||
```bash
|
||||
# Step 1: Ensure that NPM is installed on your system. Then install mermaid-js. (If you don't have npm in your computer, please go to the Node.js official website to install Node.js https://nodejs.org/ and then you will have npm tool in your computer.)
|
||||
npm --version
|
||||
sudo npm install -g @mermaid-js/mermaid-cli
|
||||
|
||||
# Step 2: Ensure that Python 3.9+ is installed on your system. You can check this by using:
|
||||
python --version
|
||||
|
||||
# Step 3: Clone the repository to your local machine, and install it.
|
||||
git clone https://github.com/geekan/metagpt
|
||||
cd metagpt
|
||||
python setup.py install
|
||||
pip install -e.
|
||||
```
|
||||
|
||||
**Note:**
|
||||
|
||||
- If already have Chrome, Chromium, or MS Edge installed, you can skip downloading Chromium by setting the environment variable
|
||||
`PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` to `true`.
|
||||
|
||||
- Some people are [having issues](https://github.com/mermaidjs/mermaid.cli/issues/15) installing this tool globally. Installing it locally is an alternative solution,
|
||||
|
||||
```bash
|
||||
npm install @mermaid-js/mermaid-cli
|
||||
```
|
||||
|
||||
- don't forget to the configuration for mmdc in config.yml
|
||||
|
||||
```yml
|
||||
PUPPETEER_CONFIG: "./config/puppeteer-config.json"
|
||||
MMDC: "./node_modules/.bin/mmdc"
|
||||
```
|
||||
|
||||
- if `pip install -e.` fails with error `[Errno 13] Permission denied: '/usr/local/lib/python3.11/dist-packages/test-easy-install-13129.write-test'`, try instead running `pip install -e. --user`
|
||||
|
||||
- To convert Mermaid charts to SVG, PNG, and PDF formats. In addition to the Node.js version of Mermaid-CLI, you now have the option to use Python version Playwright, pyppeteer or mermaid.ink for this task.
|
||||
|
||||
- Playwright
|
||||
- **Install Playwright**
|
||||
|
||||
```bash
|
||||
pip install playwright
|
||||
```
|
||||
|
||||
- **Install the Required Browsers**
|
||||
|
||||
to support PDF conversion, please install Chrominum.
|
||||
|
||||
```bash
|
||||
playwright install --with-deps chromium
|
||||
```
|
||||
|
||||
- **modify `config.yaml`**
|
||||
|
||||
uncomment MERMAID_ENGINE from config.yaml and change it to `playwright`
|
||||
|
||||
```yaml
|
||||
MERMAID_ENGINE: playwright
|
||||
```
|
||||
|
||||
- pyppeteer
|
||||
- **Install pyppeteer**
|
||||
|
||||
```bash
|
||||
pip install pyppeteer
|
||||
```
|
||||
|
||||
- **Use your own Browsers**
|
||||
|
||||
pyppeteer allows you use installed browsers, please set the following envirment
|
||||
|
||||
```bash
|
||||
export PUPPETEER_EXECUTABLE_PATH = /path/to/your/chromium or edge or chrome
|
||||
```
|
||||
|
||||
please do not use this command to install browser, it is too old
|
||||
|
||||
```bash
|
||||
pyppeteer-install
|
||||
```
|
||||
|
||||
- **modify `config.yaml`**
|
||||
|
||||
uncomment MERMAID_ENGINE from config.yaml and change it to `pyppeteer`
|
||||
|
||||
```yaml
|
||||
MERMAID_ENGINE: pyppeteer
|
||||
```
|
||||
|
||||
- mermaid.ink
|
||||
- **modify `config.yaml`**
|
||||
|
||||
uncomment MERMAID_ENGINE from config.yaml and change it to `ink`
|
||||
|
||||
```yaml
|
||||
MERMAID_ENGINE: ink
|
||||
```
|
||||
|
||||
Note: this method does not support pdf export.
|
||||
|
||||
### Installation by Docker
|
||||
|
||||
```bash
|
||||
# Step 1: Download metagpt official image and prepare config.yaml
|
||||
docker pull metagpt/metagpt:latest
|
||||
mkdir -p /opt/metagpt/{config,workspace}
|
||||
docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
|
||||
vim /opt/metagpt/config/key.yaml # Change the config
|
||||
|
||||
# Step 2: Run metagpt demo with container
|
||||
docker run --rm \
|
||||
--privileged \
|
||||
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
|
||||
-v /opt/metagpt/workspace:/app/metagpt/workspace \
|
||||
metagpt/metagpt:latest \
|
||||
python startup.py "Write a cli snake game"
|
||||
|
||||
# You can also start a container and execute commands in it
|
||||
docker run --name metagpt -d \
|
||||
--privileged \
|
||||
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
|
||||
-v /opt/metagpt/workspace:/app/metagpt/workspace \
|
||||
metagpt/metagpt:latest
|
||||
|
||||
docker exec -it metagpt /bin/bash
|
||||
$ python startup.py "Write a cli snake game"
|
||||
```
|
||||
|
||||
The command `docker run ...` do the following things:
|
||||
|
||||
- Run in privileged mode to have permission to run the browser
|
||||
- Map host directory `/opt/metagpt/config` to container directory `/app/metagpt/config`
|
||||
- Map host directory `/opt/metagpt/workspace` to container directory `/app/metagpt/workspace`
|
||||
- Execute the demo command `python startup.py "Write a cli snake game"`
|
||||
|
||||
### Build image by yourself
|
||||
|
||||
```bash
|
||||
# You can also build metagpt image by yourself.
|
||||
git clone https://github.com/geekan/MetaGPT.git
|
||||
cd MetaGPT && docker build -t metagpt:custom .
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
- You can configure your `OPENAI_API_KEY` in `config/key.yaml / config/config.yaml / env`
|
||||
- Configure your `OPENAI_API_KEY` in any of `config/key.yaml / config/config.yaml / env`
|
||||
- Priority order: `config/key.yaml > config/config.yaml > env`
|
||||
|
||||
```bash
|
||||
|
|
@ -61,23 +211,61 @@ # Copy the configuration file and make the necessary modifications.
|
|||
cp config/config.yaml config/key.yaml
|
||||
```
|
||||
|
||||
| Variable Name | config/key.yaml | env |
|
||||
|--------------------------------------------|-------------------------------------------|--------------------------------|
|
||||
| OPENAI_API_KEY # Replace with your own key | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." |
|
||||
| OPENAI_API_BASE # Optional | OPENAI_API_BASE: "https://<YOUR_SITE>/v1" | export OPENAI_API_BASE="https://<YOUR_SITE>/v1" |
|
||||
| Variable Name | config/key.yaml | env |
|
||||
| ------------------------------------------ | ----------------------------------------- | ----------------------------------------------- |
|
||||
| OPENAI_API_KEY # Replace with your own key | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." |
|
||||
| OPENAI_API_BASE # Optional | OPENAI_API_BASE: "https://<YOUR_SITE>/v1" | export OPENAI_API_BASE="https://<YOUR_SITE>/v1" |
|
||||
|
||||
## Tutorial: Initiating a startup
|
||||
|
||||
```shell
|
||||
# Run the script
|
||||
python startup.py "Write a cli snake game"
|
||||
# Do not hire an engineer to implement the project
|
||||
python startup.py "Write a cli snake game" --implement False
|
||||
# Hire an engineer and perform code reviews
|
||||
python startup.py "Write a cli snake game" --code_review True
|
||||
```
|
||||
|
||||
After running the script, you can find your new project in the `workspace/` directory.
|
||||
|
||||
### What's behind? It's a startup fully driven by GPT. You're the investor
|
||||
| A software company consists of LLM-based roles (For example only) | A software company's SOP visualization (For example only) |
|
||||
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------|
|
||||
|  |  |
|
||||
### Preference of Platform or Tool
|
||||
|
||||
You can tell which platform or tool you want to use when stating your requirements.
|
||||
|
||||
```shell
|
||||
python startup.py "Write a cli snake game based on pygame"
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
NAME
|
||||
startup.py - We are a software startup comprised of AI. By investing in us, you are empowering a future filled with limitless possibilities.
|
||||
|
||||
SYNOPSIS
|
||||
startup.py IDEA <flags>
|
||||
|
||||
DESCRIPTION
|
||||
We are a software startup comprised of AI. By investing in us, you are empowering a future filled with limitless possibilities.
|
||||
|
||||
POSITIONAL ARGUMENTS
|
||||
IDEA
|
||||
Type: str
|
||||
Your innovative idea, such as "Creating a snake game."
|
||||
|
||||
FLAGS
|
||||
--investment=INVESTMENT
|
||||
Type: float
|
||||
Default: 3.0
|
||||
As an investor, you have the opportunity to contribute a certain dollar amount to this AI company.
|
||||
--n_round=N_ROUND
|
||||
Type: int
|
||||
Default: 5
|
||||
|
||||
NOTES
|
||||
You can also use flags syntax for POSITIONAL ARGUMENTS
|
||||
```
|
||||
|
||||
### Code walkthrough
|
||||
|
||||
|
|
@ -85,7 +273,7 @@ ### Code walkthrough
|
|||
from metagpt.software_company import SoftwareCompany
|
||||
from metagpt.roles import ProjectManager, ProductManager, Architect, Engineer
|
||||
|
||||
async def startup(idea: str, investment: str = '$3.0', n_round: int = 5):
|
||||
async def startup(idea: str, investment: float = 3.0, n_round: int = 5):
|
||||
"""Run a startup. Be a boss."""
|
||||
company = SoftwareCompany()
|
||||
company.hire([ProductManager(), Architect(), ProjectManager(), Engineer()])
|
||||
|
|
@ -94,38 +282,48 @@ ### Code walkthrough
|
|||
await company.run(n_round=n_round)
|
||||
```
|
||||
|
||||
## Tutorial: single role and LLM examples
|
||||
You can check `examples` for more details on single role (with knowledge base) and LLM only examples.
|
||||
|
||||
### The framework support single role as well, here's a simple sales role use case
|
||||
## QuickStart
|
||||
|
||||
```python
|
||||
from metagpt.const import DATA_PATH
|
||||
from metagpt.document_store import FaissStore
|
||||
from metagpt.roles import Sales
|
||||
It is difficult to install and configure the local environment for some users. The following tutorials will allow you to quickly experience the charm of MetaGPT.
|
||||
|
||||
store = FaissStore(DATA_PATH / 'example.pdf')
|
||||
role = Sales(profile='Sales', store=store)
|
||||
result = await role.run('Which facial cleanser is good for oily skin?')
|
||||
```
|
||||
- [MetaGPT quickstart](https://deepwisdom.feishu.cn/wiki/CyY9wdJc4iNqArku3Lncl4v8n2b)
|
||||
|
||||
### The framework also provide llm interfaces
|
||||
Try it on Huggingface Space
|
||||
- https://huggingface.co/spaces/deepwisdom/MetaGPT
|
||||
|
||||
```python
|
||||
from metagpt.llm import LLM
|
||||
## Citation
|
||||
|
||||
llm = LLM()
|
||||
await llm.aask('hello world')
|
||||
For now, cite the [Arxiv paper](https://arxiv.org/abs/2308.00352):
|
||||
|
||||
hello_msg = [{'role': 'user', 'content': 'hello'}]
|
||||
await llm.acompletion(hello_msg)
|
||||
```bibtex
|
||||
@misc{hong2023metagpt,
|
||||
title={MetaGPT: Meta Programming for Multi-Agent Collaborative Framework},
|
||||
author={Sirui Hong and Xiawu Zheng and Jonathan Chen and Yuheng Cheng and Jinlin Wang and Ceyao Zhang and Zili Wang and Steven Ka Shing Yau and Zijuan Lin and Liyang Zhou and Chenyu Ran and Lingfeng Xiao and Chenglin Wu},
|
||||
year={2023},
|
||||
eprint={2308.00352},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.AI}
|
||||
}
|
||||
```
|
||||
|
||||
## Contact Information
|
||||
|
||||
If you have any questions or feedback about this project, feel free to reach out to us. We appreciate your input!
|
||||
If you have any questions or feedback about this project, please feel free to contact us. We highly appreciate your suggestions!
|
||||
|
||||
- **Email:** alexanderwu@fuzhi.ai
|
||||
- **GitHub Issues:** For more technical issues, you can also create a new issue in our [GitHub repository](https://github.com/geekan/metagpt/issues).
|
||||
- **GitHub Issues:** For more technical inquiries, you can also create a new issue in our [GitHub repository](https://github.com/geekan/metagpt/issues).
|
||||
|
||||
We aim to respond to all inquiries within 2-3 business days.
|
||||
We will respond to all questions within 2-3 business days.
|
||||
|
||||
## Demo
|
||||
|
||||
https://github.com/geekan/MetaGPT/assets/2707039/5e8c1062-8c35-440f-bb20-2b0320f8d27d
|
||||
|
||||
## Join us
|
||||
|
||||
📢 Join Our Discord Channel!
|
||||
https://discord.gg/ZRHeExS6xv
|
||||
|
||||
Looking forward to seeing you there! 🎉
|
||||
|
|
|
|||
129
README_CN.md
|
|
@ -1,129 +0,0 @@
|
|||
# MetaGPT:多角色元编程框架
|
||||
|
||||
[English](./README.md) / [中文](./README_CN.md)
|
||||
|
||||
## 目标
|
||||
|
||||
1. 我们的最终目标是让 GPT 能够训练、微调,并最终利用自身,以实现**自我进化**
|
||||
1. 一旦 GPT 能够优化自身,它将有能力持续改进自己的性能,而无需经常手动调整。这种自我进化使得 AI 能够识别自身改进的领域,进行必要的调整,并实施那些改变以更好地达到其目标。**这可能导致系统能力的指数级增长**
|
||||
2. 目前,我们已经使 GPT 能够以团队的形式工作,协作处理更复杂的任务
|
||||
1. 例如,`startup.py` 包括**产品经理 / 架构师 / 项目经理 / 工程师**,它提供了一个**软件公司**的全过程
|
||||
2. 该团队可以合作并生成**用户故事 / 竞品分析 / 需求 / 数据结构 / APIs / 文件等**
|
||||
|
||||
### 哲学
|
||||
|
||||
软件公司核心资产有三:可运行的代码,SOP,团队。有公式:
|
||||
|
||||
```
|
||||
可运行的代码 = SOP(团队)
|
||||
```
|
||||
|
||||
我们践行了这个过程,并且将SOP以代码形式表达了出来,而团队本身仅使用了大模型
|
||||
|
||||
## 示例(均由 GPT-4 生成)
|
||||
|
||||
1. 这里的每一列都是使用命令 `python startup.py <requirement>` 的要求
|
||||
2. 默认情况下,每个示例的投资为三美元,一旦这个金额耗尽,程序就会停止
|
||||
1. 生成一个带有分析和设计的示例大约需要**$0.2** (GPT-4 api 的费用)
|
||||
2. 生成一个完整项目的示例大约需要**$2.0** (GPT-4 api 的费用)
|
||||
|
||||
| | 设计一个支持 GPT-4 和其他 LLMs 的 MLOps/LLMOps 框架 | 设计一个像 Candy Crush Saga 的游戏 | 设计一个像今日头条的 RecSys | 设计一个像 NetHack 的 roguelike 游戏 | 设计一个搜索算法框架 | 设计一个简约的番茄钟计时器 |
|
||||
|-------------|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
|
||||
| 竞品分析 |  |  |  |  |  |  |
|
||||
| 数据 & API 设计 |  |  |  |  |  |  |
|
||||
| 序列流程图 |  |  |  |  |  |  |
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
# 第 1 步:确保您的系统上安装了 Python 3.9+。您可以使用以下命令进行检查:
|
||||
python --version
|
||||
|
||||
# 第 2 步:确保您的系统上安装了 NPM。您可以使用以下命令进行检查:
|
||||
npm --version
|
||||
|
||||
# 第 3 步:克隆仓库到您的本地机器,并进行安装。
|
||||
git clone https://github.com/geekan/metagpt
|
||||
cd metagpt
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
- 您可以在 `config/key.yaml / config/config.yaml / env` 中配置您的 `OPENAI_API_KEY`
|
||||
- 优先级顺序:`config/key.yaml > config/config.yaml > env`
|
||||
|
||||
```bash
|
||||
# 复制配置文件并进行必要的修改。
|
||||
cp config/config.yaml config/key.yaml
|
||||
```
|
||||
|
||||
| 变量名 | config/key.yaml | env |
|
||||
|--------------------------------------------|-------------------------------------------|--------------------------------|
|
||||
| OPENAI_API_KEY # 用您自己的密钥替换 | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." |
|
||||
| OPENAI_API_BASE # 可选 | OPENAI_API_BASE: "https://<YOUR_SITE>/v1" | export OPENAI_API_BASE="https://<YOUR_SITE>/v1" |
|
||||
|
||||
## 示例:启动一个创业公司
|
||||
|
||||
```shell
|
||||
python startup.py "写一个命令行贪吃蛇"
|
||||
```
|
||||
|
||||
运行脚本后,您可以在 `workspace/` 目录中找到您的新项目。
|
||||
|
||||
### 背后的运作原理?这是一个完全由 GPT 驱动的创业公司,而您是投资者
|
||||
|
||||
| 一个完全由大语言模型角色构成的软件公司(仅示例) | 一个软件公司的SOP可视化(仅示例) |
|
||||
|--------------------------------------------------------------|-------------------------------------------------------------------|
|
||||
|  |  |
|
||||
|
||||
|
||||
### 代码实现
|
||||
|
||||
```python
|
||||
from metagpt.software_company import SoftwareCompany
|
||||
from metagpt.roles import ProjectManager, ProductManager, Architect, Engineer
|
||||
|
||||
async def startup(idea: str, investment: str = '$3.0', n_round: int = 5):
|
||||
"""运行一个创业公司。做一个老板"""
|
||||
company = SoftwareCompany()
|
||||
company.hire([ProductManager(), Architect(), ProjectManager(), Engineer()])
|
||||
company.invest(investment)
|
||||
company.start_project(idea)
|
||||
await company.run(n_round=n_round)
|
||||
```
|
||||
|
||||
## 示例:单角色能力与底层LLM调用
|
||||
|
||||
### 框架同样支持单角色能力,以下是一个销售角色(完整示例见examples)
|
||||
|
||||
```python
|
||||
from metagpt.const import DATA_PATH
|
||||
from metagpt.document_store import FaissStore
|
||||
from metagpt.roles import Sales
|
||||
|
||||
store = FaissStore(DATA_PATH / 'example.pdf')
|
||||
role = Sales(profile='Sales', store=store)
|
||||
result = await role.run('Which facial cleanser is good for oily skin?')
|
||||
```
|
||||
|
||||
### 框架也支持LLM的直接接口
|
||||
|
||||
```python
|
||||
from metagpt.llm import LLM
|
||||
|
||||
llm = LLM()
|
||||
await llm.aask('hello world')
|
||||
|
||||
hello_msg = [{'role': 'user', 'content': 'hello'}]
|
||||
await llm.acompletion(hello_msg)
|
||||
```
|
||||
|
||||
## 联系信息
|
||||
|
||||
如果您对这个项目有任何问题或反馈,欢迎联系我们。我们非常欢迎您的建议!
|
||||
|
||||
- **邮箱:** alexanderwu@fuzhi.ai
|
||||
- **GitHub 问题:** 对于更技术性的问题,您也可以在我们的 [GitHub 仓库](https://github.com/geekan/metagpt/issues) 中创建一个新的问题。
|
||||
|
||||
我们会在2-3个工作日内回复所有的查询。
|
||||
|
|
@ -1,20 +1,94 @@
|
|||
# DO NOT MODIFY THIS FILE, create a new key.yaml, define OPENAI_API_KEY.
|
||||
# The configuration of key.yaml has a higher priority and will not enter git
|
||||
|
||||
# Do not modify here, create a new key.yaml, define OPENAI_API_KEY. The configuration of key.yaml has a higher priority and will not enter git
|
||||
OPENAI_API_KEY: "YOUR_API_KEY"
|
||||
#OPENAI_API_BASE: "YOUR_API_BASE"
|
||||
#### if OpenAI
|
||||
## The official OPENAI_API_BASE is https://api.openai.com/v1
|
||||
## If the official OPENAI_API_BASE is not available, we recommend using the [openai-forward](https://github.com/beidongjiedeguang/openai-forward).
|
||||
## Or, you can configure OPENAI_PROXY to access official OPENAI_API_BASE.
|
||||
OPENAI_API_BASE: "https://api.openai.com/v1"
|
||||
#OPENAI_PROXY: "http://127.0.0.1:8118"
|
||||
#OPENAI_API_KEY: "YOUR_API_KEY"
|
||||
OPENAI_API_MODEL: "gpt-4"
|
||||
MAX_TOKENS: 1500
|
||||
RPM: 10
|
||||
|
||||
#### if Spark
|
||||
#SPARK_APPID : "YOUR_APPID"
|
||||
#SPARK_API_SECRET : "YOUR_APISecret"
|
||||
#SPARK_API_KEY : "YOUR_APIKey"
|
||||
#DOMAIN : "generalv2"
|
||||
#SPARK_URL : "ws://spark-api.xf-yun.com/v2.1/chat"
|
||||
|
||||
#### if Anthropic
|
||||
#Anthropic_API_KEY: "YOUR_API_KEY"
|
||||
|
||||
#### if AZURE, check https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb
|
||||
#### You can use ENGINE or DEPLOYMENT mode
|
||||
#OPENAI_API_TYPE: "azure"
|
||||
#OPENAI_API_BASE: "YOUR_AZURE_ENDPOINT"
|
||||
#OPENAI_API_KEY: "YOUR_AZURE_API_KEY"
|
||||
#OPENAI_API_VERSION: "YOUR_AZURE_API_VERSION"
|
||||
#DEPLOYMENT_NAME: "YOUR_DEPLOYMENT_NAME"
|
||||
#DEPLOYMENT_ID: "YOUR_DEPLOYMENT_ID"
|
||||
|
||||
#### for Search
|
||||
|
||||
## Supported values: serpapi/google/serper/ddg
|
||||
#SEARCH_ENGINE: serpapi
|
||||
|
||||
## Visit https://serpapi.com/ to get key.
|
||||
#SERPAPI_API_KEY: "YOUR_API_KEY"
|
||||
#
|
||||
|
||||
## Visit https://console.cloud.google.com/apis/credentials to get key.
|
||||
#GOOGLE_API_KEY: "YOUR_API_KEY"
|
||||
## Visit https://programmablesearchengine.google.com/controlpanel/create to get id.
|
||||
#GOOGLE_CSE_ID: "YOUR_CSE_ID"
|
||||
#
|
||||
#AZURE_OPENAI_KEY: "YOUR_API_KEY"
|
||||
#AZURE_OPENAI_ENDPOINT: "YOUR_API_BASE"
|
||||
#AZURE_DEPLOYMENT_NAME: "gpt-35"
|
||||
#AZURE_OPENAI_API_VERSION: "2023-03-15-preview"
|
||||
|
||||
## Visit https://serper.dev/ to get key.
|
||||
#SERPER_API_KEY: "YOUR_API_KEY"
|
||||
|
||||
#### for web access
|
||||
|
||||
## Supported values: playwright/selenium
|
||||
#WEB_BROWSER_ENGINE: playwright
|
||||
|
||||
## Supported values: chromium/firefox/webkit, visit https://playwright.dev/python/docs/api/class-browsertype
|
||||
##PLAYWRIGHT_BROWSER_TYPE: chromium
|
||||
|
||||
## Supported values: chrome/firefox/edge/ie, visit https://www.selenium.dev/documentation/webdriver/browsers/
|
||||
# SELENIUM_BROWSER_TYPE: chrome
|
||||
|
||||
#### for TTS
|
||||
|
||||
#AZURE_TTS_SUBSCRIPTION_KEY: "YOUR_API_KEY"
|
||||
#AZURE_TTS_REGION: "eastus"
|
||||
|
||||
#### for Stable Diffusion
|
||||
## Use SD service, based on https://github.com/AUTOMATIC1111/stable-diffusion-webui
|
||||
SD_URL: "YOUR_SD_URL"
|
||||
SD_T2I_API: "/sdapi/v1/txt2img"
|
||||
|
||||
#### for Execution
|
||||
#LONG_TERM_MEMORY: false
|
||||
|
||||
#### for Mermaid CLI
|
||||
## If you installed mmdc (Mermaid CLI) only for metagpt then enable the following configuration.
|
||||
#PUPPETEER_CONFIG: "./config/puppeteer-config.json"
|
||||
#MMDC: "./node_modules/.bin/mmdc"
|
||||
|
||||
|
||||
### for calc_usage
|
||||
# CALC_USAGE: false
|
||||
|
||||
### for Research
|
||||
MODEL_FOR_RESEARCHER_SUMMARY: gpt-3.5-turbo
|
||||
MODEL_FOR_RESEARCHER_REPORT: gpt-3.5-turbo-16k
|
||||
|
||||
### choose the engine for mermaid conversion,
|
||||
# default is nodejs, you can change it to playwright,pyppeteer or ink
|
||||
# MERMAID_ENGINE: nodejs
|
||||
|
||||
### browser path for pyppeteer engine, support Chrome, Chromium,MS Edge
|
||||
#PYPPETEER_EXECUTABLE_PATH: "/usr/bin/google-chrome-stable"
|
||||
|
||||
PROMPT_FORMAT: json #json or markdown
|
||||
6
config/puppeteer-config.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"executablePath": "/usr/bin/chromium",
|
||||
"args": [
|
||||
"--no-sandbox"
|
||||
]
|
||||
}
|
||||
183
docs/FAQ-EN.md
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
Our vision is to [extend human life](https://github.com/geekan/HowToLiveLonger) and [reduce working hours](https://github.com/geekan/MetaGPT/).
|
||||
|
||||
1. ### Convenient Link for Sharing this Document:
|
||||
|
||||
```
|
||||
- MetaGPT-Index/FAQ https://deepwisdom.feishu.cn/wiki/MsGnwQBjiif9c3koSJNcYaoSnu4
|
||||
```
|
||||
|
||||
2. ### Link
|
||||
|
||||
<!---->
|
||||
|
||||
1. Code:https://github.com/geekan/MetaGPT
|
||||
|
||||
1. Roadmap:https://github.com/geekan/MetaGPT/blob/main/docs/ROADMAP.md
|
||||
|
||||
1. EN
|
||||
|
||||
1. Demo Video: [MetaGPT: Multi-Agent AI Programming Framework](https://www.youtube.com/watch?v=8RNzxZBTW8M)
|
||||
2. Tutorial: [MetaGPT: Deploy POWERFUL Autonomous Ai Agents BETTER Than SUPERAGI!](https://www.youtube.com/watch?v=q16Gi9pTG_M&t=659s)
|
||||
3. Author's thoughts video(EN): [MetaGPT Matthew Berman](https://youtu.be/uT75J_KG_aY?si=EgbfQNAwD8F5Y1Ak)
|
||||
|
||||
1. CN
|
||||
|
||||
1. Demo Video: [MetaGPT:一行代码搭建你的虚拟公司_哔哩哔哩_bilibili](https://www.bilibili.com/video/BV1NP411C7GW/?spm_id_from=333.999.0.0&vd_source=735773c218b47da1b4bd1b98a33c5c77)
|
||||
1. Tutorial: [一个提示词写游戏 Flappy bird, 比AutoGPT强10倍的MetaGPT,最接近AGI的AI项目](https://youtu.be/Bp95b8yIH5c)
|
||||
2. Author's thoughts video(CN): [MetaGPT作者深度解析直播回放_哔哩哔哩_bilibili](https://www.bilibili.com/video/BV1Ru411V7XL/?spm_id_from=333.337.search-card.all.click)
|
||||
|
||||
<!---->
|
||||
|
||||
3. ### How to become a contributor?
|
||||
|
||||
<!---->
|
||||
|
||||
1. Choose a task from the Roadmap (or you can propose one). By submitting a PR, you can become a contributor and join the dev team.
|
||||
1. Current contributors come from backgrounds including: ByteDance AI Lab/DingDong/Didi/Xiaohongshu, Tencent/Baidu/MSRA/TikTok/BloomGPT Infra/Bilibili/CUHK/HKUST/CMU/UCB
|
||||
|
||||
<!---->
|
||||
|
||||
4. ### Chief Evangelist (Monthly Rotation)
|
||||
|
||||
MetaGPT Community - The position of Chief Evangelist rotates on a monthly basis. The primary responsibilities include:
|
||||
|
||||
1. Maintaining community FAQ documents, announcements, Github resources/READMEs.
|
||||
1. Responding to, answering, and distributing community questions within an average of 30 minutes, including on platforms like Github Issues, Discord and WeChat.
|
||||
1. Upholding a community atmosphere that is enthusiastic, genuine, and friendly.
|
||||
1. Encouraging everyone to become contributors and participate in projects that are closely related to achieving AGI (Artificial General Intelligence).
|
||||
1. (Optional) Organizing small-scale events, such as hackathons.
|
||||
|
||||
<!---->
|
||||
|
||||
5. ### FAQ
|
||||
|
||||
<!---->
|
||||
|
||||
1. Experience with the generated repo code:
|
||||
|
||||
1. https://github.com/geekan/MetaGPT/releases/tag/v0.1.0
|
||||
|
||||
1. Code truncation/ Parsing failure:
|
||||
|
||||
1. Check if it's due to exceeding length. Consider using the gpt-3.5-turbo-16k or other long token versions.
|
||||
|
||||
1. Success rate:
|
||||
|
||||
1. There hasn't been a quantitative analysis yet, but the success rate of code generated by GPT-4 is significantly higher than that of gpt-3.5-turbo.
|
||||
|
||||
1. Support for incremental, differential updates (if you wish to continue a half-done task):
|
||||
|
||||
1. Several prerequisite tasks are listed on the ROADMAP.
|
||||
|
||||
1. Can existing code be loaded?
|
||||
|
||||
1. It's not on the ROADMAP yet, but there are plans in place. It just requires some time.
|
||||
|
||||
1. Support for multiple programming languages and natural languages?
|
||||
|
||||
1. It's listed on ROADMAP.
|
||||
|
||||
1. Want to join the contributor team? How to proceed?
|
||||
|
||||
1. Merging a PR will get you into the contributor's team. The main ongoing tasks are all listed on the ROADMAP.
|
||||
|
||||
1. PRD stuck / unable to access/ connection interrupted
|
||||
|
||||
1. The official OPENAI_API_BASE address is `https://api.openai.com/v1`
|
||||
1. If the official OPENAI_API_BASE address is inaccessible in your environment (this can be verified with curl), it's recommended to configure using the reverse proxy OPENAI_API_BASE provided by libraries such as openai-forward. For instance, `OPENAI_API_BASE: "``https://api.openai-forward.com/v1``"`
|
||||
1. If the official OPENAI_API_BASE address is inaccessible in your environment (again, verifiable via curl), another option is to configure the OPENAI_PROXY parameter. This way, you can access the official OPENAI_API_BASE via a local proxy. If you don't need to access via a proxy, please do not enable this configuration; if accessing through a proxy is required, modify it to the correct proxy address. Note that when OPENAI_PROXY is enabled, don't set OPENAI_API_BASE.
|
||||
1. Note: OpenAI's default API design ends with a v1. An example of the correct configuration is: `OPENAI_API_BASE: "``https://api.openai.com/v1``"`
|
||||
|
||||
1. Absolutely! How can I assist you today?
|
||||
|
||||
1. Did you use Chi or a similar service? These services are prone to errors, and it seems that the error rate is higher when consuming 3.5k-4k tokens in GPT-4
|
||||
|
||||
1. What does Max token mean?
|
||||
|
||||
1. It's a configuration for OpenAI's maximum response length. If the response exceeds the max token, it will be truncated.
|
||||
|
||||
1. How to change the investment amount?
|
||||
|
||||
1. You can view all commands by typing `python startup.py --help`
|
||||
|
||||
1. Which version of Python is more stable?
|
||||
|
||||
1. python3.9 / python3.10
|
||||
|
||||
1. Can't use GPT-4, getting the error "The model gpt-4 does not exist."
|
||||
|
||||
1. OpenAI's official requirement: You can use GPT-4 only after spending $1 on OpenAI.
|
||||
1. Tip: Run some data with gpt-3.5-turbo (consume the free quota and $1), and then you should be able to use gpt-4.
|
||||
|
||||
1. Can games whose code has never been seen before be written?
|
||||
|
||||
1. Refer to the README. The recommendation system of Toutiao is one of the most complex systems in the world currently. Although it's not on GitHub, many discussions about it exist online. If it can visualize these, it suggests it can also summarize these discussions and convert them into code. The prompt would be something like "write a recommendation system similar to Toutiao". Note: this was approached in earlier versions of the software. The SOP of those versions was different; the current one adopts Elon Musk's five-step work method, emphasizing trimming down requirements as much as possible.
|
||||
|
||||
1. Under what circumstances would there typically be errors?
|
||||
|
||||
1. More than 500 lines of code: some function implementations may be left blank.
|
||||
1. When using a database, it often gets the implementation wrong — since the SQL database initialization process is usually not in the code.
|
||||
1. With more lines of code, there's a higher chance of false impressions, leading to calls to non-existent APIs.
|
||||
|
||||
1. Instructions for using SD Skills/UI Role:
|
||||
|
||||
1. Currently, there is a test script located in /tests/metagpt/roles. The file ui_role provides the corresponding code implementation. For testing, you can refer to the test_ui in the same directory.
|
||||
|
||||
1. The UI role takes over from the product manager role, extending the output from the 【UI Design draft】 provided by the product manager role. The UI role has implemented the UIDesign Action. Within the run of UIDesign, it processes the respective context, and based on the set template, outputs the UI. The output from the UI role includes:
|
||||
|
||||
1. UI Design Description:Describes the content to be designed and the design objectives.
|
||||
1. Selected Elements:Describes the elements in the design that need to be illustrated.
|
||||
1. HTML Layout:Outputs the HTML code for the page.
|
||||
1. CSS Styles (styles.css):Outputs the CSS code for the page.
|
||||
|
||||
1. Currently, the SD skill is a tool invoked by UIDesign. It instantiates the SDEngine, with specific code found in metagpt/tools/sd_engine.
|
||||
|
||||
1. Configuration instructions for SD Skills: The SD interface is currently deployed based on *https://github.com/AUTOMATIC1111/stable-diffusion-webui* **For environmental configurations and model downloads, please refer to the aforementioned GitHub repository. To initiate the SD service that supports API calls, run the command specified in cmd with the parameter nowebui, i.e.,
|
||||
|
||||
1. > python webui.py --enable-insecure-extension-access --port xxx --no-gradio-queue --nowebui
|
||||
1. Once it runs without errors, the interface will be accessible after approximately 1 minute when the model finishes loading.
|
||||
1. Configure SD_URL and SD_T2I_API in the config.yaml/key.yaml files.
|
||||
1. 
|
||||
1. SD_URL is the deployed server/machine IP, and Port is the specified port above, defaulting to 7860.
|
||||
1. > SD_URL: IP:Port
|
||||
|
||||
1. An error occurred during installation: "Another program is using this file...egg".
|
||||
|
||||
1. Delete the file and try again.
|
||||
1. Or manually execute`pip install -r requirements.txt`
|
||||
|
||||
1. The origin of the name MetaGPT?
|
||||
|
||||
1. The name was derived after iterating with GPT-4 over a dozen rounds. GPT-4 scored and suggested it.
|
||||
|
||||
1. Is there a more step-by-step installation tutorial?
|
||||
|
||||
1. Youtube(CN):[一个提示词写游戏 Flappy bird, 比AutoGPT强10倍的MetaGPT,最接近AGI的AI项目=一个软件公司产品经理+程序员](https://youtu.be/Bp95b8yIH5c)
|
||||
1. Youtube(EN)https://www.youtube.com/watch?v=q16Gi9pTG_M&t=659s
|
||||
2. video(EN): [MetaGPT Matthew Berman](https://youtu.be/uT75J_KG_aY?si=EgbfQNAwD8F5Y1Ak)
|
||||
|
||||
1. openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details
|
||||
|
||||
1. If you haven't exhausted your free quota, set RPM to 3 or lower in the settings.
|
||||
1. If your free quota is used up, consider adding funds to your account.
|
||||
|
||||
1. What does "borg" mean in n_borg?
|
||||
|
||||
1. [Wikipedia borg meaning ](https://en.wikipedia.org/wiki/Borg)
|
||||
1. The Borg civilization operates based on a hive or collective mentality, known as "the Collective." Every Borg individual is connected to the collective via a sophisticated subspace network, ensuring continuous oversight and guidance for every member. This collective consciousness allows them to not only "share the same thoughts" but also to adapt swiftly to new strategies. While individual members of the collective rarely communicate, the collective "voice" sometimes transmits aboard ships.
|
||||
|
||||
1. How to use the Claude API?
|
||||
|
||||
1. The full implementation of the Claude API is not provided in the current code.
|
||||
1. You can use the Claude API through third-party API conversion projects like: https://github.com/jtsang4/claude-to-chatgpt
|
||||
|
||||
1. Is Llama2 supported?
|
||||
|
||||
1. On the day Llama2 was released, some of the community members began experiments and found that output can be generated based on MetaGPT's structure. However, Llama2's context is too short to generate a complete project. Before regularly using Llama2, it's necessary to expand the context window to at least 8k. If anyone has good recommendations for expansion models or methods, please leave a comment.
|
||||
|
||||
1. `mermaid-cli getElementsByTagName SyntaxError: Unexpected token '.'`
|
||||
|
||||
1. Upgrade node to version 14.x or above:
|
||||
|
||||
1. `npm install -g n`
|
||||
1. `n stable` to install the stable version of node(v18.x)
|
||||
234
docs/README_CN.md
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
# MetaGPT: 多智能体框架
|
||||
|
||||
<p align="center">
|
||||
<a href=""><img src="resources/MetaGPT-new-log.png" alt="MetaGPT logo: 使 GPT 以软件公司的形式工作,协作处理更复杂的任务" width="150px"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<b>使 GPTs 组成软件公司,协作处理更复杂的任务</b>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="docs/README_CN.md"><img src="https://img.shields.io/badge/文档-中文版-blue.svg" alt="CN doc"></a>
|
||||
<a href="README.md"><img src="https://img.shields.io/badge/document-English-blue.svg" alt="EN doc"></a>
|
||||
<a href="docs/README_JA.md"><img src="https://img.shields.io/badge/ドキュメント-日本語-blue.svg" alt="JA doc"></a>
|
||||
<a href="https://discord.gg/wCp6Q3fsAk"><img src="https://img.shields.io/badge/Discord-Join-blue?logo=discord&logoColor=white&color=blue" alt="Discord Follow"></a>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
|
||||
<a href="docs/ROADMAP.md"><img src="https://img.shields.io/badge/ROADMAP-路线图-blue" alt="roadmap"></a>
|
||||
<a href="https://twitter.com/MetaGPT_"><img src="https://img.shields.io/twitter/follow/MetaGPT?style=social" alt="Twitter Follow"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://airtable.com/appInfdG0eJ9J4NNL/shrEd9DrwVE3jX6oz"><img src="https://img.shields.io/badge/AgentStore-Waitlist-ffc107?logoColor=white" alt="AgentStore Waitlist"></a>
|
||||
<a href="https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/geekan/MetaGPT"><img src="https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode" alt="Open in Dev Containers"></a>
|
||||
<a href="https://codespaces.new/geekan/MetaGPT"><img src="https://img.shields.io/badge/Github_Codespace-Open-blue?logo=github" alt="Open in GitHub Codespaces"></a>
|
||||
<a href="https://huggingface.co/spaces/deepwisdom/MetaGPT" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20-Hugging%20Face-blue?color=blue&logoColor=white" /></a>
|
||||
</p>
|
||||
|
||||
1. MetaGPT输入**一句话的老板需求**,输出**用户故事 / 竞品分析 / 需求 / 数据结构 / APIs / 文件等**
|
||||
2. MetaGPT内部包括**产品经理 / 架构师 / 项目经理 / 工程师**,它提供了一个**软件公司**的全过程与精心调配的SOP
|
||||
1. `Code = SOP(Team)` 是核心哲学。我们将SOP具象化,并且用于LLM构成的团队
|
||||
|
||||

|
||||
|
||||
<p align="center">软件公司多角色示意图(正在逐步实现)</p>
|
||||
|
||||
## MetaGPT 的能力
|
||||
|
||||
https://github.com/geekan/MetaGPT/assets/34952977/34345016-5d13-489d-b9f9-b82ace413419
|
||||
|
||||
|
||||
## 示例(均由 GPT-4 生成)
|
||||
|
||||
例如,键入`python startup.py "写个类似今日头条的推荐系统"`并回车,你会获得一系列输出,其一是数据结构与API设计
|
||||
|
||||

|
||||
|
||||
这需要大约**0.2美元**(GPT-4 API的费用)来生成一个带有分析和设计的示例,大约2.0美元用于一个完整的项目
|
||||
|
||||
## 安装
|
||||
|
||||
### 传统安装
|
||||
|
||||
```bash
|
||||
# 第 1 步:确保您的系统上安装了 NPM。并使用npm安装mermaid-js
|
||||
npm --version
|
||||
sudo npm install -g @mermaid-js/mermaid-cli
|
||||
|
||||
# 第 2 步:确保您的系统上安装了 Python 3.9+。您可以使用以下命令进行检查:
|
||||
python --version
|
||||
|
||||
# 第 3 步:克隆仓库到您的本地机器,并进行安装。
|
||||
git clone https://github.com/geekan/metagpt
|
||||
cd metagpt
|
||||
pip install -e.
|
||||
```
|
||||
|
||||
**注意:**
|
||||
|
||||
- 如果已经安装了Chrome、Chromium或MS Edge,可以通过将环境变量`PUPPETEER_SKIP_CHROMIUM_DOWNLOAD`设置为`true`来跳过下载Chromium。
|
||||
|
||||
- 一些人在全局安装此工具时遇到问题。在本地安装是替代解决方案,
|
||||
|
||||
```bash
|
||||
npm install @mermaid-js/mermaid-cli
|
||||
```
|
||||
|
||||
- 不要忘记在config.yml中为mmdc配置配置,
|
||||
|
||||
```yml
|
||||
PUPPETEER_CONFIG: "./config/puppeteer-config.json"
|
||||
MMDC: "./node_modules/.bin/mmdc"
|
||||
```
|
||||
|
||||
- 如果`pip install -e.`失败并显示错误`[Errno 13] Permission denied: '/usr/local/lib/python3.11/dist-packages/test-easy-install-13129.write-test'`,请尝试使用`pip install -e. --user`运行。
|
||||
|
||||
### Docker安装
|
||||
|
||||
```bash
|
||||
# 步骤1: 下载metagpt官方镜像并准备好config.yaml
|
||||
docker pull metagpt/metagpt:latest
|
||||
mkdir -p /opt/metagpt/{config,workspace}
|
||||
docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config.yaml > /opt/metagpt/config/config.yaml
|
||||
vim /opt/metagpt/config/config.yaml # 修改config
|
||||
|
||||
# 步骤2: 使用容器运行metagpt演示
|
||||
docker run --rm \
|
||||
--privileged \
|
||||
-v /opt/metagpt/config:/app/metagpt/config \
|
||||
-v /opt/metagpt/workspace:/app/metagpt/workspace \
|
||||
metagpt/metagpt:latest \
|
||||
python startup.py "Write a cli snake game"
|
||||
|
||||
# 您也可以启动一个容器并在其中执行命令
|
||||
docker run --name metagpt -d \
|
||||
--privileged \
|
||||
-v /opt/metagpt/config:/app/metagpt/config \
|
||||
-v /opt/metagpt/workspace:/app/metagpt/workspace \
|
||||
metagpt/metagpt:latest
|
||||
|
||||
docker exec -it metagpt /bin/bash
|
||||
$ python startup.py "Write a cli snake game"
|
||||
```
|
||||
|
||||
`docker run ...`做了以下事情:
|
||||
|
||||
- 以特权模式运行,有权限运行浏览器
|
||||
- 将主机目录 `/opt/metagpt/config` 映射到容器目录`/app/metagpt/config`
|
||||
- 将主机目录 `/opt/metagpt/workspace` 映射到容器目录 `/app/metagpt/workspace`
|
||||
- 执行演示命令 `python startup.py "Write a cli snake game"`
|
||||
|
||||
### 自己构建镜像
|
||||
|
||||
```bash
|
||||
# 您也可以自己构建metagpt镜像
|
||||
git clone https://github.com/geekan/MetaGPT.git
|
||||
cd MetaGPT && docker build -t metagpt:custom .
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
- 在 `config/key.yaml / config/config.yaml / env` 中配置您的 `OPENAI_API_KEY`
|
||||
- 优先级顺序:`config/key.yaml > config/config.yaml > env`
|
||||
|
||||
```bash
|
||||
# 复制配置文件并进行必要的修改
|
||||
cp config/config.yaml config/key.yaml
|
||||
```
|
||||
|
||||
| 变量名 | config/key.yaml | env |
|
||||
| ----------------------------------- | ----------------------------------------- | ----------------------------------------------- |
|
||||
| OPENAI_API_KEY # 用您自己的密钥替换 | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." |
|
||||
| OPENAI_API_BASE # 可选 | OPENAI_API_BASE: "https://<YOUR_SITE>/v1" | export OPENAI_API_BASE="https://<YOUR_SITE>/v1" |
|
||||
|
||||
## 示例:启动一个创业公司
|
||||
|
||||
```shell
|
||||
python startup.py "写一个命令行贪吃蛇"
|
||||
# 开启code review模式会花费更多的金钱, 但是会提升代码质量和成功率
|
||||
python startup.py "写一个命令行贪吃蛇" --code_review True
|
||||
```
|
||||
|
||||
运行脚本后,您可以在 `workspace/` 目录中找到您的新项目。
|
||||
### 平台或工具的倾向性
|
||||
可以在阐述需求时说明想要使用的平台或工具。
|
||||
例如:
|
||||
```shell
|
||||
python startup.py "写一个基于pygame的命令行贪吃蛇"
|
||||
```
|
||||
|
||||
### 使用
|
||||
|
||||
```
|
||||
名称
|
||||
startup.py - 我们是一家AI软件创业公司。通过投资我们,您将赋能一个充满无限可能的未来。
|
||||
|
||||
概要
|
||||
startup.py IDEA <flags>
|
||||
|
||||
描述
|
||||
我们是一家AI软件创业公司。通过投资我们,您将赋能一个充满无限可能的未来。
|
||||
|
||||
位置参数
|
||||
IDEA
|
||||
类型: str
|
||||
您的创新想法,例如"写一个命令行贪吃蛇。"
|
||||
|
||||
标志
|
||||
--investment=INVESTMENT
|
||||
类型: float
|
||||
默认值: 3.0
|
||||
作为投资者,您有机会向这家AI公司投入一定的美元金额。
|
||||
--n_round=N_ROUND
|
||||
类型: int
|
||||
默认值: 5
|
||||
|
||||
备注
|
||||
您也可以用`标志`的语法,来处理`位置参数`
|
||||
```
|
||||
|
||||
### 代码实现
|
||||
|
||||
```python
|
||||
from metagpt.software_company import SoftwareCompany
|
||||
from metagpt.roles import ProjectManager, ProductManager, Architect, Engineer
|
||||
|
||||
async def startup(idea: str, investment: float = 3.0, n_round: int = 5):
|
||||
"""运行一个创业公司。做一个老板"""
|
||||
company = SoftwareCompany()
|
||||
company.hire([ProductManager(), Architect(), ProjectManager(), Engineer()])
|
||||
company.invest(investment)
|
||||
company.start_project(idea)
|
||||
await company.run(n_round=n_round)
|
||||
```
|
||||
|
||||
你可以查看`examples`,其中有单角色(带知识库)的使用例子与仅LLM的使用例子。
|
||||
|
||||
## 快速体验
|
||||
对一些用户来说,安装配置本地环境是有困难的,下面这些教程能够让你快速体验到MetaGPT的魅力。
|
||||
|
||||
- [MetaGPT快速体验](https://deepwisdom.feishu.cn/wiki/Q8ycw6J9tiNXdHk66MRcIN8Pnlg)
|
||||
|
||||
可直接在Huggingface Space体验
|
||||
|
||||
- https://huggingface.co/spaces/deepwisdom/MetaGPT
|
||||
|
||||
## 联系信息
|
||||
|
||||
如果您对这个项目有任何问题或反馈,欢迎联系我们。我们非常欢迎您的建议!
|
||||
|
||||
- **邮箱:** alexanderwu@fuzhi.ai
|
||||
- **GitHub 问题:** 对于更技术性的问题,您也可以在我们的 [GitHub 仓库](https://github.com/geekan/metagpt/issues) 中创建一个新的问题。
|
||||
|
||||
我们会在2-3个工作日内回复所有问题。
|
||||
|
||||
## 演示
|
||||
|
||||
https://github.com/geekan/MetaGPT/assets/2707039/5e8c1062-8c35-440f-bb20-2b0320f8d27d
|
||||
|
||||
## 加入我们
|
||||
|
||||
📢 加入我们的Discord频道!
|
||||
https://discord.gg/ZRHeExS6xv
|
||||
|
||||
期待在那里与您相见!🎉
|
||||
259
docs/README_JA.md
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
# MetaGPT: マルチエージェントフレームワーク
|
||||
|
||||
<p align="center">
|
||||
<a href=""><img src="resources/MetaGPT-new-log.png" alt="MetaGPT ロゴ: GPT がソフトウェア会社で働けるようにし、協力してより複雑な仕事に取り組む。" width="150px"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<b>GPT にさまざまな役割を割り当てることで、複雑なタスクのための共同ソフトウェアエンティティを形成します。</b>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="docs/README_CN.md"><img src="https://img.shields.io/badge/文档-中文版-blue.svg" alt="CN doc"></a>
|
||||
<a href="README.md"><img src="https://img.shields.io/badge/document-English-blue.svg" alt="EN doc"></a>
|
||||
<a href="docs/README_JA.md"><img src="https://img.shields.io/badge/ドキュメント-日本語-blue.svg" alt="JA doc"></a>
|
||||
<a href="https://discord.gg/wCp6Q3fsAk"><img src="https://img.shields.io/badge/Discord-Join-blue?logo=discord&logoColor=white&color=blue" alt="Discord Follow"></a>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
|
||||
<a href="docs/ROADMAP.md"><img src="https://img.shields.io/badge/ROADMAP-路线图-blue" alt="roadmap"></a>
|
||||
<a href="https://twitter.com/MetaGPT_"><img src="https://img.shields.io/twitter/follow/MetaGPT?style=social" alt="Twitter Follow"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://airtable.com/appInfdG0eJ9J4NNL/shrEd9DrwVE3jX6oz"><img src="https://img.shields.io/badge/AgentStore-Waitlist-ffc107?logoColor=white" alt="AgentStore Waitlist"></a>
|
||||
<a href="https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/geekan/MetaGPT"><img src="https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode" alt="Open in Dev Containers"></a>
|
||||
<a href="https://codespaces.new/geekan/MetaGPT"><img src="https://img.shields.io/badge/Github_Codespace-Open-blue?logo=github" alt="Open in GitHub Codespaces"></a>
|
||||
<a href="https://huggingface.co/spaces/deepwisdom/MetaGPT" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20-Hugging%20Face-blue?color=blue&logoColor=white" /></a>
|
||||
</p>
|
||||
|
||||
1. MetaGPT は、**1 行の要件** を入力とし、**ユーザーストーリー / 競合分析 / 要件 / データ構造 / API / 文書など** を出力します。
|
||||
2. MetaGPT には、**プロダクト マネージャー、アーキテクト、プロジェクト マネージャー、エンジニア** が含まれています。MetaGPT は、**ソフトウェア会社のプロセス全体を、慎重に調整された SOP とともに提供します。**
|
||||
1. `Code = SOP(Team)` が基本理念です。私たちは SOP を具体化し、LLM で構成されるチームに適用します。
|
||||
|
||||

|
||||
|
||||
<p align="center">ソフトウェア会社のマルチロール図式(順次導入)</p>
|
||||
|
||||
## MetaGPTの能力
|
||||
|
||||
https://github.com/geekan/MetaGPT/assets/34952977/34345016-5d13-489d-b9f9-b82ace413419
|
||||
|
||||
|
||||
## 例(GPT-4 で完全生成)
|
||||
|
||||
例えば、`python startup.py "Toutiao のような RecSys をデザインする"`と入力すると、多くの出力が得られます
|
||||
|
||||

|
||||
|
||||
解析と設計を含む 1 つの例を生成するのに約 **$0.2**(GPT-4 の API 使用料)、完全なプロジェクトでは約 **$2.0** かかります。
|
||||
|
||||
## インストール
|
||||
|
||||
### インストールビデオガイド
|
||||
|
||||
- [Matthew Berman: How To Install MetaGPT - Build A Startup With One Prompt!!](https://youtu.be/uT75J_KG_aY)
|
||||
|
||||
### 伝統的なインストール
|
||||
|
||||
```bash
|
||||
# ステップ 1: NPM がシステムにインストールされていることを確認してください。次に mermaid-js をインストールします。
|
||||
npm --version
|
||||
sudo npm install -g @mermaid-js/mermaid-cli
|
||||
|
||||
# ステップ 2: Python 3.9+ がシステムにインストールされていることを確認してください。これを確認するには:
|
||||
python --version
|
||||
|
||||
# ステップ 3: リポジトリをローカルマシンにクローンし、インストールする。
|
||||
git clone https://github.com/geekan/metagpt
|
||||
cd metagpt
|
||||
pip install -e.
|
||||
```
|
||||
|
||||
**注:**
|
||||
|
||||
- すでに Chrome、Chromium、MS Edge がインストールされている場合は、環境変数 `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` を `true` に設定することで、
|
||||
Chromium のダウンロードをスキップすることができます。
|
||||
|
||||
- このツールをグローバルにインストールする[問題を抱えている](https://github.com/mermaidjs/mermaid.cli/issues/15)人もいます。ローカルにインストールするのが代替の解決策です、
|
||||
|
||||
```bash
|
||||
npm install @mermaid-js/mermaid-cli
|
||||
```
|
||||
|
||||
- config.yml に mmdc のコンフィギュレーションを記述するのを忘れないこと
|
||||
|
||||
```yml
|
||||
PUPPETEER_CONFIG: "./config/puppeteer-config.json"
|
||||
MMDC: "./node_modules/.bin/mmdc"
|
||||
```
|
||||
|
||||
- もし `pip install -e.` がエラー `[Errno 13] Permission denied: '/usr/local/lib/python3.11/dist-packages/test-easy-install-13129.write-test'` で失敗したら、代わりに `pip install -e. --user` を実行してみてください
|
||||
|
||||
### Docker によるインストール
|
||||
|
||||
```bash
|
||||
# ステップ 1: metagpt 公式イメージをダウンロードし、config.yaml を準備する
|
||||
docker pull metagpt/metagpt:latest
|
||||
mkdir -p /opt/metagpt/{config,workspace}
|
||||
docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
|
||||
vim /opt/metagpt/config/key.yaml # 設定を変更する
|
||||
|
||||
# ステップ 2: コンテナで metagpt デモを実行する
|
||||
docker run --rm \
|
||||
--privileged \
|
||||
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
|
||||
-v /opt/metagpt/workspace:/app/metagpt/workspace \
|
||||
metagpt/metagpt:latest \
|
||||
python startup.py "Write a cli snake game"
|
||||
|
||||
# コンテナを起動し、その中でコマンドを実行することもできます
|
||||
docker run --name metagpt -d \
|
||||
--privileged \
|
||||
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
|
||||
-v /opt/metagpt/workspace:/app/metagpt/workspace \
|
||||
metagpt/metagpt:latest
|
||||
|
||||
docker exec -it metagpt /bin/bash
|
||||
$ python startup.py "Write a cli snake game"
|
||||
```
|
||||
|
||||
コマンド `docker run ...` は以下のことを行います:
|
||||
|
||||
- 特権モードで実行し、ブラウザの実行権限を得る
|
||||
- ホストディレクトリ `/opt/metagpt/config` をコンテナディレクトリ `/app/metagpt/config` にマップする
|
||||
- ホストディレクトリ `/opt/metagpt/workspace` をコンテナディレクトリ `/app/metagpt/workspace` にマップする
|
||||
- デモコマンド `python startup.py "Write a cli snake game"` を実行する
|
||||
|
||||
### 自分でイメージをビルドする
|
||||
|
||||
```bash
|
||||
# また、自分で metagpt イメージを構築することもできます。
|
||||
git clone https://github.com/geekan/MetaGPT.git
|
||||
cd MetaGPT && docker build -t metagpt:custom .
|
||||
```
|
||||
|
||||
## 設定
|
||||
|
||||
- `OPENAI_API_KEY` を `config/key.yaml / config/config.yaml / env` のいずれかで設定します。
|
||||
- 優先順位は: `config/key.yaml > config/config.yaml > env` の順です。
|
||||
|
||||
```bash
|
||||
# 設定ファイルをコピーし、必要な修正を加える。
|
||||
cp config/config.yaml config/key.yaml
|
||||
```
|
||||
|
||||
| 変数名 | config/key.yaml | env |
|
||||
| --------------------------------------- | ----------------------------------------- | ----------------------------------------------- |
|
||||
| OPENAI_API_KEY # 自分のキーに置き換える | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." |
|
||||
| OPENAI_API_BASE # オプション | OPENAI_API_BASE: "https://<YOUR_SITE>/v1" | export OPENAI_API_BASE="https://<YOUR_SITE>/v1" |
|
||||
|
||||
## チュートリアル: スタートアップの開始
|
||||
|
||||
```shell
|
||||
# スクリプトの実行
|
||||
python startup.py "Write a cli snake game"
|
||||
# プロジェクトの実施にエンジニアを雇わないこと
|
||||
python startup.py "Write a cli snake game" --implement False
|
||||
# エンジニアを雇い、コードレビューを行う
|
||||
python startup.py "Write a cli snake game" --code_review True
|
||||
```
|
||||
|
||||
スクリプトを実行すると、`workspace/` ディレクトリに新しいプロジェクトが見つかります。
|
||||
|
||||
### プラットフォームまたはツールの設定
|
||||
|
||||
要件を述べるときに、どのプラットフォームまたはツールを使用するかを指定できます。
|
||||
|
||||
```shell
|
||||
python startup.py "pygame をベースとした cli ヘビゲームを書く"
|
||||
```
|
||||
|
||||
### 使用方法
|
||||
|
||||
```
|
||||
会社名
|
||||
startup.py - 私たちは AI で構成されたソフトウェア・スタートアップです。私たちに投資することは、無限の可能性に満ちた未来に力を与えることです。
|
||||
|
||||
シノプシス
|
||||
startup.py IDEA <flags>
|
||||
|
||||
説明
|
||||
私たちは AI で構成されたソフトウェア・スタートアップです。私たちに投資することは、無限の可能性に満ちた未来に力を与えることです。
|
||||
|
||||
位置引数
|
||||
IDEA
|
||||
型: str
|
||||
あなたの革新的なアイデア、例えば"スネークゲームを作る。"など
|
||||
|
||||
フラグ
|
||||
--investment=INVESTMENT
|
||||
型: float
|
||||
デフォルト: 3.0
|
||||
投資家として、あなたはこの AI 企業に一定の金額を拠出する機会がある。
|
||||
--n_round=N_ROUND
|
||||
型: int
|
||||
デフォルト: 5
|
||||
|
||||
注意事項
|
||||
位置引数にフラグ構文を使うこともできます
|
||||
```
|
||||
|
||||
### コードウォークスルー
|
||||
|
||||
```python
|
||||
from metagpt.software_company import SoftwareCompany
|
||||
from metagpt.roles import ProjectManager, ProductManager, Architect, Engineer
|
||||
|
||||
async def startup(idea: str, investment: float = 3.0, n_round: int = 5):
|
||||
"""スタートアップを実行する。ボスになる。"""
|
||||
company = SoftwareCompany()
|
||||
company.hire([ProductManager(), Architect(), ProjectManager(), Engineer()])
|
||||
company.invest(investment)
|
||||
company.start_project(idea)
|
||||
await company.run(n_round=n_round)
|
||||
```
|
||||
|
||||
`examples` でシングル・ロール(ナレッジ・ベース付き)と LLM のみの例を詳しく見ることができます。
|
||||
|
||||
## クイックスタート
|
||||
|
||||
ローカル環境のインストールや設定は、ユーザーによっては難しいものです。以下のチュートリアルで MetaGPT の魅力をすぐに体験できます。
|
||||
|
||||
- [MetaGPT クイックスタート](https://deepwisdom.feishu.cn/wiki/CyY9wdJc4iNqArku3Lncl4v8n2b)
|
||||
|
||||
Hugging Face Space で試す
|
||||
- https://huggingface.co/spaces/deepwisdom/MetaGPT
|
||||
|
||||
## 引用
|
||||
|
||||
現時点では、[Arxiv 論文](https://arxiv.org/abs/2308.00352)を引用してください:
|
||||
|
||||
```bibtex
|
||||
@misc{hong2023metagpt,
|
||||
title={MetaGPT: Meta Programming for Multi-Agent Collaborative Framework},
|
||||
author={Sirui Hong and Xiawu Zheng and Jonathan Chen and Yuheng Cheng and Jinlin Wang and Ceyao Zhang and Zili Wang and Steven Ka Shing Yau and Zijuan Lin and Liyang Zhou and Chenyu Ran and Lingfeng Xiao and Chenglin Wu},
|
||||
year={2023},
|
||||
eprint={2308.00352},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.AI}
|
||||
}
|
||||
```
|
||||
|
||||
## お問い合わせ先
|
||||
|
||||
このプロジェクトに関するご質問やご意見がございましたら、お気軽にお問い合わせください。皆様のご意見をお待ちしております!
|
||||
|
||||
- **Email:** alexanderwu@fuzhi.ai
|
||||
- **GitHub Issues:** 技術的なお問い合わせについては、[GitHub リポジトリ](https://github.com/geekan/metagpt/issues) に新しい issue を作成することもできます。
|
||||
|
||||
ご質問には 2-3 営業日以内に回答いたします。
|
||||
|
||||
## デモ
|
||||
|
||||
https://github.com/geekan/MetaGPT/assets/2707039/5e8c1062-8c35-440f-bb20-2b0320f8d27d
|
||||
|
||||
## 参加する
|
||||
|
||||
📢 Discord チャンネルに参加してください!
|
||||
https://discord.gg/ZRHeExS6xv
|
||||
|
||||
お会いできることを楽しみにしています! 🎉
|
||||
84
docs/ROADMAP.md
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
## Roadmap
|
||||
|
||||
### Long-term Objective
|
||||
|
||||
Enable MetaGPT to self-evolve, accomplishing self-training, fine-tuning, optimization, utilization, and updates.
|
||||
|
||||
### Short-term Objective
|
||||
|
||||
1. Become the multi-agent framework with the highest ROI.
|
||||
2. Support fully automatic implementation of medium-sized projects (around 2000 lines of code).
|
||||
3. Implement most identified tasks, reaching version 0.5.
|
||||
|
||||
### Tasks
|
||||
|
||||
To reach version v0.5, approximately 70% of the following tasks need to be completed.
|
||||
|
||||
1. Usability
|
||||
1. Release v0.01 pip package to try to solve issues like npm installation (though not necessarily successfully)
|
||||
2. Support for overall save and recovery of software companies
|
||||
3. Support human confirmation and modification during the process
|
||||
4. Support process caching: Consider carefully whether to add server caching mechanism
|
||||
5. Resolve occasional failure to follow instruction under current prompts, causing code parsing errors, through stricter system prompts
|
||||
6. Write documentation, describing the current features and usage at all levels
|
||||
7. ~~Support Docker~~
|
||||
2. Features
|
||||
1. Support a more standard and stable parser (need to analyze the format that the current LLM is better at)
|
||||
2. ~~Establish a separate output queue, differentiated from the message queue~~
|
||||
3. Attempt to atomize all role work, but this may significantly increase token overhead
|
||||
4. Complete the design and implementation of module breakdown
|
||||
5. Support various modes of memory: clearly distinguish between long-term and short-term memory
|
||||
6. Perfect the test role, and carry out necessary interactions with humans
|
||||
7. Provide full mode instead of the current fast mode, allowing natural communication between roles
|
||||
8. Implement SkillManager and the process of incremental Skill learning
|
||||
9. Automatically get RPM and configure it by calling the corresponding openai page, so that each key does not need to be manually configured
|
||||
3. Strategies
|
||||
1. Support ReAct strategy
|
||||
2. Support CoT strategy
|
||||
3. Support ToT strategy
|
||||
4. Support Reflection strategy
|
||||
4. Actions
|
||||
1. Implementation: Search
|
||||
2. Implementation: Knowledge search, supporting 10+ data formats
|
||||
3. Implementation: Data EDA
|
||||
4. Implementation: Review
|
||||
5. Implementation: Add Document
|
||||
6. Implementation: Delete Document
|
||||
7. Implementation: Self-training
|
||||
8. Implementation: DebugError
|
||||
9. Implementation: Generate reliable unit tests based on YAPI
|
||||
10. Implementation: Self-evaluation
|
||||
11. Implementation: AI Invocation
|
||||
12. Implementation: Learning and using third-party standard libraries
|
||||
13. Implementation: Data collection
|
||||
14. Implementation: AI training
|
||||
15. Implementation: Run code
|
||||
16. Implementation: Web access
|
||||
5. Plugins: Compatibility with plugin system
|
||||
6. Tools
|
||||
1. ~~Support SERPER api~~
|
||||
2. ~~Support Selenium apis~~
|
||||
3. ~~Support Playwright apis~~
|
||||
7. Roles
|
||||
1. Perfect the action pool/skill pool for each role
|
||||
2. Red Book blogger
|
||||
3. E-commerce seller
|
||||
4. Data analyst
|
||||
5. News observer
|
||||
6. Institutional researcher
|
||||
8. Evaluation
|
||||
1. Support an evaluation on a game dataset
|
||||
2. Reproduce papers, implement full skill acquisition for a single game role, achieving SOTA results
|
||||
3. Support an evaluation on a math dataset
|
||||
4. Reproduce papers, achieving SOTA results for current mathematical problem solving process
|
||||
9. LLM
|
||||
1. Support Claude underlying API
|
||||
2. ~~Support Azure asynchronous API~~
|
||||
3. Support streaming version of all APIs
|
||||
4. ~~Make gpt-3.5-turbo available (HARD)~~
|
||||
10. Other
|
||||
1. Clean up existing unused code
|
||||
2. Unify all code styles and establish contribution standards
|
||||
3. Multi-language support
|
||||
4. Multi-programming-language support
|
||||
BIN
docs/resources/MetaGPT-logo.jpeg
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
docs/resources/MetaGPT-logo.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
docs/resources/MetaGPT-new-log.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 145 KiB |
|
Before Width: | Height: | Size: 183 KiB After Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 173 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 143 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 132 KiB After Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 183 KiB After Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
100
examples/agent_creator.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
'''
|
||||
Filename: MetaGPT/examples/agent_creator.py
|
||||
Created Date: Tuesday, September 12th 2023, 3:28:37 pm
|
||||
Author: garylin2099
|
||||
'''
|
||||
import re
|
||||
|
||||
from metagpt.const import PROJECT_ROOT, WORKSPACE_ROOT
|
||||
from metagpt.actions import Action
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.logs import logger
|
||||
|
||||
with open(PROJECT_ROOT / "examples/build_customized_agent.py", "r") as f:
|
||||
# use official example script to guide AgentCreator
|
||||
MULTI_ACTION_AGENT_CODE_EXAMPLE = f.read()
|
||||
|
||||
class CreateAgent(Action):
|
||||
|
||||
PROMPT_TEMPLATE = """
|
||||
### BACKGROUND
|
||||
You are using an agent framework called metagpt to write agents capable of different actions,
|
||||
the usage of metagpt can be illustrated by the following example:
|
||||
### EXAMPLE STARTS AT THIS LINE
|
||||
{example}
|
||||
### EXAMPLE ENDS AT THIS LINE
|
||||
### TASK
|
||||
Now you should create an agent with appropriate actions based on the instruction, consider carefully about
|
||||
the PROMPT_TEMPLATE of all actions and when to call self._aask()
|
||||
### INSTRUCTION
|
||||
{instruction}
|
||||
### YOUR CODE
|
||||
Return ```python your_code_here ``` with NO other texts, your code:
|
||||
"""
|
||||
|
||||
async def run(self, example: str, instruction: str):
|
||||
|
||||
prompt = self.PROMPT_TEMPLATE.format(example=example, instruction=instruction)
|
||||
# logger.info(prompt)
|
||||
|
||||
rsp = await self._aask(prompt)
|
||||
|
||||
code_text = CreateAgent.parse_code(rsp)
|
||||
|
||||
return code_text
|
||||
|
||||
@staticmethod
|
||||
def parse_code(rsp):
|
||||
pattern = r'```python(.*)```'
|
||||
match = re.search(pattern, rsp, re.DOTALL)
|
||||
code_text = match.group(1) if match else ""
|
||||
with open(WORKSPACE_ROOT / "agent_created_agent.py", "w") as f:
|
||||
f.write(code_text)
|
||||
return code_text
|
||||
|
||||
class AgentCreator(Role):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "Matrix",
|
||||
profile: str = "AgentCreator",
|
||||
agent_template: str = MULTI_ACTION_AGENT_CODE_EXAMPLE,
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(name, profile, **kwargs)
|
||||
self._init_actions([CreateAgent])
|
||||
self.agent_template = agent_template
|
||||
|
||||
async def _act(self) -> Message:
|
||||
logger.info(f"{self._setting}: ready to {self._rc.todo}")
|
||||
todo = self._rc.todo
|
||||
msg = self._rc.memory.get()[-1]
|
||||
|
||||
instruction = msg.content
|
||||
code_text = await CreateAgent().run(example=self.agent_template, instruction=instruction)
|
||||
msg = Message(content=code_text, role=self.profile, cause_by=todo)
|
||||
|
||||
return msg
|
||||
|
||||
if __name__ == "__main__":
|
||||
import asyncio
|
||||
|
||||
async def main():
|
||||
|
||||
agent_template = MULTI_ACTION_AGENT_CODE_EXAMPLE
|
||||
|
||||
creator = AgentCreator(agent_template=agent_template)
|
||||
|
||||
# msg = """Write an agent called SimpleTester that will take any code snippet (str)
|
||||
# and return a testing code (str) for testing
|
||||
# the given code snippet. Use pytest as the testing framework."""
|
||||
|
||||
msg = """
|
||||
Write an agent called SimpleTester that will take any code snippet (str) and do the following:
|
||||
1. write a testing code (str) for testing the given code snippet, save the testing code as a .py file in the current working directory;
|
||||
2. run the testing code.
|
||||
You can use pytest as the testing framework.
|
||||
"""
|
||||
await creator.run(msg)
|
||||
|
||||
asyncio.run(main())
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/5/25 16:24
|
||||
@Author : alexanderwu
|
||||
@File : azure_hello_world.py
|
||||
"""
|
||||
from metagpt.logs import logger
|
||||
from metagpt.provider import AzureGPTAPI
|
||||
|
||||
|
||||
def azure_gpt_api():
|
||||
"""Currently, Azure only supports synchronous mode."""
|
||||
api = AzureGPTAPI()
|
||||
logger.info(api.ask('write python hello world.'))
|
||||
logger.info(api.completion([{'role': 'user', 'content': 'hello'}]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
azure_gpt_api()
|
||||
139
examples/build_customized_agent.py
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
'''
|
||||
Filename: MetaGPT/examples/build_customized_agent.py
|
||||
Created Date: Tuesday, September 19th 2023, 6:52:25 pm
|
||||
Author: garylin2099
|
||||
'''
|
||||
import re
|
||||
import subprocess
|
||||
import asyncio
|
||||
|
||||
import fire
|
||||
|
||||
from metagpt.actions import Action
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.logs import logger
|
||||
|
||||
class SimpleWriteCode(Action):
|
||||
|
||||
PROMPT_TEMPLATE = """
|
||||
Write a python function that can {instruction} and provide two runnnable test cases.
|
||||
Return ```python your_code_here ``` with NO other texts,
|
||||
example:
|
||||
```python
|
||||
# function
|
||||
def add(a, b):
|
||||
return a + b
|
||||
# test cases
|
||||
print(add(1, 2))
|
||||
print(add(3, 4))
|
||||
```
|
||||
your code:
|
||||
"""
|
||||
|
||||
def __init__(self, name="SimpleWriteCode", context=None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
|
||||
async def run(self, instruction: str):
|
||||
|
||||
prompt = self.PROMPT_TEMPLATE.format(instruction=instruction)
|
||||
|
||||
rsp = await self._aask(prompt)
|
||||
|
||||
code_text = SimpleWriteCode.parse_code(rsp)
|
||||
|
||||
return code_text
|
||||
|
||||
@staticmethod
|
||||
def parse_code(rsp):
|
||||
pattern = r'```python(.*)```'
|
||||
match = re.search(pattern, rsp, re.DOTALL)
|
||||
code_text = match.group(1) if match else rsp
|
||||
return code_text
|
||||
|
||||
class SimpleRunCode(Action):
|
||||
def __init__(self, name="SimpleRunCode", context=None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
|
||||
async def run(self, code_text: str):
|
||||
result = subprocess.run(["python3", "-c", code_text], capture_output=True, text=True)
|
||||
code_result = result.stdout
|
||||
logger.info(f"{code_result=}")
|
||||
return code_result
|
||||
|
||||
class SimpleCoder(Role):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "Alice",
|
||||
profile: str = "SimpleCoder",
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(name, profile, **kwargs)
|
||||
self._init_actions([SimpleWriteCode])
|
||||
|
||||
async def _act(self) -> Message:
|
||||
logger.info(f"{self._setting}: ready to {self._rc.todo}")
|
||||
todo = self._rc.todo
|
||||
|
||||
msg = self._rc.memory.get()[-1] # retrieve the latest memory
|
||||
instruction = msg.content
|
||||
|
||||
code_text = await SimpleWriteCode().run(instruction)
|
||||
msg = Message(content=code_text, role=self.profile, cause_by=todo)
|
||||
|
||||
return msg
|
||||
|
||||
class RunnableCoder(Role):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "Alice",
|
||||
profile: str = "RunnableCoder",
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(name, profile, **kwargs)
|
||||
self._init_actions([SimpleWriteCode, SimpleRunCode])
|
||||
|
||||
async def _think(self) -> None:
|
||||
if self._rc.todo is None:
|
||||
self._set_state(0)
|
||||
return
|
||||
|
||||
if self._rc.state + 1 < len(self._states):
|
||||
self._set_state(self._rc.state + 1)
|
||||
else:
|
||||
self._rc.todo = None
|
||||
|
||||
async def _act(self) -> Message:
|
||||
logger.info(f"{self._setting}: ready to {self._rc.todo}")
|
||||
todo = self._rc.todo
|
||||
msg = self._rc.memory.get()[-1]
|
||||
|
||||
if isinstance(todo, SimpleWriteCode):
|
||||
instruction = msg.content
|
||||
result = await SimpleWriteCode().run(instruction)
|
||||
|
||||
elif isinstance(todo, SimpleRunCode):
|
||||
code_text = msg.content
|
||||
result = await SimpleRunCode().run(code_text)
|
||||
|
||||
msg = Message(content=result, role=self.profile, cause_by=todo)
|
||||
self._rc.memory.add(msg)
|
||||
return msg
|
||||
|
||||
async def _react(self) -> Message:
|
||||
while True:
|
||||
await self._think()
|
||||
if self._rc.todo is None:
|
||||
break
|
||||
await self._act()
|
||||
return Message(content="All job done", role=self.profile)
|
||||
|
||||
def main(msg="write a function that calculates the sum of a list"):
|
||||
# role = SimpleCoder()
|
||||
role = RunnableCoder()
|
||||
logger.info(msg)
|
||||
result = asyncio.run(role.run(msg))
|
||||
logger.info(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
fire.Fire(main)
|
||||
148
examples/debate.py
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
'''
|
||||
Filename: MetaGPT/examples/debate.py
|
||||
Created Date: Tuesday, September 19th 2023, 6:52:25 pm
|
||||
Author: garylin2099
|
||||
'''
|
||||
import asyncio
|
||||
import platform
|
||||
import fire
|
||||
|
||||
from metagpt.software_company import SoftwareCompany
|
||||
from metagpt.actions import Action, BossRequirement
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.logs import logger
|
||||
|
||||
class ShoutOut(Action):
|
||||
"""Action: Shout out loudly in a debate (quarrel)"""
|
||||
|
||||
PROMPT_TEMPLATE = """
|
||||
## BACKGROUND
|
||||
Suppose you are {name}, you are in a debate with {opponent_name}.
|
||||
## DEBATE HISTORY
|
||||
Previous rounds:
|
||||
{context}
|
||||
## YOUR TURN
|
||||
Now it's your turn, you should closely respond to your opponent's latest argument, state your position, defend your arguments, and attack your opponent's arguments,
|
||||
craft a strong and emotional response in 80 words, in {name}'s rhetoric and viewpoints, your will argue:
|
||||
"""
|
||||
|
||||
def __init__(self, name="ShoutOut", context=None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
|
||||
async def run(self, context: str, name: str, opponent_name: str):
|
||||
|
||||
prompt = self.PROMPT_TEMPLATE.format(context=context, name=name, opponent_name=opponent_name)
|
||||
# logger.info(prompt)
|
||||
|
||||
rsp = await self._aask(prompt)
|
||||
|
||||
return rsp
|
||||
|
||||
class Trump(Role):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "Trump",
|
||||
profile: str = "Republican",
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(name, profile, **kwargs)
|
||||
self._init_actions([ShoutOut])
|
||||
self._watch([ShoutOut])
|
||||
self.name = "Trump"
|
||||
self.opponent_name = "Biden"
|
||||
|
||||
async def _observe(self) -> int:
|
||||
await super()._observe()
|
||||
# accept messages sent (from opponent) to self, disregard own messages from the last round
|
||||
self._rc.news = [msg for msg in self._rc.news if msg.send_to == self.name]
|
||||
return len(self._rc.news)
|
||||
|
||||
async def _act(self) -> Message:
|
||||
logger.info(f"{self._setting}: ready to {self._rc.todo}")
|
||||
|
||||
msg_history = self._rc.memory.get_by_actions([ShoutOut])
|
||||
context = []
|
||||
for m in msg_history:
|
||||
context.append(str(m))
|
||||
context = "\n".join(context)
|
||||
|
||||
rsp = await ShoutOut().run(context=context, name=self.name, opponent_name=self.opponent_name)
|
||||
|
||||
msg = Message(
|
||||
content=rsp,
|
||||
role=self.profile,
|
||||
cause_by=ShoutOut,
|
||||
sent_from=self.name,
|
||||
send_to=self.opponent_name,
|
||||
)
|
||||
|
||||
return msg
|
||||
|
||||
class Biden(Role):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "Biden",
|
||||
profile: str = "Democrat",
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(name, profile, **kwargs)
|
||||
self._init_actions([ShoutOut])
|
||||
self._watch([BossRequirement, ShoutOut])
|
||||
self.name = "Biden"
|
||||
self.opponent_name = "Trump"
|
||||
|
||||
async def _observe(self) -> int:
|
||||
await super()._observe()
|
||||
# accept the very first human instruction (the debate topic) or messages sent (from opponent) to self,
|
||||
# disregard own messages from the last round
|
||||
self._rc.news = [msg for msg in self._rc.news if msg.cause_by == BossRequirement or msg.send_to == self.name]
|
||||
return len(self._rc.news)
|
||||
|
||||
async def _act(self) -> Message:
|
||||
logger.info(f"{self._setting}: ready to {self._rc.todo}")
|
||||
|
||||
msg_history = self._rc.memory.get_by_actions([BossRequirement, ShoutOut])
|
||||
context = []
|
||||
for m in msg_history:
|
||||
context.append(str(m))
|
||||
context = "\n".join(context)
|
||||
|
||||
rsp = await ShoutOut().run(context=context, name=self.name, opponent_name=self.opponent_name)
|
||||
|
||||
msg = Message(
|
||||
content=rsp,
|
||||
role=self.profile,
|
||||
cause_by=ShoutOut,
|
||||
sent_from=self.name,
|
||||
send_to=self.opponent_name,
|
||||
)
|
||||
|
||||
return msg
|
||||
|
||||
async def startup(idea: str, investment: float = 3.0, n_round: int = 5,
|
||||
code_review: bool = False, run_tests: bool = False):
|
||||
"""We reuse the startup paradigm for roles to interact with each other.
|
||||
Now we run a startup of presidents and watch they quarrel. :) """
|
||||
company = SoftwareCompany()
|
||||
company.hire([Biden(), Trump()])
|
||||
company.invest(investment)
|
||||
company.start_project(idea)
|
||||
await company.run(n_round=n_round)
|
||||
|
||||
|
||||
def main(idea: str, investment: float = 3.0, n_round: int = 10):
|
||||
"""
|
||||
:param idea: Debate topic, such as "Topic: The U.S. should commit more in climate change fighting"
|
||||
or "Trump: Climate change is a hoax"
|
||||
:param investment: contribute a certain dollar amount to watch the debate
|
||||
:param n_round: maximum rounds of the debate
|
||||
:return:
|
||||
"""
|
||||
if platform.system() == "Windows":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
asyncio.run(startup(idea, investment, n_round))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
fire.Fire(main)
|
||||
|
|
@ -7,21 +7,25 @@
|
|||
"""
|
||||
import asyncio
|
||||
|
||||
from metagpt.llm import LLM, Claude
|
||||
from metagpt.logs import logger
|
||||
from metagpt.llm import LLM
|
||||
|
||||
|
||||
async def main():
|
||||
llm = LLM()
|
||||
|
||||
claude = Claude()
|
||||
logger.info(await claude.aask('你好,请进行自我介绍'))
|
||||
logger.info(await llm.aask('hello world'))
|
||||
logger.info(await llm.aask_batch(['hi', 'write python hello world.']))
|
||||
|
||||
hello_msg = [{'role': 'user', 'content': 'hello'}]
|
||||
hello_msg = [{'role': 'user', 'content': 'count from 1 to 10. split by newline.'}]
|
||||
logger.info(await llm.acompletion(hello_msg))
|
||||
logger.info(await llm.acompletion_batch([hello_msg]))
|
||||
logger.info(await llm.acompletion_batch_text([hello_msg]))
|
||||
|
||||
logger.info(await llm.acompletion_text(hello_msg))
|
||||
await llm.acompletion_text(hello_msg, stream=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
|
|
|||
16
examples/research.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import asyncio
|
||||
|
||||
from metagpt.roles.researcher import RESEARCH_PATH, Researcher
|
||||
|
||||
|
||||
async def main():
|
||||
topic = "dataiku vs. datarobot"
|
||||
role = Researcher(language="en-us")
|
||||
await role.run(topic)
|
||||
print(f"save report to {RESEARCH_PATH / f'{topic}.md'}.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
"""
|
||||
|
||||
import asyncio
|
||||
from metagpt.config import Config
|
||||
|
||||
from metagpt.roles import Searcher
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
@File : search_kb.py
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from metagpt.const import DATA_PATH
|
||||
from metagpt.document_store import FaissStore
|
||||
from metagpt.roles import Sales
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles import Sales
|
||||
|
||||
|
||||
async def search():
|
||||
|
|
|
|||
16
examples/search_with_specific_engine.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import asyncio
|
||||
|
||||
from metagpt.roles import Searcher
|
||||
from metagpt.tools import SearchEngineType
|
||||
|
||||
|
||||
async def main():
|
||||
# Serper API
|
||||
#await Searcher(engine = SearchEngineType.SERPER_GOOGLE).run(["What are some good sun protection products?","What are some of the best beaches?"])
|
||||
# SerpAPI
|
||||
#await Searcher(engine=SearchEngineType.SERPAPI_GOOGLE).run("What are the best ski brands for skiers?")
|
||||
# Google API
|
||||
await Searcher(engine=SearchEngineType.DIRECT_GOOGLE).run("What are the most interesting human facts?")
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
82
examples/sk_agent.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/9/13 12:36
|
||||
@Author : femto Zheng
|
||||
@File : sk_agent.py
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from semantic_kernel.core_skills import FileIOSkill, MathSkill, TextSkill, TimeSkill
|
||||
from semantic_kernel.planning import SequentialPlanner
|
||||
|
||||
# from semantic_kernel.planning import SequentialPlanner
|
||||
from semantic_kernel.planning.action_planner.action_planner import ActionPlanner
|
||||
|
||||
from metagpt.actions import BossRequirement
|
||||
from metagpt.const import SKILL_DIRECTORY
|
||||
from metagpt.roles.sk_agent import SkAgent
|
||||
from metagpt.schema import Message
|
||||
from metagpt.tools.search_engine import SkSearchEngine
|
||||
|
||||
|
||||
async def main():
|
||||
# await basic_planner_example()
|
||||
# await action_planner_example()
|
||||
|
||||
# await sequential_planner_example()
|
||||
await basic_planner_web_search_example()
|
||||
|
||||
|
||||
async def basic_planner_example():
|
||||
task = """
|
||||
Tomorrow is Valentine's day. I need to come up with a few date ideas. She speaks French so write it in French.
|
||||
Convert the text to uppercase"""
|
||||
role = SkAgent()
|
||||
|
||||
# let's give the agent some skills
|
||||
role.import_semantic_skill_from_directory(SKILL_DIRECTORY, "SummarizeSkill")
|
||||
role.import_semantic_skill_from_directory(SKILL_DIRECTORY, "WriterSkill")
|
||||
role.import_skill(TextSkill(), "TextSkill")
|
||||
# using BasicPlanner
|
||||
await role.run(Message(content=task, cause_by=BossRequirement))
|
||||
|
||||
|
||||
async def sequential_planner_example():
|
||||
task = """
|
||||
Tomorrow is Valentine's day. I need to come up with a few date ideas. She speaks French so write it in French.
|
||||
Convert the text to uppercase"""
|
||||
role = SkAgent(planner_cls=SequentialPlanner)
|
||||
|
||||
# let's give the agent some skills
|
||||
role.import_semantic_skill_from_directory(SKILL_DIRECTORY, "SummarizeSkill")
|
||||
role.import_semantic_skill_from_directory(SKILL_DIRECTORY, "WriterSkill")
|
||||
role.import_skill(TextSkill(), "TextSkill")
|
||||
# using BasicPlanner
|
||||
await role.run(Message(content=task, cause_by=BossRequirement))
|
||||
|
||||
|
||||
async def basic_planner_web_search_example():
|
||||
task = """
|
||||
Question: Who made the 1989 comic book, the film version of which Jon Raymond Polito appeared in?"""
|
||||
role = SkAgent()
|
||||
|
||||
role.import_skill(SkSearchEngine(), "WebSearchSkill")
|
||||
# role.import_semantic_skill_from_directory(skills_directory, "QASkill")
|
||||
|
||||
await role.run(Message(content=task, cause_by=BossRequirement))
|
||||
|
||||
|
||||
async def action_planner_example():
|
||||
role = SkAgent(planner_cls=ActionPlanner)
|
||||
# let's give the agent 4 skills
|
||||
role.import_skill(MathSkill(), "math")
|
||||
role.import_skill(FileIOSkill(), "fileIO")
|
||||
role.import_skill(TimeSkill(), "time")
|
||||
role.import_skill(TextSkill(), "text")
|
||||
task = "What is the sum of 110 and 990?"
|
||||
await role.run(Message(content=task, cause_by=BossRequirement)) # it will choose mathskill.Add
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
18
examples/use_off_the_shelf_agent.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
'''
|
||||
Filename: MetaGPT/examples/use_off_the_shelf_agent.py
|
||||
Created Date: Tuesday, September 19th 2023, 6:52:25 pm
|
||||
Author: garylin2099
|
||||
'''
|
||||
import asyncio
|
||||
|
||||
from metagpt.roles.product_manager import ProductManager
|
||||
from metagpt.logs import logger
|
||||
|
||||
async def main():
|
||||
msg = "Write a PRD for a snake game"
|
||||
role = ProductManager()
|
||||
result = await role.run(msg)
|
||||
logger.info(result.content[:100])
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
21
examples/write_tutorial.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
# _*_ coding: utf-8 _*_
|
||||
"""
|
||||
@Time : 2023/9/4 21:40:57
|
||||
@Author : Stitch-z
|
||||
@File : tutorial_assistant.py
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from metagpt.roles.tutorial_assistant import TutorialAssistant
|
||||
|
||||
|
||||
async def main():
|
||||
topic = "Write a tutorial about MySQL"
|
||||
role = TutorialAssistant(language="Chinese")
|
||||
await role.run(topic)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2023/4/24 22:26
|
||||
# @Author : alexanderwu
|
||||
# @File : __init__.py
|
||||
|
||||
from metagpt import _compat as _ # noqa: F401
|
||||
|
|
|
|||
23
metagpt/_compat.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import platform
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
if sys.implementation.name == "cpython" and platform.system() == "Windows":
|
||||
import asyncio
|
||||
|
||||
if sys.version_info[:2] == (3, 9):
|
||||
from asyncio.proactor_events import _ProactorBasePipeTransport
|
||||
|
||||
# https://github.com/python/cpython/pull/92842
|
||||
def pacth_del(self, _warn=warnings.warn):
|
||||
if self._sock is not None:
|
||||
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
|
||||
self._sock.close()
|
||||
|
||||
_ProactorBasePipeTransport.__del__ = pacth_del
|
||||
|
||||
if sys.version_info >= (3, 9, 0):
|
||||
from semantic_kernel.orchestration import sk_function as _ # noqa: F401
|
||||
|
||||
# caused by https://github.com/microsoft/semantic-kernel/pull/1416
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
||||
|
|
@ -8,24 +8,26 @@
|
|||
from enum import Enum
|
||||
|
||||
from metagpt.actions.action import Action
|
||||
|
||||
from metagpt.actions.write_prd import WritePRD
|
||||
from metagpt.actions.write_prd_review import WritePRDReview
|
||||
from metagpt.actions.action_output import ActionOutput
|
||||
from metagpt.actions.add_requirement import BossRequirement
|
||||
from metagpt.actions.debug_error import DebugError
|
||||
from metagpt.actions.design_api import WriteDesign
|
||||
from metagpt.actions.design_api_review import DesignReview
|
||||
from metagpt.actions.design_filenames import DesignFilenames
|
||||
from metagpt.actions.project_management import AssignTasks, WriteTasks
|
||||
from metagpt.actions.research import CollectLinks, WebBrowseAndSummarize, ConductResearch
|
||||
from metagpt.actions.run_code import RunCode
|
||||
from metagpt.actions.search_and_summarize import SearchAndSummarize
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from metagpt.actions.write_code_review import WriteCodeReview
|
||||
from metagpt.actions.write_prd import WritePRD
|
||||
from metagpt.actions.write_prd_review import WritePRDReview
|
||||
from metagpt.actions.write_test import WriteTest
|
||||
from metagpt.actions.run_code import RunCode
|
||||
from metagpt.actions.debug_error import DebugError
|
||||
from metagpt.actions.project_management import WriteTasks, AssignTasks
|
||||
from metagpt.actions.add_requirement import BossRequirement
|
||||
from metagpt.actions.search_and_summarize import SearchAndSummarize
|
||||
|
||||
|
||||
class ActionType(Enum):
|
||||
"""All types of Actions, used for indexing."""
|
||||
|
||||
ADD_REQUIREMENT = BossRequirement
|
||||
WRITE_PRD = WritePRD
|
||||
WRITE_PRD_REVIEW = WritePRDReview
|
||||
|
|
@ -40,3 +42,13 @@ class ActionType(Enum):
|
|||
WRITE_TASKS = WriteTasks
|
||||
ASSIGN_TASKS = AssignTasks
|
||||
SEARCH_AND_SUMMARIZE = SearchAndSummarize
|
||||
COLLECT_LINKS = CollectLinks
|
||||
WEB_BROWSE_AND_SUMMARIZE = WebBrowseAndSummarize
|
||||
CONDUCT_RESEARCH = ConductResearch
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ActionType",
|
||||
"Action",
|
||||
"ActionOutput",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,14 +5,21 @@
|
|||
@Author : alexanderwu
|
||||
@File : action.py
|
||||
"""
|
||||
from typing import Optional
|
||||
import re
|
||||
from abc import ABC
|
||||
from typing import Optional
|
||||
|
||||
from tenacity import retry, stop_after_attempt, wait_fixed
|
||||
|
||||
from metagpt.actions.action_output import ActionOutput
|
||||
from metagpt.llm import LLM
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.common import OutputParser
|
||||
from metagpt.utils.custom_decoder import CustomDecoder
|
||||
|
||||
|
||||
class Action(ABC):
|
||||
def __init__(self, name: str = '', context=None, llm: LLM = None):
|
||||
def __init__(self, name: str = "", context=None, llm: LLM = None):
|
||||
self.name: str = name
|
||||
if llm is None:
|
||||
llm = LLM()
|
||||
|
|
@ -21,6 +28,8 @@ class Action(ABC):
|
|||
self.prefix = ""
|
||||
self.profile = ""
|
||||
self.desc = ""
|
||||
self.content = ""
|
||||
self.instruct_content = None
|
||||
|
||||
def set_prefix(self, prefix, profile):
|
||||
"""Set prefix for later usage"""
|
||||
|
|
@ -40,6 +49,41 @@ class Action(ABC):
|
|||
system_msgs.append(self.prefix)
|
||||
return await self.llm.aask(prompt, system_msgs)
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
||||
async def _aask_v1(
|
||||
self,
|
||||
prompt: str,
|
||||
output_class_name: str,
|
||||
output_data_mapping: dict,
|
||||
system_msgs: Optional[list[str]] = None,
|
||||
format="markdown", # compatible to original format
|
||||
) -> ActionOutput:
|
||||
"""Append default prefix"""
|
||||
if not system_msgs:
|
||||
system_msgs = []
|
||||
system_msgs.append(self.prefix)
|
||||
content = await self.llm.aask(prompt, system_msgs)
|
||||
logger.debug(content)
|
||||
output_class = ActionOutput.create_model_class(output_class_name, output_data_mapping)
|
||||
|
||||
if format == "json":
|
||||
pattern = r"\[CONTENT\](\s*\{.*?\}\s*)\[/CONTENT\]"
|
||||
matches = re.findall(pattern, content, re.DOTALL)
|
||||
|
||||
for match in matches:
|
||||
if match:
|
||||
content = match
|
||||
break
|
||||
|
||||
parsed_data = CustomDecoder(strict=False).decode(content)
|
||||
|
||||
else: # using markdown parser
|
||||
parsed_data = OutputParser.parse_data_with_mapping(content, output_data_mapping)
|
||||
|
||||
logger.debug(parsed_data)
|
||||
instruct_content = output_class(**parsed_data)
|
||||
return ActionOutput(content, instruct_content)
|
||||
|
||||
async def run(self, *args, **kwargs):
|
||||
"""Run action"""
|
||||
raise NotImplementedError("The run method should be implemented in a subclass.")
|
||||
|
|
|
|||
43
metagpt/actions/action_output.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
"""
|
||||
@Time : 2023/7/11 10:03
|
||||
@Author : chengmaoyu
|
||||
@File : action_output
|
||||
"""
|
||||
|
||||
from typing import Dict, Type
|
||||
|
||||
from pydantic import BaseModel, create_model, root_validator, validator
|
||||
|
||||
|
||||
class ActionOutput:
|
||||
content: str
|
||||
instruct_content: BaseModel
|
||||
|
||||
def __init__(self, content: str, instruct_content: BaseModel):
|
||||
self.content = content
|
||||
self.instruct_content = instruct_content
|
||||
|
||||
@classmethod
|
||||
def create_model_class(cls, class_name: str, mapping: Dict[str, Type]):
|
||||
new_class = create_model(class_name, **mapping)
|
||||
|
||||
@validator('*', allow_reuse=True)
|
||||
def check_name(v, field):
|
||||
if field.name not in mapping.keys():
|
||||
raise ValueError(f'Unrecognized block: {field.name}')
|
||||
return v
|
||||
|
||||
@root_validator(pre=True, allow_reuse=True)
|
||||
def check_missing_fields(values):
|
||||
required_fields = set(mapping.keys())
|
||||
missing_fields = required_fields - set(values.keys())
|
||||
if missing_fields:
|
||||
raise ValueError(f'Missing fields: {missing_fields}')
|
||||
return values
|
||||
|
||||
new_class.__validator_check_name = classmethod(check_name)
|
||||
new_class.__root_validator_check_missing_fields = classmethod(check_missing_fields)
|
||||
return new_class
|
||||
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
from metagpt.actions import Action
|
||||
|
||||
|
||||
PROMPT = """You are an AI developer, trying to write a program that generates code for users based on their intentions.
|
||||
|
||||
For the user's prompt:
|
||||
|
|
@ -29,10 +28,10 @@ Focus only on the names of shared dependencies, do not add any other explanation
|
|||
class AnalyzeDepLibs(Action):
|
||||
def __init__(self, name, context=None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
self.desc = "根据上下文,分析程序运行依赖库"
|
||||
self.desc = "Analyze the runtime dependencies of the program based on the context"
|
||||
|
||||
async def run(self, requirement, filepaths_string):
|
||||
# prompt = f"以下是产品需求文档(PRD):\n\n{prd}\n\n{PROMPT}"
|
||||
# prompt = f"Below is the product requirement document (PRD):\n\n{prd}\n\n{PROMPT}"
|
||||
prompt = PROMPT.format(prompt=requirement, filepaths_string=filepaths_string)
|
||||
design_filenames = await self._aask(prompt)
|
||||
return design_filenames
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@
|
|||
@Author : Leo Xiao
|
||||
@File : azure_tts.py
|
||||
"""
|
||||
from azure.cognitiveservices.speech import AudioConfig, SpeechConfig, SpeechSynthesizer
|
||||
|
||||
from metagpt.actions.action import Action
|
||||
from azure.cognitiveservices.speech import SpeechConfig, SpeechSynthesizer, AudioConfig
|
||||
from metagpt.config import Config
|
||||
|
||||
|
||||
|
|
@ -15,10 +16,10 @@ class AzureTTS(Action):
|
|||
super().__init__(name, context, llm)
|
||||
self.config = Config()
|
||||
|
||||
# 参数参考:https://learn.microsoft.com/zh-cn/azure/cognitive-services/speech-service/language-support?tabs=tts#voice-styles-and-roles
|
||||
# Parameters reference: https://learn.microsoft.com/zh-cn/azure/cognitive-services/speech-service/language-support?tabs=tts#voice-styles-and-roles
|
||||
def synthesize_speech(self, lang, voice, role, text, output_file):
|
||||
subscription_key = self.config.get('SUBSCRIPTION_KEY')
|
||||
region = self.config.get('REGION')
|
||||
subscription_key = self.config.get('AZURE_TTS_SUBSCRIPTION_KEY')
|
||||
region = self.config.get('AZURE_TTS_REGION')
|
||||
speech_config = SpeechConfig(
|
||||
subscription=subscription_key, region=region)
|
||||
|
||||
|
|
@ -48,5 +49,5 @@ if __name__ == "__main__":
|
|||
"zh-CN",
|
||||
"zh-CN-YunxiNeural",
|
||||
"Boy",
|
||||
"你好,我是卡卡",
|
||||
"Hello, I am Kaka",
|
||||
"output.wav")
|
||||
|
|
|
|||
65
metagpt/actions/clone_function.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from pathlib import Path
|
||||
import traceback
|
||||
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from metagpt.logs import logger
|
||||
from metagpt.schema import Message
|
||||
from metagpt.utils.highlight import highlight
|
||||
|
||||
CLONE_PROMPT = """
|
||||
*context*
|
||||
Please convert the function code ```{source_code}``` into the the function format: ```{template_func}```.
|
||||
*Please Write code based on the following list and context*
|
||||
1. Write code start with ```, and end with ```.
|
||||
2. Please implement it in one function if possible, except for import statements. for exmaple:
|
||||
```python
|
||||
import pandas as pd
|
||||
def run(*args) -> pd.DataFrame:
|
||||
...
|
||||
```
|
||||
3. Do not use public member functions that do not exist in your design.
|
||||
4. The output function name, input parameters and return value must be the same as ```{template_func}```.
|
||||
5. Make sure the results before and after the code conversion are required to be exactly the same.
|
||||
6. Don't repeat my context in your replies.
|
||||
7. Return full results, for example, if the return value has df.head(), please return df.
|
||||
8. If you must use a third-party package, use the most popular ones, for example: pandas, numpy, ta, ...
|
||||
"""
|
||||
|
||||
|
||||
class CloneFunction(WriteCode):
|
||||
def __init__(self, name="CloneFunction", context: list[Message] = None, llm=None):
|
||||
super().__init__(name, context, llm)
|
||||
|
||||
def _save(self, code_path, code):
|
||||
if isinstance(code_path, str):
|
||||
code_path = Path(code_path)
|
||||
code_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
code_path.write_text(code)
|
||||
logger.info(f"Saving Code to {code_path}")
|
||||
|
||||
async def run(self, template_func: str, source_code: str) -> str:
|
||||
"""将source_code转换成template_func一样的入参和返回类型"""
|
||||
prompt = CLONE_PROMPT.format(source_code=source_code, template_func=template_func)
|
||||
logger.info(f"query for CloneFunction: \n {prompt}")
|
||||
code = await self.write_code(prompt)
|
||||
logger.info(f'CloneFunction code is \n {highlight(code)}')
|
||||
return code
|
||||
|
||||
|
||||
def run_function_code(func_code: str, func_name: str, *args, **kwargs):
|
||||
"""Run function code from string code."""
|
||||
try:
|
||||
locals_ = {}
|
||||
exec(func_code, locals_)
|
||||
func = locals_[func_name]
|
||||
return func(*args, **kwargs), ""
|
||||
except Exception:
|
||||
return "", traceback.format_exc()
|
||||
|
||||
|
||||
def run_function_script(code_script_path: str, func_name: str, *args, **kwargs):
|
||||
"""Run function code from script."""
|
||||
if isinstance(code_script_path, str):
|
||||
code_path = Path(code_script_path)
|
||||
code = code_path.read_text(encoding='utf-8')
|
||||
return run_function_code(code, func_name, *args, **kwargs)
|
||||