From fe697ac0953300d5314fa30ca8935c4a5349a70f Mon Sep 17 00:00:00 2001 From: geekan Date: Thu, 28 Dec 2023 17:42:28 +0800 Subject: [PATCH] fix openai --- metagpt/config.py | 2 +- metagpt/provider/openai_api.py | 6 +++--- tests/metagpt/provider/test_openai.py | 14 ++++---------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/metagpt/config.py b/metagpt/config.py index 3acb07743..1adc27532 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -143,7 +143,7 @@ class Config(metaclass=Singleton): if not self._get("DISABLE_LLM_PROVIDER_CHECK"): _ = self.get_default_llm_provider_enum() - # self.openai_base_url = self._get("OPENAI_BASE_URL") + self.openai_base_url = self._get("OPENAI_BASE_URL") self.openai_proxy = self._get("OPENAI_PROXY") or self.global_proxy self.openai_api_type = self._get("OPENAI_API_TYPE") self.openai_api_version = self._get("OPENAI_API_VERSION") diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 64adbb1c0..20dde9ea5 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -69,7 +69,7 @@ class OpenAILLM(BaseLLM): self.aclient = AsyncOpenAI(**kwargs) def _make_client_kwargs(self) -> dict: - kwargs = {"api_key": self.config.OPENAI_API_KEY, "base_url": self.config.OPENAI_BASE_URL} + kwargs = {"api_key": self.config.openai_api_key, "base_url": self.config.openai_base_url} # to use proxy, openai v1 needs http_client if proxy_params := self._get_proxy_params(): @@ -81,8 +81,8 @@ class OpenAILLM(BaseLLM): params = {} if self.config.openai_proxy: params = {"proxies": self.config.openai_proxy} - if self.config.OPENAI_BASE_URL: - params["base_url"] = self.config.OPENAI_BASE_URL + if self.config.openai_base_url: + params["base_url"] = self.config.openai_base_url return params diff --git a/tests/metagpt/provider/test_openai.py b/tests/metagpt/provider/test_openai.py index 329edadff..cb86dfcf9 100644 --- a/tests/metagpt/provider/test_openai.py +++ b/tests/metagpt/provider/test_openai.py @@ -86,31 +86,25 @@ class TestOpenAI: def test_make_client_kwargs_without_proxy(self, config): instance = OpenAILLM() instance.config = config - kwargs, async_kwargs = instance._make_client_kwargs() + kwargs = instance._make_client_kwargs() assert kwargs == {"api_key": "test_key", "base_url": "test_url"} - assert async_kwargs == {"api_key": "test_key", "base_url": "test_url"} assert "http_client" not in kwargs - assert "http_client" not in async_kwargs def test_make_client_kwargs_without_proxy_azure(self, config_azure): instance = OpenAILLM() instance.config = config_azure - kwargs, async_kwargs = instance._make_client_kwargs() + kwargs = instance._make_client_kwargs() assert kwargs == {"api_key": "test_key", "base_url": "test_url"} - assert async_kwargs == {"api_key": "test_key", "base_url": "test_url"} assert "http_client" not in kwargs - assert "http_client" not in async_kwargs def test_make_client_kwargs_with_proxy(self, config_proxy): instance = OpenAILLM() instance.config = config_proxy - kwargs, async_kwargs = instance._make_client_kwargs() + kwargs = instance._make_client_kwargs() assert "http_client" in kwargs - assert "http_client" in async_kwargs def test_make_client_kwargs_with_proxy_azure(self, config_azure_proxy): instance = OpenAILLM() instance.config = config_azure_proxy - kwargs, async_kwargs = instance._make_client_kwargs() + kwargs = instance._make_client_kwargs() assert "http_client" in kwargs - assert "http_client" in async_kwargs