diff --git a/custom_components/llama_conversation/ai_task.py b/custom_components/llama_conversation/ai_task.py index 9fd6063..d55c619 100644 --- a/custom_components/llama_conversation/ai_task.py +++ b/custom_components/llama_conversation/ai_task.py @@ -156,7 +156,7 @@ class LocalLLMTaskEntity( def _extract_data( self, raw_text: str, - tool_calls: list | None, + tool_calls: list[llm.ToolInput] | None, extraction_method: ResultExtractionMethod, chat_log: conversation.ChatLog, structure: vol.Schema | None, @@ -178,8 +178,9 @@ class LocalLLMTaskEntity( if extraction_method == ResultExtractionMethod.TOOL: first_tool = next(iter(tool_calls or []), None) - if not first_tool or not getattr(first_tool, "tool_args", None): + if not first_tool: return None, HomeAssistantError("Please produce at least one tool call with the structured response.") + structure(first_tool.tool_args) # validate tool call against vol schema structure return ai_task.GenDataTaskResult( conversation_id=chat_log.conversation_id, diff --git a/custom_components/llama_conversation/backends/generic_openai.py b/custom_components/llama_conversation/backends/generic_openai.py index 3d5a88b..8c0fc8e 100644 --- a/custom_components/llama_conversation/backends/generic_openai.py +++ b/custom_components/llama_conversation/backends/generic_openai.py @@ -111,7 +111,7 @@ class GenericOpenAIAPIClient(LocalLLMClient): ) as response: response.raise_for_status() models_result = await response.json() - except: + except (asyncio.TimeoutError, aiohttp.ClientResponseError): _LOGGER.exception("Failed to get available models") return RECOMMENDED_CHAT_MODELS diff --git a/custom_components/llama_conversation/manifest.json b/custom_components/llama_conversation/manifest.json index 6d7c4ab..036f1a2 100644 --- a/custom_components/llama_conversation/manifest.json +++ b/custom_components/llama_conversation/manifest.json @@ -1,7 +1,7 @@ { "domain": "llama_conversation", "name": "Local LLMs", - "version": "0.4.4", + "version": "0.4.5", "codeowners": ["@acon96"], "config_flow": true, "dependencies": ["conversation", "ai_task"], diff --git a/custom_components/llama_conversation/utils.py b/custom_components/llama_conversation/utils.py index 4fe9b95..2ad6f59 100644 --- a/custom_components/llama_conversation/utils.py +++ b/custom_components/llama_conversation/utils.py @@ -279,7 +279,8 @@ def get_oai_formatted_tools(llm_api: llm.APIInstance, domains: list[str]) -> Lis result: List[ChatCompletionTool] = [] for tool in llm_api.tools: - if tool.name == SERVICE_TOOL_NAME: + # when combining with home assistant llm APIs, it adds a prefix to differentiate tools; compare against the suffix here + if tool.name.endswith(SERVICE_TOOL_NAME): result.extend([{ "type": "function", "function": {