mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
Fix Anthropic bug parsing a streaming response with no json (#142745)
This commit is contained in:
parent
28d776a0b0
commit
d868f39aea
@ -266,7 +266,7 @@ async def _transform_stream(
|
|||||||
raise ValueError("Unexpected stop event without a current block")
|
raise ValueError("Unexpected stop event without a current block")
|
||||||
if current_block["type"] == "tool_use":
|
if current_block["type"] == "tool_use":
|
||||||
tool_block = cast(ToolUseBlockParam, current_block)
|
tool_block = cast(ToolUseBlockParam, current_block)
|
||||||
tool_args = json.loads(current_tool_args)
|
tool_args = json.loads(current_tool_args) if current_tool_args else {}
|
||||||
tool_block["input"] = tool_args
|
tool_block["input"] = tool_args
|
||||||
yield {
|
yield {
|
||||||
"tool_calls": [
|
"tool_calls": [
|
||||||
|
@ -303,11 +303,27 @@ async def test_conversation_agent(
|
|||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.anthropic.conversation.llm.AssistAPI._async_get_tools")
|
@patch("homeassistant.components.anthropic.conversation.llm.AssistAPI._async_get_tools")
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("tool_call_json_parts", "expected_call_tool_args"),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
['{"param1": "test_value"}'],
|
||||||
|
{"param1": "test_value"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
['{"para', 'm1": "test_valu', 'e"}'],
|
||||||
|
{"param1": "test_value"},
|
||||||
|
),
|
||||||
|
([""], {}),
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_function_call(
|
async def test_function_call(
|
||||||
mock_get_tools,
|
mock_get_tools,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_config_entry_with_assist: MockConfigEntry,
|
mock_config_entry_with_assist: MockConfigEntry,
|
||||||
mock_init_component,
|
mock_init_component,
|
||||||
|
tool_call_json_parts: list[str],
|
||||||
|
expected_call_tool_args: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test function call from the assistant."""
|
"""Test function call from the assistant."""
|
||||||
agent_id = "conversation.claude"
|
agent_id = "conversation.claude"
|
||||||
@ -343,7 +359,7 @@ async def test_function_call(
|
|||||||
1,
|
1,
|
||||||
"toolu_0123456789AbCdEfGhIjKlM",
|
"toolu_0123456789AbCdEfGhIjKlM",
|
||||||
"test_tool",
|
"test_tool",
|
||||||
['{"para', 'm1": "test_valu', 'e"}'],
|
tool_call_json_parts,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -387,7 +403,7 @@ async def test_function_call(
|
|||||||
llm.ToolInput(
|
llm.ToolInput(
|
||||||
id="toolu_0123456789AbCdEfGhIjKlM",
|
id="toolu_0123456789AbCdEfGhIjKlM",
|
||||||
tool_name="test_tool",
|
tool_name="test_tool",
|
||||||
tool_args={"param1": "test_value"},
|
tool_args=expected_call_tool_args,
|
||||||
),
|
),
|
||||||
llm.LLMContext(
|
llm.LLMContext(
|
||||||
platform="anthropic",
|
platform="anthropic",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user