OpenAI: Fix device without model (#86754)

pull/86756/head
Paulus Schoutsen 2023-01-26 17:25:02 -05:00 committed by GitHub
parent 04bc522fa5
commit 9cd48b4999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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: