mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(anthropic): keep defer_loading and allowed_callers on the computer_20251124 chat tool
This commit is contained in:
parent
e896a9bb9c
commit
2d36056193
2 changed files with 22 additions and 6 deletions
|
|
@ -1114,9 +1114,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
if returned_tool is not None:
|
||||
# Only set defer_loading on tools that support it (not tool search tools or computer tools)
|
||||
tool_type = returned_tool.get("type", "")
|
||||
if not tool_type.startswith("computer_") and tool_type not in (
|
||||
if tool_type not in (
|
||||
"tool_search_tool_regex_20251119",
|
||||
"tool_search_tool_bm25_20251119",
|
||||
"computer_20241022",
|
||||
"computer_20250124",
|
||||
):
|
||||
if _defer_loading is not None:
|
||||
returned_tool["defer_loading"] = _validated_defer_loading(_defer_loading)
|
||||
|
|
@ -1131,9 +1133,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
if returned_tool is not None:
|
||||
# Only set allowed_callers on tools that support it (not tool search tools or computer tools)
|
||||
tool_type = returned_tool.get("type", "")
|
||||
if not tool_type.startswith("computer_") and tool_type not in (
|
||||
if tool_type not in (
|
||||
"tool_search_tool_regex_20251119",
|
||||
"tool_search_tool_bm25_20251119",
|
||||
"computer_20241022",
|
||||
"computer_20250124",
|
||||
):
|
||||
if _allowed_callers is not None:
|
||||
if not isinstance(_allowed_callers, list) or not all(
|
||||
|
|
|
|||
|
|
@ -6787,22 +6787,34 @@ def test_eager_input_streaming_not_set_on_computer_use_tool():
|
|||
assert "eager_input_streaming" not in mapped_tool
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tool_type", ["computer_20241022", "computer_20250124", "computer_20251124"])
|
||||
def test_computer_tools_drop_defer_loading_and_allowed_callers(tool_type: str):
|
||||
computer_tool: Final = {
|
||||
def _computer_tool_with_defer_loading_and_allowed_callers(tool_type: str) -> dict[str, object]:
|
||||
return {
|
||||
"type": tool_type,
|
||||
"function": {"name": "computer", "parameters": {"display_width_px": 1024, "display_height_px": 768}},
|
||||
"defer_loading": True,
|
||||
"allowed_callers": ["code_execution_20250825"],
|
||||
}
|
||||
|
||||
mapped_tool, _ = AnthropicConfig().map_tool_helper(computer_tool)
|
||||
|
||||
@pytest.mark.parametrize("tool_type", ["computer_20241022", "computer_20250124"])
|
||||
def test_legacy_computer_tools_drop_defer_loading_and_allowed_callers(tool_type: str):
|
||||
mapped_tool, _ = AnthropicConfig().map_tool_helper(_computer_tool_with_defer_loading_and_allowed_callers(tool_type))
|
||||
|
||||
assert mapped_tool["type"] == tool_type
|
||||
assert "defer_loading" not in mapped_tool
|
||||
assert "allowed_callers" not in mapped_tool
|
||||
|
||||
|
||||
def test_computer_20251124_keeps_defer_loading_and_allowed_callers():
|
||||
mapped_tool, _ = AnthropicConfig().map_tool_helper(
|
||||
_computer_tool_with_defer_loading_and_allowed_callers("computer_20251124")
|
||||
)
|
||||
|
||||
assert mapped_tool["type"] == "computer_20251124"
|
||||
assert mapped_tool["defer_loading"] is True
|
||||
assert mapped_tool["allowed_callers"] == ["code_execution_20250825"]
|
||||
|
||||
|
||||
def test_eager_input_streaming_reaches_anthropic_request_tools():
|
||||
result = AnthropicConfig().map_openai_params(
|
||||
non_default_params={"tools": [_eager_chat_tool(eager_input_streaming=True)], "stream": True},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue