From 564bbe073d587461cbdf75b1487d2fd252542f33 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sat, 16 Nov 2024 13:38:49 -0700 Subject: [PATCH] c --- matrix_gpt/api_client_manager.py | 1 - matrix_gpt/generate_clients/anthropic.py | 6 +++--- matrix_gpt/generate_clients/api_client.py | 3 +-- matrix_gpt/generate_clients/openai.py | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/matrix_gpt/api_client_manager.py b/matrix_gpt/api_client_manager.py index 5edbdef..73f748a 100644 --- a/matrix_gpt/api_client_manager.py +++ b/matrix_gpt/api_client_manager.py @@ -16,7 +16,6 @@ Global variable to sync importing and sharing the configured module. class ApiClientManager: def __init__(self): self._openai_api_key = None - self._openai_api_base = None self._anth_api_key = None self.logger = logging.getLogger('MatrixGPT').getChild('ApiClientManager') diff --git a/matrix_gpt/generate_clients/anthropic.py b/matrix_gpt/generate_clients/anthropic.py index ae35745..9c8a151 100644 --- a/matrix_gpt/generate_clients/anthropic.py +++ b/matrix_gpt/generate_clients/anthropic.py @@ -11,10 +11,10 @@ class AnthropicApiClient(ApiClient): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - def _create_client(self): + def _create_client(self, api_base: str = None): return AsyncAnthropic( api_key=self._api_key, - base_url=self._api_base + base_url=api_base ) def prepare_context(self, context: list, system_prompt: str = None, injected_system_prompt: str = None): @@ -58,7 +58,7 @@ class AnthropicApiClient(ApiClient): }) async def generate(self, command_info: CommandInfo, matrix_gpt_data: str = None): - r = await self._create_client().messages.create( + r = await self._create_client(command_info.api_base).messages.create( model=command_info.model, max_tokens=None if command_info.max_tokens == 0 else command_info.max_tokens, temperature=command_info.temperature, diff --git a/matrix_gpt/generate_clients/api_client.py b/matrix_gpt/generate_clients/api_client.py index 95aef66..50e745b 100644 --- a/matrix_gpt/generate_clients/api_client.py +++ b/matrix_gpt/generate_clients/api_client.py @@ -10,12 +10,11 @@ class ApiClient: _HUMAN_NAME = 'user' _BOT_NAME = 'assistant' - def __init__(self, api_key: str, client_helper: MatrixClientHelper, room: MatrixRoom, event: Event, api_base: str = None): + def __init__(self, api_key: str, client_helper: MatrixClientHelper, room: MatrixRoom, event: Event): self._api_key = api_key self._client_helper = client_helper self._room = room self._event = event - self._api_base = api_base self._context = [] def _create_client(self): diff --git a/matrix_gpt/generate_clients/openai.py b/matrix_gpt/generate_clients/openai.py index c0b80c8..55d38a7 100644 --- a/matrix_gpt/generate_clients/openai.py +++ b/matrix_gpt/generate_clients/openai.py @@ -12,10 +12,10 @@ class OpenAIClient(ApiClient): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - def _create_client(self): + def _create_client(self, api_base: str = None): return AsyncOpenAI( api_key=self._api_key, - base_url=self._api_base + base_url=api_base ) def append_msg(self, content: str, role: str):