Skip to content

Commit

Permalink
LLM Tool parameters check (#123621)
Browse files Browse the repository at this point in the history
* LLM Tool parameters check

* fix tests
  • Loading branch information
Shulyaka authored Sep 9, 2024
1 parent 391de22 commit a85ccb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions homeassistant/helpers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ async def async_call_tool(self, tool_input: ToolInput) -> JsonObjectType:
else:
raise HomeAssistantError(f'Tool "{tool_input.tool_name}" not found')

tool_input = ToolInput(
tool_name=tool_input.tool_name,
tool_args=tool.parameters(tool_input.tool_args),
)

return await tool.async_call(self.api.hass, tool_input, self.llm_context)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def test_function_call(
name="test_tool",
args={
"param1": ["test_value", "param1\\'s value"],
"param2": "param2\\'s value",
"param2": 2.7,
},
)

Expand Down Expand Up @@ -258,7 +258,7 @@ def tool_call(
tool_name="test_tool",
tool_args={
"param1": ["test_value", "param1's value"],
"param2": "param2's value",
"param2": 2.7,
},
),
llm.LLMContext(
Expand Down
5 changes: 3 additions & 2 deletions tests/components/ollama/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def test_template_variables(
("tool_args", "expected_tool_args"),
[
({"param1": "test_value"}, {"param1": "test_value"}),
({"param1": 2}, {"param1": 2}),
({"param2": 2}, {"param2": 2}),
(
{"param1": "test_value", "floor": ""},
{"param1": "test_value"}, # Omit empty arguments
Expand Down Expand Up @@ -153,7 +153,8 @@ async def test_function_call(
mock_tool.name = "test_tool"
mock_tool.description = "Test function"
mock_tool.parameters = vol.Schema(
{vol.Optional("param1", description="Test parameters"): str}
{vol.Optional("param1", description="Test parameters"): str},
extra=vol.ALLOW_EXTRA,
)
mock_tool.async_call.return_value = "Test response"

Expand Down

0 comments on commit a85ccb9

Please sign in to comment.