mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
add zhipuai_api unittest and remove useless log
This commit is contained in:
parent
8e201384bf
commit
2c81cc3e0f
3 changed files with 47 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
47
tests/metagpt/provider/test_zhipuai_api.py
Normal file
47
tests/metagpt/provider/test_zhipuai_api.py
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue