diff --git a/metagpt/provider/zhipuai_api.py b/metagpt/provider/zhipuai_api.py index e4b066a0c..df8c330b8 100644 --- a/metagpt/provider/zhipuai_api.py +++ b/metagpt/provider/zhipuai_api.py @@ -49,6 +49,9 @@ class ZhiPuAIGPTAPI(BaseLLM): zhipuai.api_key = config.zhipuai_api_key # due to use openai sdk, set the api_key but it will't be used. # 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: + # FIXME: openai v1.x sdk has no proxy support + openai.proxy = config.openai_proxy def _const_kwargs(self, messages: list[dict]) -> dict: kwargs = {"model": self.model, "prompt": messages, "temperature": 0.3} diff --git a/tests/metagpt/provider/test_zhipuai_api.py b/tests/metagpt/provider/test_zhipuai_api.py index d9cd23281..06f2cba62 100644 --- a/tests/metagpt/provider/test_zhipuai_api.py +++ b/tests/metagpt/provider/test_zhipuai_api.py @@ -51,3 +51,13 @@ async def test_zhipuai_acompletion(mocker): resp = await zhipu_gpt.aask(prompt_msg) assert resp == resp_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