Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

merge main

geekan5c7cdf5ee76c
diff --cc metagpt/provider/zhipuai_api.py
index e4b066a0c,b258d2883..df8c330b8
--- a/metagpt/provider/zhipuai_api.py
+++ b/metagpt/provider/zhipuai_api.py
@@@ -47,8 -49,9 +47,11 @@@ class ZhiPuAIGPTAPI(BaseLLM)
def __init_zhipuai(self, config: CONFIG):
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.
+ # 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 --cc tests/metagpt/provider/test_zhipuai_api.py
index d9cd23281,dc8b63cc3..06f2cba62
--- a/tests/metagpt/provider/test_zhipuai_api.py
+++ b/tests/metagpt/provider/test_zhipuai_api.py
@@@ -30,24 -29,16 +30,34 @@@ async def mock_llm_achat_completion_str
@pytest.mark.asyncio
async def test_zhipuai_acompletion(mocker):
- mocker.patch("metagpt.provider.zhipuai_api.ZhiPuAIGPTAPI.acompletion_text", mock_llm_aask)
+ mocker.patch("metagpt.provider.zhipuai_api.ZhiPuAIGPTAPI.acompletion", mock_llm_acompletion)
+ mocker.patch("metagpt.provider.zhipuai_api.ZhiPuAIGPTAPI._achat_completion", mock_llm_acompletion)
+ mocker.patch(
+ "metagpt.provider.zhipuai_api.ZhiPuAIGPTAPI._achat_completion_stream", mock_llm_achat_completion_stream
+ )
+ zhipu_gpt = ZhiPuAIGPTAPI()
+
+ resp = await zhipu_gpt.acompletion(messages)
+ assert resp["data"]["choices"][0]["content"] == resp_content
- resp = await ZhiPuAIGPTAPI().acompletion_text(messages, stream=False)
+ resp = await zhipu_gpt.aask(prompt_msg, stream=False)
+ assert resp == resp_content
+
+ resp = await zhipu_gpt.acompletion_text(messages, stream=False)
+ assert resp == resp_content
+
+ resp = await zhipu_gpt.acompletion_text(messages, stream=True)
+ assert resp == resp_content
+
+ resp = await zhipu_gpt.aask(prompt_msg)
+ assert resp == resp_content
+
- 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'
++
++ CONFIG.openai_proxy = "http://127.0.0.1:8080"
+ _ = ZhiPuAIGPTAPI()
+ assert openai.proxy == CONFIG.openai_proxy