Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config for other LLM #37

Merged
merged 11 commits into from
Dec 29, 2023
138 changes: 127 additions & 11 deletions src/en/guide/get_started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

Using MetaGPT involves connecting with model providers. We will walk through the setup in this page.

## Setup for LLM API
After your [Installation](./installation.md) is complete, follow the instructions in this document to complete the
configuration before use.
At the moment, the example of this project only needs to configure OpenAi API.

## OpenAI API

We will take OpenAI API as an example. You can finish the setup in either way:

Expand All @@ -22,34 +26,146 @@ Or in python:

```python
import os

os.environ["OPENAI_API_KEY"] = "sk-..." # YOUR_API_KEY
os.environ["OPENAI_API_MODEL"] = "intended model" # gpt-4, gpt-3.5-turbo, etc.
os.environ["OPENAI_API_MODEL"] = "intended model" # gpt-4, gpt-3.5-turbo, etc.
```

### 2. Use a config or key file

1. In your current working directory, create a folder `config` and add a new file named `config.yaml` or `key.yaml` under it.
2. Copy the content from the example [config.yaml](https://github.com/geekan/MetaGPT/blob/main/config/config.yaml) file into your new files
1. In your current working directory, create a folder `config` and add a new file named `config.yaml` or `key.yaml`
under it.
2. Copy the content from the example [config.yaml](https://github.com/geekan/MetaGPT/blob/main/config/config.yaml) file
into your new files
3. Fill in your own values to the file:

```yaml
OPENAI_API_KEY: 'sk-...' # YOUR_API_KEY
OPENAI_API_MODEL: 'intended model' # gpt-4, gpt-3.5-turbo, etc.
```

Remember: If you follow the `git clone` approach in [Installation](./installation), `config/config.yaml` will already be there. Just edit it or make a copy named `config/key.yaml` for editting. This way you don't accidentally commit and share your API key using git.
Remember: If you follow the `git clone` approach in [Installation](./installation), `config/config.yaml` will already be
there. Just edit it or make a copy named `config/key.yaml` for editting. This way you don't accidentally commit and
share your API key using git.

> Note:
> MetaGPT will read your setup in this priority order: `config/key.yaml > config/config.yaml > environment variable`

Here you are good to go! See [Quickstart](./quickstart) or our [Tutorials](/guide/tutorials/agent_101) for your first run!
Here you are good to go! See [Quickstart](./quickstart) or our [Tutorials](/guide/tutorials/agent_101) for your first
run!

MetaGPT also supports various LLM models, configure the keys of model APIs according to your needs.

## Zhipu API

```yaml
#### if zhipuai from `https://open.bigmodel.cn`. You can set here or export API_KEY="YOUR_API_KEY"
ZHIPUAI_API_KEY: "YOUR_API_KEY"
```

## iFlytek's large model Spark API :

``` yaml
#### if Spark
### Nomally YOU only need to modify SPARK_APPID SPARK_API_SECRET SPARK_API_KEY
SPARK_APPID : "YOUR_APPID"
SPARK_API_SECRET : "YOUR_API_SECRET"
SPARK_API_KEY : "YOUR_API_KEY"
DOMAIN : "generalv2"
SPARK_URL : "ws://spark-api.xf-yun.com/v2.1/chat"
```

## Microsoft Azure Based Openai

``` yaml
#### 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"
```

## Web Searching API
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

belows are not LLM API configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尽管不是,但本章讲的是配置问题。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above has writen with MetaGPT also supports various LLM models. If it's focus on configuration, you can split it with LLM-configuration and non-LLM-configuration. Put them together will make people think it's all about LLM-configuration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我后面提个PR来改吧


``` yaml
#### 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"

## Visit https://serper.dev/ to get key.
SERPER_API_KEY: "YOUR_API_KEY"
```

## Website Access For Agent

``` yaml
#### 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
```

## Auzre TTS

```` yaml
#### for TTS

AZURE_TTS_SUBSCRIPTION_KEY: "YOUR_API_KEY"
AZURE_TTS_REGION: "eastus"
````

## Stable Diffusion Local Deployment

````yaml
#### 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"

````

## Other Abilities

````yaml
#### 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"


## Setup for different model providers
### for calc_usage
CALC_USAGE: false

### OpenAI
### for Research
MODEL_FOR_RESEARCHER_SUMMARY: gpt-3.5-turbo
MODEL_FOR_RESEARCHER_REPORT: gpt-3.5-turbo-16k

### Azure
### choose the engine for mermaid conversion,
# default is nodejs, you can change it to playwright,pyppeteer or ink
MERMAID_ENGINE: nodejs

### Anthropic
### browser path for pyppeteer engine, support Chrome, Chromium,MS Edge
PYPPETEER_EXECUTABLE_PATH: "/usr/bin/google-chrome-stable"

## Setup for other APIs
PROMPT_FORMAT: json #json or markdown
````
157 changes: 134 additions & 23 deletions src/zh/guide/get_started/setup.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,166 @@
# 配置
# 设置

MetaGPT的使用涉及到不同模型提供商的访问配置,我们将在本页中详细介绍该设置
使用MetaGPT需要配置模型API。我们将在本页面中介绍设置过程

## 配置LLM API
在[安装](./installation.md)完成后,请按照本文档中的说明完成配置,然后开始使用。
目前,该项目的示例只需要配置OpenAI API。

我们将使用OpenAI API作为例子。你可以通过下述方式完成配置:
## OpenAI API

1. 使用环境变量,这是推荐的最快捷的方式。
2. 使用config或key配置文件,这是推荐的进行完整功能体验和开发的方式。
我们以OpenAI API为例。您可以通过以下两种方式完成设置:

1. 使用环境变量。这可以用于临时快速启动或尝试演示。
2. 使用key.yaml配置。这是推荐的方式,适用于持续和全功能的使用和开发。

### 1. 使用环境变量

在命令行下执行
在命令行中运行

```shell
export OPENAI_API_KEY="sk-..." # YOUR_API_KEY
export OPENAI_API_MODEL="intended model" # gpt-4, gpt-3.5-turbo, etc.
export OPENAI_API_MODEL="intended model" # gpt-4, gpt-3.5-turbo, 等等
```

或者在python代码中添加
或在Python中

```python
import os

os.environ["OPENAI_API_KEY"] = "sk-..." # YOUR_API_KEY
os.environ["OPENAI_API_MODEL"] = "intended model" # gpt-4, gpt-3.5-turbo, etc.
os.environ["OPENAI_API_MODEL"] = "intended model" # gpt-4, gpt-3.5-turbo, 等等
```

### 2. 使用一个`config.yaml`或者`key.yaml`文件
### 2.使用一个`config.yaml`或者`key.yaml`文件

1. 在当前项目的工作目录下,新建一个文件夹`config`并在该文件夹下添加一个`config.yaml`或`key.yaml`文件
2. 拷贝样例配置 [config.yaml](https://github.com/geekan/MetaGPT/blob/main/config/config.yaml) 中的内容到你的新文件中
3. 在新文件内设置自己的OPENAI API KEY配置
1. 在当前工作目录中创建一个名为`config`的文件夹,并在其中添加一个名为`key.yaml`的新文件。
2. 将示例[config.yaml](https://github.com/geekan/MetaGPT/blob/main/config/config.yaml)文件的内容复制到您的新文件中
3. 将您自己的值填入文件中

```yaml
OPENAI_API_KEY: 'sk-...' # YOUR_API_KEY
OPENAI_API_MODEL: 'intended model' # gpt-4, gpt-3.5-turbo, etc.
OPENAI_API_MODEL: 'intended model' # gpt-4, gpt-3.5-turbo, 等等
```

记住:如果你按照 [安装](./installation) 使用`git clone`的方法进行安装,`config/config.yaml`已经存在于目录中。只需要直接进行配置,或拷贝一个新文件 `config/key.yaml` 并进行配置。 这样你就不会因为不小心提交了API KEYT而导致泄露。
请记住:如果您按照[安装](./installation)中的`git clone`方法,`config/config.yaml`
文件已经存在。只需编辑它或创建一个名为`config/key.yaml`的副本进行编辑。这样您就不会意外地使用git提交和共享您的API密钥。

> 注意:
> MetaGPT将会按照下述优先级来读取你的配置:`config/key.yaml > config/config.yaml > environment variable`
> MetaGPT将按照以下优先顺序读取您的设置:`config/key.yaml > config/config.yaml > 环境变量`

现在您可以开始使用了!请参阅[快速入门](./quickstart)或我们的[教程](/guide/tutorials/agent_101)以进行第一次运行!

MetaGPT还支持各种LLM模型,根据您的需求配置模型API的密钥。

## 智谱 API

```yaml
#### 关于智谱,搜索`https://open.bigmodel.cn`。您可以在此设置,或export API_KEY="YOUR_API_KEY"
ZHIPUAI_API_KEY: "YOUR_API_KEY"
```

## 科大讯飞的大模型 Spark API:

``` yaml
#### 如果是Spark
### 通常您只需要修改 SPARK_APPID、SPARK_API_SECRET和SPARK_API_KEY
SPARK_APPID : "YOUR_APPID"
SPARK_API_SECRET : "YOUR_API_SECRET"
SPARK_API_KEY : "YOUR_API_KEY"
DOMAIN : "generalv2"
SPARK_URL : "ws://spark-api.xf-yun.com/v2.1/chat"
```

## 基于Microsoft Azure的Openai

``` yaml
#### 如果是AZURE,请参考https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb
#### 您可以使用ENGINE或DEPLOYMENT模式
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"
```

## 网页搜索 API

``` yaml
#### 用于搜索

## 可选值:serpapi/google/serper/ddg
SEARCH_ENGINE: serpapi

## 访问 https://serpapi.com/ 获取密钥。
SERPAPI_API_KEY: "YOUR_API_KEY"

## 访问 https://console.cloud.google.com/apis/credentials 获取密钥。
GOOGLE_API_KEY: "YOUR_API_KEY"
## 访问 https://programmablesearchengine.google.com/controlpanel/create 获取ID。
GOOGLE_CSE_ID: "YOUR_CSE_ID"

## 访问 https://serper.dev/ 获取密钥。
SERPER_API_KEY: "YOUR_API_KEY"
```

## 代理访问网站

``` yaml
#### 用于访问网站

## 可选值:playwright/selenium
WEB_BROWSER_ENGINE: playwright

## 可选值:chromium/firefox/webkit,访问 https://playwright.dev/python/docs/api/class-browsertype
PLAYWRIGHT_BROWSER_TYPE: chromium

## 可选值:chrome/firefox/edge/ie,访问 https://www.selenium.dev/documentation/webdriver/browsers/
SELENIUM_BROWSER_TYPE: chrome
```

## Azure TTS

```` yaml
#### 用于TTS

AZURE_TTS_SUBSCRIPTION_KEY: "YOUR_API_KEY"
AZURE_TTS_REGION: "eastus"
````

## Stable Diffusion 本地部署

````yaml
#### 用于Stable Diffusion
## 使用SD服务,基于 https://github.com/AUTOMATIC1111/stable-diffusion-webui
SD_URL: "YOUR_SD_URL"
SD_T2I_API: "/sdapi/v1/txt2img"

````

## 其他功能

````yaml
#### 用于执行
LONG_TERM_MEMORY: false
#### 用于Mermaid CLI
## 如果您只为metagpt安装了mmdc(Mermaid CLI),请启用以下配置。
PUPPETEER_CONFIG: "./config/puppeteer-config.json"
MMDC: "./node_modules/.bin/mmdc"

现在你可以开始使用了!参考 [快速开始](./quickstart) 或 [教程](/guide/tutorials/agent_101) 进行第一个软件项目的生成。

## 不同模型提供商的配置
### 用于计算使用量
CALC_USAGE: false

### OpenAI
### 用于搜索
MODEL_FOR_RESEARCHER_SUMMARY: gpt-3.5-turbo
MODEL_FOR_RESEARCHER_REPORT: gpt-3.5-turbo-16k

### Azure
### 选择Mermaid转换的引擎,
# 默认为nodejs,您可以将其更改为playwright、pyppeteer或ink
MERMAID_ENGINE: nodejs

### Anthropic
### pyppeteer引擎的浏览器路径,支持Chrome、Chromium、MS Edge
PYPPETEER_EXECUTABLE_PATH: "/usr/bin/google-chrome-stable"

## 其他API的配置
PROMPT_FORMAT: json #json或markdown
````