mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Filter Anthropic schema (#168542)
This commit is contained in:
@@ -124,10 +124,14 @@ def _format_tool(
|
||||
tool: llm.Tool, custom_serializer: Callable[[Any], Any] | None
|
||||
) -> ToolParam:
|
||||
"""Format tool specification."""
|
||||
unsupported_keys = {"oneOf", "anyOf", "allOf"}
|
||||
schema = convert(tool.parameters, custom_serializer=custom_serializer)
|
||||
schema = {k: v for k, v in schema.items() if k not in unsupported_keys}
|
||||
|
||||
return ToolParam(
|
||||
name=tool.name,
|
||||
description=tool.description or "",
|
||||
input_schema=convert(tool.parameters, custom_serializer=custom_serializer),
|
||||
input_schema=schema,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ from homeassistant.components.anthropic.const import (
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.components.anthropic.entity import CitationDetails, ContentDetails
|
||||
from homeassistant.components.homeassistant.exposed_entities import async_expose_entity
|
||||
from homeassistant.components.intent import async_register_timer_handler
|
||||
from homeassistant.const import CONF_LLM_HASS_API
|
||||
from homeassistant.core import Context, HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -486,19 +488,25 @@ async def test_assist_api_tools_conversion(
|
||||
) -> None:
|
||||
"""Test that we are able to convert actual tools from Assist API."""
|
||||
for component in (
|
||||
"intent",
|
||||
"todo",
|
||||
"light",
|
||||
"shopping_list",
|
||||
"humidifier",
|
||||
"calendar",
|
||||
"climate",
|
||||
"media_player",
|
||||
"vacuum",
|
||||
"cover",
|
||||
"weather",
|
||||
"demo",
|
||||
"humidifier",
|
||||
"intent",
|
||||
"light",
|
||||
"media_player",
|
||||
"script",
|
||||
"shopping_list",
|
||||
"todo",
|
||||
"vacuum",
|
||||
"weather",
|
||||
):
|
||||
assert await async_setup_component(hass, component, {})
|
||||
hass.states.async_set(f"{component}.test", "on")
|
||||
async_expose_entity(hass, "conversation", f"{component}.test", True)
|
||||
|
||||
async_register_timer_handler(hass, "test_device", lambda *args: None)
|
||||
|
||||
agent_id = "conversation.claude_conversation"
|
||||
|
||||
@@ -506,11 +514,20 @@ async def test_assist_api_tools_conversion(
|
||||
create_content_block(0, ["Hello, how can I help you?"])
|
||||
]
|
||||
|
||||
await conversation.async_converse(hass, "hello", None, Context(), agent_id=agent_id)
|
||||
await conversation.async_converse(
|
||||
hass, "hello", None, Context(), agent_id=agent_id, device_id="test_device"
|
||||
)
|
||||
|
||||
tools = mock_create_stream.mock_calls[0][2]["tools"]
|
||||
assert tools
|
||||
|
||||
for tool in tools:
|
||||
for key in ("oneOf", "allOf", "anyOf"):
|
||||
assert key not in tool["input_schema"], (
|
||||
f"{tool['name']}.input_schema: input_schema does not support "
|
||||
"oneOf, allOf, or anyOf at the top level"
|
||||
)
|
||||
|
||||
|
||||
async def test_unknown_hass_api(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user