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:
Denis Shulyaka 2024-05-25 21:24:51 +03:00 committed by GitHub
parent 89e2c57da6
commit cee3be5f7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 13 deletions

View File

@ -199,7 +199,10 @@ class AssistAPI(API):
async def async_get_api_prompt(self, tool_input: ToolInput) -> str:
"""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:
device_reg = device_registry.async_get(self.hass)
device = device_reg.async_get(tool_input.device_id)

View File

@ -174,9 +174,9 @@ async def test_assist_api_prompt(
)
api = llm.async_get_api(hass, "assist")
prompt = await api.async_get_api_prompt(tool_input)
assert (
prompt
== "Call the intent tools to control Home Assistant. Just pass the name to the intent."
assert prompt == (
"Call the intent tools to control Home Assistant."
" Just pass the name to the intent."
)
entry = MockConfigEntry(title=None)
@ -190,18 +190,18 @@ async def test_assist_api_prompt(
suggested_area="Test Area",
).id
prompt = await api.async_get_api_prompt(tool_input)
assert (
prompt
== "Call the intent tools to control Home Assistant. Just pass the name to the intent. You are in Test Area."
assert prompt == (
"Call the intent tools to control Home Assistant."
" Just pass the name to the intent. You are in Test Area."
)
floor = floor_registry.async_create("second floor")
area = area_registry.async_get_area_by_name("Test Area")
area_registry.async_update(area.id, floor_id=floor.floor_id)
prompt = await api.async_get_api_prompt(tool_input)
assert (
prompt
== "Call the intent tools to control Home Assistant. Just pass the name to the intent. You are in Test Area (second floor)."
assert prompt == (
"Call the intent tools to control Home Assistant."
" Just pass the name to the intent. You are in Test Area (second floor)."
)
context.user_id = "12345"
@ -210,7 +210,8 @@ async def test_assist_api_prompt(
mock_user.name = "Test User"
with patch("homeassistant.auth.AuthManager.async_get_user", return_value=mock_user):
prompt = await api.async_get_api_prompt(tool_input)
assert (
prompt
== "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."
assert prompt == (
"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."
)