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>
pull/119742/head
tronikos 2024-06-14 11:47:41 -07:00 committed by Franck Nijhof
parent 415bfb40a7
commit 7443878333
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 39 additions and 4 deletions

View File

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

View File

@ -149,8 +149,13 @@ async def test_assist_api(
assert test_context.json_fragment # To reproduce an error case in tracing
intent_response = intent.IntentResponse("*")
intent_response.matched_states = [State("light.matched", "on")]
intent_response.unmatched_states = [State("light.unmatched", "on")]
intent_response.async_set_states(
[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_name="test_intent",
tool_args={"area": "kitchen", "floor": "ground_floor"},
@ -181,8 +186,22 @@ async def test_assist_api(
"success": [],
"targets": [],
},
"reprompt": {
"plain": {
"extra_data": None,
"reprompt": "Do it again",
},
},
"response_type": "action_done",
"speech": {},
"speech": {
"plain": {
"extra_data": None,
"speech": "Some speech",
},
},
"speech_slots": {
"hello": 1,
},
}
# Call with a device/area/floor
@ -227,7 +246,21 @@ async def test_assist_api(
"targets": [],
},
"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,
},
}