Make remaining time of timers available to LLMs (#118696)

* Include speech_slots in IntentResponse.as_dict

* Populate speech_slots only if available

* fix typo

* Add test

* test all fields

* Fix another test

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
tronikos 2024-06-14 11:47:41 -07:00 committed by GitHub
parent c077c2a972
commit 6b8bddf6e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 4 deletions

View File

@ -1363,6 +1363,8 @@ class IntentResponse:
if self.reprompt: if self.reprompt:
response_dict["reprompt"] = self.reprompt response_dict["reprompt"] = self.reprompt
if self.speech_slots:
response_dict["speech_slots"] = self.speech_slots
response_data: dict[str, Any] = {} response_data: dict[str, Any] = {}

View File

@ -147,8 +147,13 @@ async def test_assist_api(
assert test_context.json_fragment # To reproduce an error case in tracing assert test_context.json_fragment # To reproduce an error case in tracing
intent_response = intent.IntentResponse("*") intent_response = intent.IntentResponse("*")
intent_response.matched_states = [State("light.matched", "on")] intent_response.async_set_states(
intent_response.unmatched_states = [State("light.unmatched", "on")] [State("light.matched", "on")], [State("light.unmatched", "on")]
)
intent_response.async_set_speech("Some speech")
intent_response.async_set_card("Card title", "card content")
intent_response.async_set_speech_slots({"hello": 1})
intent_response.async_set_reprompt("Do it again")
tool_input = llm.ToolInput( tool_input = llm.ToolInput(
tool_name="test_intent", tool_name="test_intent",
tool_args={"area": "kitchen", "floor": "ground_floor"}, tool_args={"area": "kitchen", "floor": "ground_floor"},
@ -179,8 +184,22 @@ async def test_assist_api(
"success": [], "success": [],
"targets": [], "targets": [],
}, },
"reprompt": {
"plain": {
"extra_data": None,
"reprompt": "Do it again",
},
},
"response_type": "action_done", "response_type": "action_done",
"speech": {}, "speech": {
"plain": {
"extra_data": None,
"speech": "Some speech",
},
},
"speech_slots": {
"hello": 1,
},
} }
# Call with a device/area/floor # Call with a device/area/floor
@ -225,7 +244,21 @@ async def test_assist_api(
"targets": [], "targets": [],
}, },
"response_type": "action_done", "response_type": "action_done",
"speech": {}, "reprompt": {
"plain": {
"extra_data": None,
"reprompt": "Do it again",
},
},
"speech": {
"plain": {
"extra_data": None,
"speech": "Some speech",
},
},
"speech_slots": {
"hello": 1,
},
} }