diff --git a/custom_components/ha_text_ai/api_client.py b/custom_components/ha_text_ai/api_client.py index 86cb553..e3f8255 100644 --- a/custom_components/ha_text_ai/api_client.py +++ b/custom_components/ha_text_ai/api_client.py @@ -106,6 +106,11 @@ class APIClient: return await self._create_openai_completion( model, messages, temperature, max_tokens ) + except (KeyError, IndexError) as e: + if "'choices'" in str(e) or "'message'" in str(e): + raise HomeAssistantError("Failed to get a response from the AI model. Please check your internet connection and try again later.") + else: + raise except Exception as e: _LOGGER.error("API request failed: %s", str(e)) raise HomeAssistantError(f"API request failed: {str(e)}") diff --git a/custom_components/ha_text_ai/manifest.json b/custom_components/ha_text_ai/manifest.json index a6ffb03..caa1571 100644 --- a/custom_components/ha_text_ai/manifest.json +++ b/custom_components/ha_text_ai/manifest.json @@ -23,6 +23,6 @@ "single_config_entry": false, "ssdp": [], "usb": [], - "version": "2.0.2-beta", + "version": "2.0.3-beta", "zeroconf": [] }