mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Add aliases to script llm tool description (#122380)
* Add aliases to script llm tool description * Also add name
This commit is contained in:
parent
262d778a38
commit
ed6d6575d7
@ -677,6 +677,19 @@ class ScriptTool(Tool):
|
|||||||
|
|
||||||
self.parameters = vol.Schema(schema)
|
self.parameters = vol.Schema(schema)
|
||||||
|
|
||||||
|
aliases: list[str] = []
|
||||||
|
if entity_entry.name:
|
||||||
|
aliases.append(entity_entry.name)
|
||||||
|
if entity_entry.aliases:
|
||||||
|
aliases.extend(entity_entry.aliases)
|
||||||
|
if aliases:
|
||||||
|
if self.description:
|
||||||
|
self.description = (
|
||||||
|
self.description + ". Aliases: " + str(list(aliases))
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.description = "Aliases: " + str(list(aliases))
|
||||||
|
|
||||||
parameters_cache[entity_entry.unique_id] = (
|
parameters_cache[entity_entry.unique_id] = (
|
||||||
self.description,
|
self.description,
|
||||||
self.parameters,
|
self.parameters,
|
||||||
|
@ -411,7 +411,9 @@ async def test_assist_api_prompt(
|
|||||||
)
|
)
|
||||||
hass.states.async_set(entry2.entity_id, "on", {"friendly_name": "Living Room"})
|
hass.states.async_set(entry2.entity_id, "on", {"friendly_name": "Living Room"})
|
||||||
|
|
||||||
def create_entity(device: dr.DeviceEntry, write_state=True) -> None:
|
def create_entity(
|
||||||
|
device: dr.DeviceEntry, write_state=True, aliases: set[str] | None = None
|
||||||
|
) -> None:
|
||||||
"""Create an entity for a device and track entity_id."""
|
"""Create an entity for a device and track entity_id."""
|
||||||
entity = entity_registry.async_get_or_create(
|
entity = entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
@ -421,6 +423,8 @@ async def test_assist_api_prompt(
|
|||||||
original_name=str(device.name or "Unnamed Device"),
|
original_name=str(device.name or "Unnamed Device"),
|
||||||
suggested_object_id=str(device.name or "unnamed_device"),
|
suggested_object_id=str(device.name or "unnamed_device"),
|
||||||
)
|
)
|
||||||
|
if aliases:
|
||||||
|
entity_registry.async_update_entity(entity.entity_id, aliases=aliases)
|
||||||
if write_state:
|
if write_state:
|
||||||
entity.write_unavailable_state(hass)
|
entity.write_unavailable_state(hass)
|
||||||
|
|
||||||
@ -432,7 +436,8 @@ async def test_assist_api_prompt(
|
|||||||
manufacturer="Test Manufacturer",
|
manufacturer="Test Manufacturer",
|
||||||
model="Test Model",
|
model="Test Model",
|
||||||
suggested_area="Test Area",
|
suggested_area="Test Area",
|
||||||
)
|
),
|
||||||
|
aliases={"my test light"},
|
||||||
)
|
)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
create_entity(
|
create_entity(
|
||||||
@ -516,7 +521,7 @@ async def test_assist_api_prompt(
|
|||||||
domain: light
|
domain: light
|
||||||
state: 'on'
|
state: 'on'
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Device
|
- names: Test Device, my test light
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
@ -616,6 +621,7 @@ async def test_assist_api_prompt(
|
|||||||
|
|
||||||
async def test_script_tool(
|
async def test_script_tool(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
area_registry: ar.AreaRegistry,
|
area_registry: ar.AreaRegistry,
|
||||||
floor_registry: fr.FloorRegistry,
|
floor_registry: fr.FloorRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -659,6 +665,10 @@ async def test_script_tool(
|
|||||||
)
|
)
|
||||||
async_expose_entity(hass, "conversation", "script.test_script", True)
|
async_expose_entity(hass, "conversation", "script.test_script", True)
|
||||||
|
|
||||||
|
entity_registry.async_update_entity(
|
||||||
|
"script.test_script", name="script name", aliases={"script alias"}
|
||||||
|
)
|
||||||
|
|
||||||
area = area_registry.async_create("Living room")
|
area = area_registry.async_create("Living room")
|
||||||
floor = floor_registry.async_create("2")
|
floor = floor_registry.async_create("2")
|
||||||
|
|
||||||
@ -671,7 +681,10 @@ async def test_script_tool(
|
|||||||
|
|
||||||
tool = tools[0]
|
tool = tools[0]
|
||||||
assert tool.name == "test_script"
|
assert tool.name == "test_script"
|
||||||
assert tool.description == "This is a test script"
|
assert (
|
||||||
|
tool.description
|
||||||
|
== "This is a test script. Aliases: ['script name', 'script alias']"
|
||||||
|
)
|
||||||
schema = {
|
schema = {
|
||||||
vol.Required("beer", description="Number of beers"): cv.string,
|
vol.Required("beer", description="Number of beers"): cv.string,
|
||||||
vol.Optional("wine"): selector.NumberSelector({"min": 0, "max": 3}),
|
vol.Optional("wine"): selector.NumberSelector({"min": 0, "max": 3}),
|
||||||
@ -684,7 +697,10 @@ async def test_script_tool(
|
|||||||
assert tool.parameters.schema == schema
|
assert tool.parameters.schema == schema
|
||||||
|
|
||||||
assert hass.data[llm.SCRIPT_PARAMETERS_CACHE] == {
|
assert hass.data[llm.SCRIPT_PARAMETERS_CACHE] == {
|
||||||
"test_script": ("This is a test script", vol.Schema(schema))
|
"test_script": (
|
||||||
|
"This is a test script. Aliases: ['script name', 'script alias']",
|
||||||
|
vol.Schema(schema),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
tool_input = llm.ToolInput(
|
tool_input = llm.ToolInput(
|
||||||
@ -754,12 +770,18 @@ async def test_script_tool(
|
|||||||
|
|
||||||
tool = tools[0]
|
tool = tools[0]
|
||||||
assert tool.name == "test_script"
|
assert tool.name == "test_script"
|
||||||
assert tool.description == "This is a new test script"
|
assert (
|
||||||
|
tool.description
|
||||||
|
== "This is a new test script. Aliases: ['script name', 'script alias']"
|
||||||
|
)
|
||||||
schema = {vol.Required("beer", description="Number of beers"): cv.string}
|
schema = {vol.Required("beer", description="Number of beers"): cv.string}
|
||||||
assert tool.parameters.schema == schema
|
assert tool.parameters.schema == schema
|
||||||
|
|
||||||
assert hass.data[llm.SCRIPT_PARAMETERS_CACHE] == {
|
assert hass.data[llm.SCRIPT_PARAMETERS_CACHE] == {
|
||||||
"test_script": ("This is a new test script", vol.Schema(schema))
|
"test_script": (
|
||||||
|
"This is a new test script. Aliases: ['script name', 'script alias']",
|
||||||
|
vol.Schema(schema),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user