Skip to content

设置

使用MetaGPT需要配置模型API。我们将在本页面中介绍设置过程。

安装完成后,请按照本文档中的说明完成配置,然后开始使用。 目前,该项目的示例只需要配置OpenAI API。

配置大模型API

OpenAI API

我们以OpenAI API为例说明配置过程,其他大模型的API配置过程是相同的。

您可以通过设置 config2.yaml 完成配置

使用config2.yaml

  1. 在当前工作目录中创建一个名为config的文件夹,并在其中添加一个名为config2.yaml的新文件。
  2. 将示例config2.yaml文件的内容复制到您的新文件中。
  3. 将您自己的值填入文件中:
yaml
llm:
  api_type: 'openai' # or azure / ollama / open_llm etc. Check LLMType for more options
  api_key: 'sk-...' # YOUR_API_KEY
  model: 'gpt-4-turbo-preview' # or gpt-3.5-turbo-1106 / gpt-4-1106-preview
  # base_url: 'https://api.openai.com/v1'  # or any forward url.
  # proxy: 'YOUR_LLM_PROXY_IF_NEEDED'  # Optional. If you want to use a proxy, set it here.
  # pricing_plan: 'YOUR_PRICING_PLAN' # Optional. If your pricing plan uses a different name than the `model`.
llm:
  api_type: 'openai' # or azure / ollama / open_llm etc. Check LLMType for more options
  api_key: 'sk-...' # YOUR_API_KEY
  model: 'gpt-4-turbo-preview' # or gpt-3.5-turbo-1106 / gpt-4-1106-preview
  # base_url: 'https://api.openai.com/v1'  # or any forward url.
  # proxy: 'YOUR_LLM_PROXY_IF_NEEDED'  # Optional. If you want to use a proxy, set it here.
  # pricing_plan: 'YOUR_PRICING_PLAN' # Optional. If your pricing plan uses a different name than the `model`.

请记住:如果您按照安装中的git clone方法,config/config2.yaml 文件已经存在。只需编辑它或创建一个名为~/.metagpt/config2.yaml的副本进行编辑。这样您就不会意外地使用git提交和共享您的API密钥。

注意: MetaGPT将按照以下优先顺序读取您的设置:~/.metagpt/config2.yaml > config/config2.yaml

现在您可以开始使用了!请参阅快速入门或我们的教程以进行第一次运行!

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

Anthropic / Claude API

支持模型名列表,在metagpt/utils/token_counter.pyclaude-*

yaml
llm:
  api_type: 'claude' # 或 anthropic
  base_url: 'https://api.anthropic.com'
  api_key: 'YOUR_API_KEY'
  model: 'claude-3-opus-20240229'
llm:
  api_type: 'claude' # 或 anthropic
  base_url: 'https://api.anthropic.com'
  api_key: 'YOUR_API_KEY'
  model: 'claude-3-opus-20240229'

智谱 API

访问 llm_config.py 获得更新详情。

yaml
llm:
  api_type: 'zhipuai'
  api_key: 'YOUR_API_KEY'
  model: 'MODEL_NAME'
llm:
  api_type: 'zhipuai'
  api_key: 'YOUR_API_KEY'
  model: 'MODEL_NAME'

科大讯飞的大模型 Spark API:

访问 llm_config.py 获得更新详情。

yaml
llm:
  api_type: 'spark'
  app_id: 'YOUR_APPID'
  api_key: 'YOUR_API_KEY'
  api_secret: 'YOUR_API_SECRET'
  domain: 'generalv2'
  base_url: 'wss://spark-api.xf-yun.com/v3.1/chat'
llm:
  api_type: 'spark'
  app_id: 'YOUR_APPID'
  api_key: 'YOUR_API_KEY'
  api_secret: 'YOUR_API_SECRET'
  domain: 'generalv2'
  base_url: 'wss://spark-api.xf-yun.com/v3.1/chat'

Azure OpenAI API

访问 llm_config.py 获得更新详情。

yaml
llm:
  api_type: 'azure'
  base_url: 'YOUR_AZURE_BASE_URL'
  api_key: 'YOUR_API_KEY'
  api_version: 'YOUR_API_VERSION'
  model: 'YOUR_MODEL_NAME'
llm:
  api_type: 'azure'
  base_url: 'YOUR_AZURE_BASE_URL'
  api_key: 'YOUR_API_KEY'
  api_version: 'YOUR_API_VERSION'
  model: 'YOUR_MODEL_NAME'

谷歌 Gemini

默认支持模型gemini-pro

yaml
llm:
  api_type: 'gemini'
  api_key: 'YOUR_API_KEY'
  model: 'gemini-pro'
llm:
  api_type: 'gemini'
  api_key: 'YOUR_API_KEY'
  model: 'gemini-pro'

百度 千帆 API

支持ERNIE-*模型和部分主流开源模型,详见metagpt/utils/token_counter.py

使用安全认证AK/SK鉴权

使用model进行调用

yaml
llm:
  api_type: 'qianfan'
  access_key: 'YOUR_ACCESS_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  model: 'YOUR_MODEL_NAME like ERNIE-Bot-turbo'
llm:
  api_type: 'qianfan'
  access_key: 'YOUR_ACCESS_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  model: 'YOUR_MODEL_NAME like ERNIE-Bot-turbo'

使用endpoint进行调用

yaml
llm:
  api_type: 'qianfan'
  access_key: 'YOUR_ACCESS_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  endpoint: 'YOUR_ENDPOINT_NAME like ernie_speed'
llm:
  api_type: 'qianfan'
  access_key: 'YOUR_ACCESS_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  endpoint: 'YOUR_ENDPOINT_NAME like ernie_speed'

使用应用AK/SK鉴权(不推荐)

使用model进行调用

yaml
llm:
  api_type: 'qianfan'
  api_key: 'YOUR_API_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  model: 'YOUR_MODEL_NAME like ERNIE-Bot-turbo'
llm:
  api_type: 'qianfan'
  api_key: 'YOUR_API_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  model: 'YOUR_MODEL_NAME like ERNIE-Bot-turbo'

使用endpoint进行调用

yaml
llm:
  api_type: 'qianfan'
  api_key: 'YOUR_API_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  endpoint: 'YOUR_ENDPOINT_NAME like ernie_speed'
llm:
  api_type: 'qianfan'
  api_key: 'YOUR_API_KEY'
  secret_key: 'YOUR_SECRET_KEY'
  endpoint: 'YOUR_ENDPOINT_NAME like ernie_speed'

阿里云 灵积 DashScope API

支持qwen-*模型和部分主流开源模型,详见metagpt/utils/token_counter.py

yaml
llm:
  api_type: 'dashscope'
  api_key: 'YOUR_API_KEY'
  model: 'YOUR_ENDPOINT_NAME like qwen-max'
llm:
  api_type: 'dashscope'
  api_key: 'YOUR_API_KEY'
  model: 'YOUR_ENDPOINT_NAME like qwen-max'

月之暗面 Moonshot API

支持 moonshot-v1-*模型,详见metagpt/utils/token_counter.py

yaml
llm:
  api_type: 'moonshot'
  base_url: 'https://api.moonshot.cn/v1'
  api_key: 'YOUR_API_KEY'
  model: 'moonshot-v1-8k'
llm:
  api_type: 'moonshot'
  base_url: 'https://api.moonshot.cn/v1'
  api_key: 'YOUR_API_KEY'
  model: 'moonshot-v1-8k'

FireWorks API

支持 FireWorksmodels模型,详见metagpt/utils/token_counter.py

yaml
llm:
  api_type: 'fireworks'
  base_url: 'https://api.fireworks.ai/inference/v1'
  api_key: 'YOUR_API_KEY'
  model: 'accounts/fireworks/models/llama-v2-13b-chat'
llm:
  api_type: 'fireworks'
  base_url: 'https://api.fireworks.ai/inference/v1'
  api_key: 'YOUR_API_KEY'
  model: 'accounts/fireworks/models/llama-v2-13b-chat'

Mistral API

支持 Mistralmodels模型,详见metagpt/utils/token_counter.py

yaml
llm:
  api_type: 'mistral'
  base_url: 'https://api.mistral.ai/v1'
  api_key: 'YOUR_API_KEY'
  model: 'open-mixtral-8x7b'
llm:
  api_type: 'mistral'
  base_url: 'https://api.mistral.ai/v1'
  api_key: 'YOUR_API_KEY'
  model: 'open-mixtral-8x7b'

Yi / 零一万物 API

支持模型名列表,在metagpt/utils/token_counter.pyyi-34b-*

yaml
llm:
  api_type: 'yi'
  base_url: 'https://api.lingyiwanwu.com/v1'
  api_key: 'YOUR_API_KEY'
  model: 'yi-34b-chat-0205'
  max_token: 4000
llm:
  api_type: 'yi'
  base_url: 'https://api.lingyiwanwu.com/v1'
  api_key: 'YOUR_API_KEY'
  model: 'yi-34b-chat-0205'
  max_token: 4000

ollama API

yaml
llm:
  api_type: 'ollama'
  base_url: 'http://127.0.0.1:11434/api'
  model: 'llama2'
llm:
  api_type: 'ollama'
  base_url: 'http://127.0.0.1:11434/api'
  model: 'llama2'

配置工具(可选)

除了让智能体能调用大模型,我们时常期望智能体能调用工具。我们需要配置好所需工具以完成准备工作。

网页搜索 API

Check search_config.py for more details.

yaml
## Supported api_type: serpapi/google/serper/ddg
## serper: Visit https://serper.dev/ to get key.
## serpapi: Visit https://serpapi.com/ to get key.
## google: Visit https://console.cloud.google.com/apis/credentials to get key.
## ddg: it is free, no need to get key.
search:
  api_type: 'google' # serpapi/google/serper/ddg
  api_key: 'YOUR_API_KEY'
  cse_id: 'YOUR_CSE_ID' # only for google
  params:
    engine: google # google/bing/yahoo/baidu/yandex, check https://serpapi.com/bing-search-api for more details
    google_domain: 'google.com'
    gl: us
    hl: en
## Supported api_type: serpapi/google/serper/ddg
## serper: Visit https://serper.dev/ to get key.
## serpapi: Visit https://serpapi.com/ to get key.
## google: Visit https://console.cloud.google.com/apis/credentials to get key.
## ddg: it is free, no need to get key.
search:
  api_type: 'google' # serpapi/google/serper/ddg
  api_key: 'YOUR_API_KEY'
  cse_id: 'YOUR_CSE_ID' # only for google
  params:
    engine: google # google/bing/yahoo/baidu/yandex, check https://serpapi.com/bing-search-api for more details
    google_domain: 'google.com'
    gl: us
    hl: en

网页浏览

yaml
browser:
  engine: 'playwright' # playwright/selenium
  # for playwright engine, please check https://playwright.dev/python/docs/api/class-browsertype
  # for selenium engine, please check https://www.selenium.dev/documentation/webdriver/browsers
  browser_type: 'chrome' # playwright: chromium/firefox/webkit; selenium: chrome/firefox/edge/ie
browser:
  engine: 'playwright' # playwright/selenium
  # for playwright engine, please check https://playwright.dev/python/docs/api/class-browsertype
  # for selenium engine, please check https://www.selenium.dev/documentation/webdriver/browsers
  browser_type: 'chrome' # playwright: chromium/firefox/webkit; selenium: chrome/firefox/edge/ie

Azure TTS

yaml
azure_tts_subscription_key: 'YOUR_API_KEY'
azure_tts_region: 'eastus'
azure_tts_subscription_key: 'YOUR_API_KEY'
azure_tts_region: 'eastus'

Mermaid

Check mermaid_config.py for more details.

yaml
mermaid:
  engine: 'nodejs' # nodejs/ink/playwright/pyppeteer
  path: 'mmdc' # such as './node_modules/.bin/mmdc'
  puppeteer_config: './config/puppeteer-config' # only for nodejs
  pyppeteer_path: '/usr/bin/google-chrome-stable' # only for pyppeteer
mermaid:
  engine: 'nodejs' # nodejs/ink/playwright/pyppeteer
  path: 'mmdc' # such as './node_modules/.bin/mmdc'
  puppeteer_config: './config/puppeteer-config' # only for nodejs
  pyppeteer_path: '/usr/bin/google-chrome-stable' # only for pyppeteer

其他配置(可选)

Check config2.example.yaml and config2.py for more details.

yaml
enable_longterm_memory: false
prompt_schema: json #json or markdown
enable_longterm_memory: false
prompt_schema: json #json or markdown

Released under the MIT License.