10000 Replace dot with underscores for NamespacedTool and ActionTool by Shulyaka · Pull Request #147764 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace dot with underscores for NamespacedTool and ActionTool #147764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/helpers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class NamespacedTool(Tool):
def __init__(self, namespace: str, tool: Tool) -> None:
"""Init the class."""
self.namespace = namespace
self.name = f"{namespace}.{tool.name}"
self.name = f"{namespace}__{tool.name}"
self.description = tool.description
self.parameters = tool.parameters
self.tool = tool
Expand Down Expand Up @@ -899,7 +899,7 @@ def __init__(
"""Init the class."""
self._domain = domain
self._action = action
self.name = f"{domain}.{action}"
self.name = f"{domain}__{action}"
# Note: _get_cached_action_parameters only works for services which
# add their description directly to the service description cache.
# This is not the case for most services, but it is for scripts.
Expand Down
8 changes: 4 additions & 4 deletions tests/helpers/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,18 +1489,18 @@ async def async_call(
"""
)
assert [(tool.name, tool.description) for tool in instance.tools] == [
("api-1.Tool_1", "Description 1"),
("api-2.Tool_2", "Description 2"),
("api-1__Tool_1", "Description 1"),
("api-2__Tool_2", "Description 2"),
]

# The test tool returns back the provided arguments so we can verify
# the original tool is invoked with the correct tool name and args.
result = await instance.async_call_tool(
llm.ToolInput(tool_name="api-1.Tool_1", tool_args={"arg1": "value1"})
llm.ToolInput(tool_name="api-1__Tool_1", tool_args={"arg1": "value1"})
)
assert result == {"result": {"Tool_1": {"arg1": "value1"}}}

result = await instance.async_call_tool(
llm.ToolInput(tool_name="api-2.Tool_2", tool_args={"arg2": "value2"})
llm.ToolInput(tool_name="api-2__Tool_2", tool_args={"arg2": "value2"})
)
assert result == {"result": {"Tool_2": {"arg2": "value2"}}}
0