diff --git a/README.md b/README.md index 4aceb48f7..9a496cff4 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ # Step 3: Clone the repository to your local machine, and install it. - don't forget to the configuration for mmdc in config.yml ```yml - PUPPETEER_CONFIG: "./puppeteer-config.json" + PUPPETEER_CONFIG: "./config/puppeteer-config.json" MMDC: "./node_modules/.bin/mmdc" ``` diff --git a/config/config.yaml b/config/config.yaml index 4abec8f25..ceab18854 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -2,10 +2,12 @@ # The configuration of key.yaml has a higher priority and will not enter git #### if OpenAI - -#OPENAI_API_KEY: "YOUR_API_KEY" -#OPENAI_API_BASE: "YOUR_API_BASE" +## 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 @@ -57,7 +59,10 @@ SD_T2I_API: "/sdapi/v1/txt2img" #LONG_TERM_MEMORY: false #### for Mermaid CLI -# adds support for installing mmdc (Mermaid CLI) locally on the user's machine. -# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install @mermaid-js/mermaid-cli -#PUPPETEER_CONFIG: "./puppeteer-config.json" -#MMDC: "./node_modules/.bin/mmdc" \ No newline at end of file +## 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 update_costs & calc_usage +UPDATE_COSTS: false +CALC_USAGE: false \ No newline at end of file diff --git a/puppeteer-config.json b/config/puppeteer-config.json similarity index 100% rename from puppeteer-config.json rename to config/puppeteer-config.json diff --git a/docs/README_CN.md b/docs/README_CN.md index 82416ab7f..5f80a7f33 100644 --- a/docs/README_CN.md +++ b/docs/README_CN.md @@ -1,4 +1,4 @@ -# MetaGPT:多智能体元编程框架 +# MetaGPT: 多智能体框架

MetaGPT logo: 使 GPT 以软件公司的形式工作,协作处理更复杂的任务 @@ -37,6 +37,8 @@ ## 示例(均由 GPT-4 生成) ## 安装 +### 传统安装 + ```bash # 第 1 步:确保您的系统上安装了 NPM。并使用npm安装mermaid-js npm --version @@ -51,13 +53,56 @@ # 第 3 步:克隆仓库到您的本地机器,并进行安装。 python setup.py install ``` +### Docker安装 + +```bash +# 步骤1: 下载metagpt官方镜像并准备好config.yaml +docker pull metagpt/metagpt:v0.3 +mkdir -p /opt/metagpt/{config,workspace} +docker run --rm metagpt/metagpt:v0.3 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:v0.3 \ + 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:v0.3 + +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:v0.3 . +``` + ## 配置 - 在 `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 ``` @@ -71,18 +116,41 @@ ## 示例:启动一个创业公司 ```shell python startup.py "写一个命令行贪吃蛇" # 开启code review模式会会花费更多的money, 但是会提升代码质量和成功率 -python startup.py "写一个命令行贪吃蛇" --code_review True +python startup.py "写一个命令行贪吃蛇" --code_review True ``` 运行脚本后,您可以在 `workspace/` 目录中找到您的新项目。 -### 平台或工具的倾向性 -可以在阐述需求时告知想要使用的平台或工具。 -例如: +### 使用 -```shell -python startup.py "写一个基于pygame的命令行贪吃蛇" ``` +名称 + startup.py - 我们是一家AI软件创业公司。通过投资我们,您将赋能一个充满无限可能的未来。 + +概要 + startup.py IDEA + +描述 + 我们是一家AI软件创业公司。通过投资我们,您将赋能一个充满无限可能的未来。 + +位置参数 + IDEA + 类型: str + 您的创新想法,例如"写一个命令行贪吃蛇。" + +标志 + --investment=INVESTMENT + 类型: float + 默认值: 3.0 + 作为投资者,您有机会向这家AI公司投入一定的美元金额。 + --n_round=N_ROUND + 类型: int + 默认值: 5 + +备注 + 您也可以用`标志`的语法,来处理`位置参数` +``` + ### 代码实现 ```python @@ -115,6 +183,8 @@ ## 演示 ## 加入微信讨论群 -- 群已满,加人进群 +MetaGPT WeChat Discuss Group -MetaGPT WeChat Discuss Group +如果群已满,请添加负责人微信,会邀请进群 + +MetaGPT WeChat Discuss Group \ No newline at end of file diff --git a/docs/README_JA.md b/docs/README_JA.md index fa0ed60b5..a5e5f6552 100644 --- a/docs/README_JA.md +++ b/docs/README_JA.md @@ -53,6 +53,24 @@ # ステップ 3: リポジトリをローカルマシンにクローンし、 python setup.py install ``` +**注:** + +- すでに 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" + ``` + ### Docker によるインストール ```bash diff --git a/docs/resources/MetaGPT-WeChat-Group4.jpeg b/docs/resources/MetaGPT-WeChat-Group4.jpeg new file mode 100644 index 000000000..f665f8b1d Binary files /dev/null and b/docs/resources/MetaGPT-WeChat-Group4.jpeg differ diff --git a/docs/resources/MetaGPT-WeChat-Personal.jpeg b/docs/resources/MetaGPT-WeChat-Personal.jpeg index aaf6c775f..f6b48577d 100644 Binary files a/docs/resources/MetaGPT-WeChat-Personal.jpeg and b/docs/resources/MetaGPT-WeChat-Personal.jpeg differ diff --git a/metagpt/config.py b/metagpt/config.py index 0f8ed37d6..d53571468 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -79,6 +79,10 @@ class Config(metaclass=Singleton): self.total_cost = 0.0 self.puppeteer_config = self._get("PUPPETEER_CONFIG","") self.mmdc = self._get("MMDC","mmdc") + self.update_costs = self._get("UPDATE_COSTS",True) + self.calc_usage = self._get("CALC_USAGE",True) + + def _init_with_config_files_and_env(self, configs: dict, yaml_file): """从config/key.yaml / config/config.yaml / env三处按优先级递减加载""" diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index f6499c643..fe9532d43 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -221,10 +221,11 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter): def _calc_usage(self, messages: list[dict], rsp: str) -> dict: usage = {} - prompt_tokens = count_message_tokens(messages, self.model) - completion_tokens = count_string_tokens(rsp, self.model) - usage['prompt_tokens'] = prompt_tokens - usage['completion_tokens'] = completion_tokens + if CONFIG.calc_usage: + prompt_tokens = count_message_tokens(messages, self.model) + completion_tokens = count_string_tokens(rsp, self.model) + usage['prompt_tokens'] = prompt_tokens + usage['completion_tokens'] = completion_tokens return usage async def acompletion_batch(self, batch: list[list[dict]]) -> list[dict]: @@ -254,9 +255,10 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter): return results def _update_costs(self, usage: dict): - prompt_tokens = int(usage['prompt_tokens']) - completion_tokens = int(usage['completion_tokens']) - self._cost_manager.update_cost(prompt_tokens, completion_tokens, self.model) + if CONFIG.update_costs: + prompt_tokens = int(usage['prompt_tokens']) + completion_tokens = int(usage['completion_tokens']) + self._cost_manager.update_cost(prompt_tokens, completion_tokens, self.model) def get_costs(self) -> Costs: return self._cost_manager.get_costs() diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index d1bbb85f7..3850faae3 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -16,8 +16,6 @@ from metagpt.utils.common import check_cmd_exists IS_DOCKER = os.environ.get('AM_I_IN_A_DOCKER_CONTAINER', 'false').lower() - - def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height=2048) -> int: """suffix: png/svg/pdf @@ -41,15 +39,15 @@ def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height # Call the `mmdc` command to convert the Mermaid code to a PNG logger.info(f"Generating {output_file}..") if IS_DOCKER == 'true': - subprocess.run(['mmdc', '-p', '/app/metagpt/puppeteer-config.json', '-i', + subprocess.run(['mmdc', '-p', '/app/metagpt/config/puppeteer-config.json', '-i', str(tmp), '-o', output_file, '-w', str(width), '-H', str(height)]) else: if CONFIG.puppeteer_config: - subprocess.run([CONFIG.mmdc,'-p',CONFIG.puppeteer_config, '-i', str(tmp), '-o', - output_file, '-w', str(width), '-H', str(height)]) + subprocess.run([CONFIG.mmdc, '-p', CONFIG.puppeteer_config, '-i', str(tmp), '-o', + output_file, '-w', str(width), '-H', str(height)]) else: - subprocess.run( [CONFIG.mmdc, '-i', str(tmp), '-o', - output_file, '-w', str(width), '-H', str(height)]) + subprocess.run([CONFIG.mmdc, '-i', str(tmp), '-o', + output_file, '-w', str(width), '-H', str(height)]) return 0