diff --git a/homeassistant/components/openai_conversation/__init__.py b/homeassistant/components/openai_conversation/__init__.py index 3f71537a9d2..c9d92f554ee 100644 --- a/homeassistant/components/openai_conversation/__init__.py +++ b/homeassistant/components/openai_conversation/__init__.py @@ -73,6 +73,7 @@ class OpenAIAgent(conversation.AbstractConversationAgent): try: prompt = self._async_generate_prompt() except TemplateError as err: + _LOGGER.error("Error rendering prompt: %s", err) intent_response = intent.IntentResponse(language=user_input.language) intent_response.async_set_error( intent.IntentResponseErrorCode.UNKNOWN, diff --git a/homeassistant/components/openai_conversation/const.py b/homeassistant/components/openai_conversation/const.py index 34516cbb109..378548173b0 100644 --- a/homeassistant/components/openai_conversation/const.py +++ b/homeassistant/components/openai_conversation/const.py @@ -15,14 +15,14 @@ An overview of the areas and the devices in this smart home: {{ area.name }}: {%- set area_info.printed = true %} {%- endif %} -- {{ device_attr(device, "name") }}{% if device_attr(device, "model") not in device_attr(device, "name") %} ({{ device_attr(device, "model") }}){% endif %} +- {{ device_attr(device, "name") }}{% if device_attr(device, "model") and device_attr(device, "model") not in device_attr(device, "name") %} ({{ device_attr(device, "model") }}){% endif %} {%- endif %} {%- endfor %} {%- endfor %} Answer the users questions about the world truthfully. -If the user wants to control a device, reject the request and suggest using the Home Assistant UI. +If the user wants to control a device, reject the request and suggest using the Home Assistant app. Now finish this conversation: diff --git a/tests/components/openai_conversation/test_init.py b/tests/components/openai_conversation/test_init.py index ac5be9f6115..551d493df8e 100644 --- a/tests/components/openai_conversation/test_init.py +++ b/tests/components/openai_conversation/test_init.py @@ -50,6 +50,12 @@ async def test_default_prompt(hass, mock_init_component): model="Test Model 3A", suggested_area="Test Area 2", ) + device_reg.async_get_or_create( + config_entry_id="1234", + connections={("test", "qwer")}, + name="Test Device 4", + suggested_area="Test Area 2", + ) device = device_reg.async_get_or_create( config_entry_id="1234", connections={("test", "9876-disabled")}, @@ -63,7 +69,9 @@ async def test_default_prompt(hass, mock_init_component): ) with patch("openai.Completion.create") as mock_create: - await conversation.async_converse(hass, "hello", None, Context()) + result = await conversation.async_converse(hass, "hello", None, Context()) + + assert result.response.response_type == intent.IntentResponseType.ACTION_DONE assert ( mock_create.mock_calls[0][2]["prompt"] @@ -77,10 +85,11 @@ Test Area: Test Area 2: - Test Device 2 - Test Device 3 (Test Model 3A) +- Test Device 4 Answer the users questions about the world truthfully. -If the user wants to control a device, reject the request and suggest using the Home Assistant UI. +If the user wants to control a device, reject the request and suggest using the Home Assistant app. Now finish this conversation: