Skip to content

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

add zhipuai_api unittest and remove useless log

better6292c81cc3e0f97
diff --git a/metagpt/provider/general_api_requestor.py b/metagpt/provider/general_api_requestor.py
index e4e5f0f96..169b7c146 100644
--- a/metagpt/provider/general_api_requestor.py
+++ b/metagpt/provider/general_api_requestor.py
@@ -38,7 +38,6 @@ class GeneralAPIRequestor(APIRequestor):
self, result: aiohttp.ClientResponse, stream: bool
) -> Tuple[Union[str, AsyncGenerator[str, None]], bool]:
if stream and "text/event-stream" in result.headers.get("Content-Type", ""):
- logger.warning("stream")
return (
self._interpret_response_line(
line, result.status, result.headers, stream=True
@@ -46,7 +45,6 @@ class GeneralAPIRequestor(APIRequestor):
async for line in result.content
), True
else:
- logger.warning("non stream")
try:
await result.read()
except (aiohttp.ServerTimeoutError, asyncio.TimeoutError) as e:
diff --git a/metagpt/provider/zhipuai/zhipu_model_api.py b/metagpt/provider/zhipuai/zhipu_model_api.py
index f1fd6f2e2..e1d52061d 100644
--- a/metagpt/provider/zhipuai/zhipu_model_api.py
+++ b/metagpt/provider/zhipuai/zhipu_model_api.py
@@ -5,7 +5,6 @@
import zhipuai
from zhipuai.model_api.api import ModelAPI, InvokeType
from zhipuai.utils.http_client import headers as zhipuai_default_headers
-from zhipuai.utils.sse_client import SSEClient
from metagpt.provider.zhipuai.async_sse_client import AsyncSSEClient
from metagpt.provider.general_api_requestor import GeneralAPIRequestor
diff --git a/tests/metagpt/provider/test_zhipuai_api.py b/tests/metagpt/provider/test_zhipuai_api.py
new file mode 100644
index 000000000..6a0c70de5
--- /dev/null
+++ b/tests/metagpt/provider/test_zhipuai_api.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# @Desc : the unittest of ZhiPuAIGPTAPI
+
+import pytest
+
+from metagpt.provider.zhipuai_api import ZhiPuAIGPTAPI
+
+
+default_resp = {
+ "code": 200,
+ "data": {
+ "choices": [
+ {"role": "assistant", "content": "I'm chatglm-turbo"}
+ ]
+ }
+}
+
+messages = [
+ {"role": "user", "content": "who are you"}
+]
+
+
+def mock_llm_ask(self, messages: list[dict]) -> dict:
+ return default_resp
+
+
+def test_zhipuai_completion(mocker):
+ mocker.patch("metagpt.provider.zhipuai_api.ZhiPuAIGPTAPI.completion", mock_llm_ask)
+
+ resp = ZhiPuAIGPTAPI().completion(messages)
+ assert resp["code"] == 200
+ assert "chatglm-turbo" in resp["data"]["choices"][0]["content"]
+
+
+async def mock_llm_aask(self, messgaes: list[dict], stream: bool = False) -> dict:
+ return default_resp
+
+
+async def test_zhipuai_acompletion(mocker):
+ mocker.patch("metagpt.provider.zhipuai_api.ZhiPuAIGPTAPI.acompletion_text", mock_llm_aask)
+
+ resp = await ZhiPuAIGPTAPI().acompletion_text(messages, stream=False)
+
+ assert resp["code"] == 200
+ assert "chatglm-turbo" in resp["data"]["choices"][0]["content"]