mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
[Bugfix] Set openai proxy for class ZhiPuAPTAPI
When using ZHIPUAI as the large model provider, it is not possible to access ZHIPUAI in an HTTP proxy environment, and the following error will be reported: openai.error.APIConnectionError: Error communicating with OpenAI So we need set proxy for class ZhiPuAPTAPI.
This commit is contained in:
parent
4f52b47610
commit
a87b5056d7
2 changed files with 9 additions and 0 deletions
|
|
@ -50,6 +50,8 @@ class ZhiPuAIGPTAPI(BaseGPTAPI):
|
|||
assert config.zhipuai_api_key
|
||||
zhipuai.api_key = config.zhipuai_api_key
|
||||
openai.api_key = zhipuai.api_key # due to use openai sdk, set the api_key but it will't be used.
|
||||
if config.openai_proxy:
|
||||
openai.proxy = config.openai_proxy
|
||||
|
||||
def _const_kwargs(self, messages: list[dict]) -> dict:
|
||||
kwargs = {"model": self.model, "prompt": messages, "temperature": 0.3}
|
||||
|
|
|
|||
|
|
@ -35,3 +35,10 @@ async def test_zhipuai_acompletion(mocker):
|
|||
|
||||
assert resp["code"] == 200
|
||||
assert "chatglm-turbo" in resp["data"]["choices"][0]["content"]
|
||||
|
||||
def test_zhipuai_proxy(mocker):
|
||||
import openai
|
||||
from metagpt.config import CONFIG
|
||||
CONFIG.openai_proxy = 'http://127.0.0.1:8080'
|
||||
_ = ZhiPuAIGPTAPI()
|
||||
assert openai.proxy == CONFIG.openai_proxy
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue