OpenAI: Fix device without model (#86754)
This commit is contained in:
parent
04bc522fa5
commit
9cd48b4999
3 changed files with 14 additions and 4 deletions
|
@ -73,6 +73,7 @@ class OpenAIAgent(conversation.AbstractConversationAgent):
|
||||||
try:
|
try:
|
||||||
prompt = self._async_generate_prompt()
|
prompt = self._async_generate_prompt()
|
||||||
except TemplateError as err:
|
except TemplateError as err:
|
||||||
|
_LOGGER.error("Error rendering prompt: %s", err)
|
||||||
intent_response = intent.IntentResponse(language=user_input.language)
|
intent_response = intent.IntentResponse(language=user_input.language)
|
||||||
intent_response.async_set_error(
|
intent_response.async_set_error(
|
||||||
intent.IntentResponseErrorCode.UNKNOWN,
|
intent.IntentResponseErrorCode.UNKNOWN,
|
||||||
|
|
|
@ -15,14 +15,14 @@ An overview of the areas and the devices in this smart home:
|
||||||
{{ area.name }}:
|
{{ area.name }}:
|
||||||
{%- set area_info.printed = true %}
|
{%- set area_info.printed = true %}
|
||||||
{%- endif %}
|
{%- 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 %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
Answer the users questions about the world truthfully.
|
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:
|
Now finish this conversation:
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,12 @@ async def test_default_prompt(hass, mock_init_component):
|
||||||
model="Test Model 3A",
|
model="Test Model 3A",
|
||||||
suggested_area="Test Area 2",
|
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(
|
device = device_reg.async_get_or_create(
|
||||||
config_entry_id="1234",
|
config_entry_id="1234",
|
||||||
connections={("test", "9876-disabled")},
|
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:
|
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 (
|
assert (
|
||||||
mock_create.mock_calls[0][2]["prompt"]
|
mock_create.mock_calls[0][2]["prompt"]
|
||||||
|
@ -77,10 +85,11 @@ Test Area:
|
||||||
Test Area 2:
|
Test Area 2:
|
||||||
- Test Device 2
|
- Test Device 2
|
||||||
- Test Device 3 (Test Model 3A)
|
- Test Device 3 (Test Model 3A)
|
||||||
|
- Test Device 4
|
||||||
|
|
||||||
Answer the users questions about the world truthfully.
|
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:
|
Now finish this conversation:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue