mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
LLM Tool parameters check (#123621)
* LLM Tool parameters check * fix tests
This commit is contained in:
parent
391de22342
commit
a85ccb94e3
@ -177,6 +177,11 @@ class APIInstance:
|
|||||||
else:
|
else:
|
||||||
raise HomeAssistantError(f'Tool "{tool_input.tool_name}" not found')
|
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)
|
return await tool.async_call(self.api.hass, tool_input, self.llm_context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ async def test_function_call(
|
|||||||
name="test_tool",
|
name="test_tool",
|
||||||
args={
|
args={
|
||||||
"param1": ["test_value", "param1\\'s value"],
|
"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_name="test_tool",
|
||||||
tool_args={
|
tool_args={
|
||||||
"param1": ["test_value", "param1's value"],
|
"param1": ["test_value", "param1's value"],
|
||||||
"param2": "param2's value",
|
"param2": 2.7,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
llm.LLMContext(
|
llm.LLMContext(
|
||||||
|
@ -121,7 +121,7 @@ async def test_template_variables(
|
|||||||
("tool_args", "expected_tool_args"),
|
("tool_args", "expected_tool_args"),
|
||||||
[
|
[
|
||||||
({"param1": "test_value"}, {"param1": "test_value"}),
|
({"param1": "test_value"}, {"param1": "test_value"}),
|
||||||
({"param1": 2}, {"param1": 2}),
|
({"param2": 2}, {"param2": 2}),
|
||||||
(
|
(
|
||||||
{"param1": "test_value", "floor": ""},
|
{"param1": "test_value", "floor": ""},
|
||||||
{"param1": "test_value"}, # Omit empty arguments
|
{"param1": "test_value"}, # Omit empty arguments
|
||||||
@ -153,7 +153,8 @@ async def test_function_call(
|
|||||||
mock_tool.name = "test_tool"
|
mock_tool.name = "test_tool"
|
||||||
mock_tool.description = "Test function"
|
mock_tool.description = "Test function"
|
||||||
mock_tool.parameters = vol.Schema(
|
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"
|
mock_tool.async_call.return_value = "Test response"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user