mirror of
https://github.com/home-assistant/core.git
synced 2025-05-04 05:59:16 +00:00
Break long strings in LLM tools (#118114)
* Break long code strings * Address comments --------- Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
89e2c57da6
commit
cee3be5f7a
@ -199,7 +199,10 @@ class AssistAPI(API):
|
|||||||
|
|
||||||
async def async_get_api_prompt(self, tool_input: ToolInput) -> str:
|
async def async_get_api_prompt(self, tool_input: ToolInput) -> str:
|
||||||
"""Return the prompt for the API."""
|
"""Return the prompt for the API."""
|
||||||
prompt = "Call the intent tools to control Home Assistant. Just pass the name to the intent."
|
prompt = (
|
||||||
|
"Call the intent tools to control Home Assistant. "
|
||||||
|
"Just pass the name to the intent."
|
||||||
|
)
|
||||||
if tool_input.device_id:
|
if tool_input.device_id:
|
||||||
device_reg = device_registry.async_get(self.hass)
|
device_reg = device_registry.async_get(self.hass)
|
||||||
device = device_reg.async_get(tool_input.device_id)
|
device = device_reg.async_get(tool_input.device_id)
|
||||||
|
@ -174,9 +174,9 @@ async def test_assist_api_prompt(
|
|||||||
)
|
)
|
||||||
api = llm.async_get_api(hass, "assist")
|
api = llm.async_get_api(hass, "assist")
|
||||||
prompt = await api.async_get_api_prompt(tool_input)
|
prompt = await api.async_get_api_prompt(tool_input)
|
||||||
assert (
|
assert prompt == (
|
||||||
prompt
|
"Call the intent tools to control Home Assistant."
|
||||||
== "Call the intent tools to control Home Assistant. Just pass the name to the intent."
|
" Just pass the name to the intent."
|
||||||
)
|
)
|
||||||
|
|
||||||
entry = MockConfigEntry(title=None)
|
entry = MockConfigEntry(title=None)
|
||||||
@ -190,18 +190,18 @@ async def test_assist_api_prompt(
|
|||||||
suggested_area="Test Area",
|
suggested_area="Test Area",
|
||||||
).id
|
).id
|
||||||
prompt = await api.async_get_api_prompt(tool_input)
|
prompt = await api.async_get_api_prompt(tool_input)
|
||||||
assert (
|
assert prompt == (
|
||||||
prompt
|
"Call the intent tools to control Home Assistant."
|
||||||
== "Call the intent tools to control Home Assistant. Just pass the name to the intent. You are in Test Area."
|
" Just pass the name to the intent. You are in Test Area."
|
||||||
)
|
)
|
||||||
|
|
||||||
floor = floor_registry.async_create("second floor")
|
floor = floor_registry.async_create("second floor")
|
||||||
area = area_registry.async_get_area_by_name("Test Area")
|
area = area_registry.async_get_area_by_name("Test Area")
|
||||||
area_registry.async_update(area.id, floor_id=floor.floor_id)
|
area_registry.async_update(area.id, floor_id=floor.floor_id)
|
||||||
prompt = await api.async_get_api_prompt(tool_input)
|
prompt = await api.async_get_api_prompt(tool_input)
|
||||||
assert (
|
assert prompt == (
|
||||||
prompt
|
"Call the intent tools to control Home Assistant."
|
||||||
== "Call the intent tools to control Home Assistant. Just pass the name to the intent. You are in Test Area (second floor)."
|
" Just pass the name to the intent. You are in Test Area (second floor)."
|
||||||
)
|
)
|
||||||
|
|
||||||
context.user_id = "12345"
|
context.user_id = "12345"
|
||||||
@ -210,7 +210,8 @@ async def test_assist_api_prompt(
|
|||||||
mock_user.name = "Test User"
|
mock_user.name = "Test User"
|
||||||
with patch("homeassistant.auth.AuthManager.async_get_user", return_value=mock_user):
|
with patch("homeassistant.auth.AuthManager.async_get_user", return_value=mock_user):
|
||||||
prompt = await api.async_get_api_prompt(tool_input)
|
prompt = await api.async_get_api_prompt(tool_input)
|
||||||
assert (
|
assert prompt == (
|
||||||
prompt
|
"Call the intent tools to control Home Assistant."
|
||||||
== "Call the intent tools to control Home Assistant. Just pass the name to the intent. You are in Test Area (second floor). The user name is Test User."
|
" Just pass the name to the intent. You are in Test Area (second floor)."
|
||||||
|
" The user name is Test User."
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user