From c9c03fc39d5969299132cb3de5dff536ed5dd149 Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Sat, 31 May 2025 14:30:21 -0400 Subject: [PATCH] Introduce BaseOpenAICompatibleAPIAgent --- .../llama_conversation/conversation.py | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/custom_components/llama_conversation/conversation.py b/custom_components/llama_conversation/conversation.py index 8393fcc..30b1873 100644 --- a/custom_components/llama_conversation/conversation.py +++ b/custom_components/llama_conversation/conversation.py @@ -1225,7 +1225,7 @@ class LlamaCppAgent(LocalLLMAgent): return result -class GenericOpenAIAPIAgent(LocalLLMAgent): +class BaseOpenAICompatibleAPIAgent(LocalLLMAgent): api_host: str api_key: str model_name: str @@ -1241,6 +1241,8 @@ class GenericOpenAIAPIAgent(LocalLLMAgent): self.api_key = entry.data.get(CONF_OPENAI_API_KEY) self.model_name = entry.data.get(CONF_CHAT_MODEL) +class GenericOpenAIAPIAgent(BaseOpenAICompatibleAPIAgent): + """Implements the OpenAPI-compatible text completion and chat completion API backends.""" def _chat_completion_params(self, conversation: dict) -> (str, dict): request_params = {} @@ -1319,22 +1321,8 @@ class GenericOpenAIAPIAgent(LocalLLMAgent): return self._extract_response(result) -class GenericOpenAIResponsesAPIAgent(LocalLLMAgent): +class GenericOpenAIResponsesAPIAgent(BaseOpenAICompatibleAPIAgent): """Implements the OpenAPI-compatible Responses API backend.""" - api_host: str - api_key: str - model_name: str - - async def _async_load_model(self, entry: ConfigEntry) -> None: - self.api_host = format_url( - hostname=entry.data[CONF_HOST], - port=entry.data[CONF_PORT], - ssl=entry.data[CONF_SSL], - path="" - ) - - self.api_key = entry.data.get(CONF_OPENAI_API_KEY) - self.model_name = entry.data.get(CONF_CHAT_MODEL) def _responses_params(self, conversation: dict) -> (str, dict): request_params = {}