diff --git a/config/config.yaml b/config/config.yaml index bed67083c..249552693 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -2,10 +2,10 @@ # The configuration of key.yaml has a higher priority and will not enter git #### 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" +## The official OPENAI_BASE_URL is https://api.openai.com/v1/ +## If the official OPENAI_BASE_URL 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_BASE_URL. +OPENAI_BASE_URL: "https://api.openai.com/v1/" #OPENAI_PROXY: "http://127.0.0.1:8118" #OPENAI_API_KEY: "YOUR_API_KEY" # set the value to sk-xxx if you host the openai interface for open llm model OPENAI_API_MODEL: "gpt-4" @@ -25,7 +25,7 @@ RPM: 10 #### 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_BASE_URL: "YOUR_AZURE_ENDPOINT" #OPENAI_API_KEY: "YOUR_AZURE_API_KEY" #OPENAI_API_VERSION: "YOUR_AZURE_API_VERSION" #DEPLOYMENT_NAME: "YOUR_DEPLOYMENT_NAME" diff --git a/docs/FAQ-EN.md b/docs/FAQ-EN.md index f9df50caf..1c5b4a86a 100644 --- a/docs/FAQ-EN.md +++ b/docs/FAQ-EN.md @@ -83,10 +83,10 @@ 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. The official OPENAI_BASE_URL address is `https://api.openai.com/v1/` + 1. If the official OPENAI_BASE_URL address is inaccessible in your environment (this can be verified with curl), it's recommended to configure using the reverse proxy OPENAI_BASE_URL provided by libraries such as openai-forward. For instance, `OPENAI_BASE_URL: "``https://api.openai-forward.com/v1/``"` + 1. If the official OPENAI_BASE_URL 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_BASE_URL 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_BASE_URL. + 1. Note: OpenAI's default API design ends with a v1. An example of the correct configuration is: `OPENAI_BASE_URL: "``https://api.openai.com/v1/``"` 1. Absolutely! How can I assist you today? diff --git a/docs/README_JA.md b/docs/README_JA.md index 411d190b4..33b08b770 100644 --- a/docs/README_JA.md +++ b/docs/README_JA.md @@ -219,7 +219,7 @@ # 設定ファイルをコピーし、必要な修正を加える。 | 変数名 | config/key.yaml | env | | --------------------------------------- | ----------------------------------------- | ----------------------------------------------- | | OPENAI_API_KEY # 自分のキーに置き換える | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." | -| OPENAI_API_BASE # オプション | OPENAI_API_BASE: "https:///v1" | export OPENAI_API_BASE="https:///v1" | +| OPENAI_BASE_URL # オプション | OPENAI_BASE_URL: "https:///v1/" | export OPENAI_BASE_URL="https:///v1/" | ## チュートリアル: スタートアップの開始 diff --git a/docs/tutorial/usage.md b/docs/tutorial/usage.md index ee87b65c9..f8a25c84f 100644 --- a/docs/tutorial/usage.md +++ b/docs/tutorial/usage.md @@ -13,7 +13,7 @@ # Copy the configuration file and make the necessary modifications. | 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:///v1" | export OPENAI_API_BASE="https:///v1" | +| OPENAI_BASE_URL # Optional | OPENAI_BASE_URL: "https:///v1/" | export OPENAI_BASE_URL="https:///v1/" | ### Initiating a startup diff --git a/docs/tutorial/usage_cn.md b/docs/tutorial/usage_cn.md index 4b3bdd2c3..ddd1c2267 100644 --- a/docs/tutorial/usage_cn.md +++ b/docs/tutorial/usage_cn.md @@ -13,7 +13,7 @@ # 复制配置文件并进行必要的修改 | 变量名 | config/key.yaml | env | | ----------------------------------- | ----------------------------------------- | ----------------------------------------------- | | OPENAI_API_KEY # 用您自己的密钥替换 | OPENAI_API_KEY: "sk-..." | export OPENAI_API_KEY="sk-..." | -| OPENAI_API_BASE # 可选 | OPENAI_API_BASE: "https:///v1" | export OPENAI_API_BASE="https:///v1" | +| OPENAI_BASE_URL # 可选 | OPENAI_BASE_URL: "https:///v1/" | export OPENAI_BASE_URL="https:///v1/" | ### 示例:启动一个创业公司 diff --git a/metagpt/config.py b/metagpt/config.py index 3f9e742bd..a6ecab5ff 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -46,11 +46,13 @@ class Config(metaclass=Singleton): self.openai_api_key = self._get("OPENAI_API_KEY") self.anthropic_api_key = self._get("Anthropic_API_KEY") self.zhipuai_api_key = self._get("ZHIPUAI_API_KEY") - if (not self.openai_api_key or "YOUR_API_KEY" == self.openai_api_key) and \ - (not self.anthropic_api_key or "YOUR_API_KEY" == self.anthropic_api_key) and \ - (not self.zhipuai_api_key or "YOUR_API_KEY" == self.zhipuai_api_key): + if ( + (not self.openai_api_key or "YOUR_API_KEY" == self.openai_api_key) + and (not self.anthropic_api_key or "YOUR_API_KEY" == self.anthropic_api_key) + and (not self.zhipuai_api_key or "YOUR_API_KEY" == self.zhipuai_api_key) + ): raise NotConfiguredException("Set OPENAI_API_KEY or Anthropic_API_KEY or ZHIPUAI_API_KEY first") - self.openai_api_base = self._get("OPENAI_API_BASE") + self.openai_api_base = self._get("OPENAI_BASE_URL") openai_proxy = self._get("OPENAI_PROXY") or self.global_proxy if openai_proxy: openai.proxy = openai_proxy