mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-20 15:38:09 +02:00
support new openai package
This commit is contained in:
parent
eaf531e0ac
commit
09134c9c72
8 changed files with 73 additions and 15 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
from httpx import AsyncClient, Client
|
||||
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI
|
||||
from metagpt.schema import UserMessage
|
||||
|
|
@ -78,3 +79,43 @@ def test_ask_code_list_str():
|
|||
assert "language" in rsp
|
||||
assert "code" in rsp
|
||||
assert len(rsp["code"]) > 0
|
||||
|
||||
|
||||
def test_make_client_kwargs():
|
||||
class Config:
|
||||
openai_api_key = "test_key"
|
||||
openai_base_url = "test_url"
|
||||
openai_proxy = "http://test_proxy"
|
||||
|
||||
config = Config()
|
||||
obj = OpenAIGPTAPI()
|
||||
kwargs, async_kwargs = obj._make_client_kwargs(config)
|
||||
|
||||
assert kwargs["api_key"] == "test_key"
|
||||
assert kwargs["base_url"] == "test_url/"
|
||||
assert isinstance(kwargs["http_client"], Client)
|
||||
assert kwargs["http_client"].base_url == "test_url/"
|
||||
|
||||
assert async_kwargs["api_key"] == "test_key"
|
||||
assert async_kwargs["base_url"] == "test_url/"
|
||||
assert isinstance(async_kwargs["http_client"], AsyncClient)
|
||||
assert async_kwargs["http_client"].base_url == "test_url/"
|
||||
|
||||
|
||||
def test_make_client_kwargs_no_proxy():
|
||||
class Config:
|
||||
openai_api_key = "test_key"
|
||||
openai_base_url = "test_url"
|
||||
openai_proxy = None
|
||||
|
||||
config = Config()
|
||||
obj = OpenAIGPTAPI()
|
||||
kwargs, async_kwargs = obj._make_client_kwargs(config)
|
||||
|
||||
assert kwargs["api_key"] == "test_key"
|
||||
assert kwargs["base_url"] == "test_url/"
|
||||
assert "http_client" not in kwargs
|
||||
|
||||
assert async_kwargs["api_key"] == "test_key"
|
||||
assert async_kwargs["base_url"] == "test_url/"
|
||||
assert "http_client" not in async_kwargs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue