Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ def translate_anthropic_tool_choice_to_openai(
return ChatCompletionToolChoiceObjectParam(
type="function", function=tc_function_param
)
elif tool_choice["type"] == "none":
return "none"
else:
raise ValueError(
"Incompatible tool choice param submitted - {}".format(tool_choice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2162,16 +2162,19 @@ def test_incomplete_required_gets_completed(self):
assert sorted(schema["required"]) == ["age", "email", "name"]

def test_invalid_output_format_returns_none(self):
assert (
self.adapter.translate_anthropic_output_format_to_openai("invalid") is None
)
assert (
self.adapter.translate_anthropic_output_format_to_openai({"type": "text"})
is None
)
assert (
self.adapter.translate_anthropic_output_format_to_openai(
{"type": "json_schema"}
)
is None
)
assert self.adapter.translate_anthropic_output_format_to_openai("invalid") is None
assert self.adapter.translate_anthropic_output_format_to_openai({"type": "text"}) is None
assert self.adapter.translate_anthropic_output_format_to_openai({"type": "json_schema"}) is None


def test_translate_anthropic_tool_choice_none():
"""
Regression test for issue #24443.

tool_choice={"type": "none"} should be translated to "none" for OpenAI format,
not raise a ValueError.
"""
adapter = LiteLLMAnthropicMessagesAdapter()

result = adapter.translate_anthropic_tool_choice_to_openai({"type": "none"})
assert result == "none"
Loading