LLM Tool parameters check (#123621)

* LLM Tool parameters check

* fix tests
pull/125554/head
Denis Shulyaka 2024-09-09 04:42:51 +03:00 committed by GitHub
parent 391de22342
commit a85ccb94e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View File

@ -177,6 +177,11 @@ class APIInstance:
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)

View File

@ -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,
},
)
@ -258,7 +258,7 @@ async def test_function_call(
tool_name="test_tool",
tool_args={
"param1": ["test_value", "param1's value"],
"param2": "param2's value",
"param2": 2.7,
},
),
llm.LLMContext(

View File

@ -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
@ -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"