mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-06 21:13:43 +00:00
fix: normalize content_filtered finish_reason (#23564)
Map provider finish_reason "content_filtered" to the OpenAI-compatible "content_filter" and extend core_helpers tests to cover this case. Made-with: Cursor
This commit is contained in:
@@ -96,6 +96,8 @@ _FINISH_REASON_MAP: dict[str, OpenAIChatCompletionFinishReason] = {
|
||||
"tool_calls": "tool_calls",
|
||||
"function_call": "function_call",
|
||||
"content_filter": "content_filter",
|
||||
# Anthropic Sonnet 4
|
||||
"content_filtered": "content_filter",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,20 +59,19 @@ VALID_OPENAI_FINISH_REASONS = {"stop", "length", "tool_calls", "function_call",
|
||||
|
||||
|
||||
class TestMapFinishReasonAnthropic:
|
||||
def test_stop_sequence(self):
|
||||
assert map_finish_reason("stop_sequence") == "stop"
|
||||
|
||||
def test_end_turn(self):
|
||||
assert map_finish_reason("end_turn") == "stop"
|
||||
|
||||
def test_max_tokens(self):
|
||||
assert map_finish_reason("max_tokens") == "length"
|
||||
|
||||
def test_tool_use(self):
|
||||
assert map_finish_reason("tool_use") == "tool_calls"
|
||||
|
||||
def test_compaction(self):
|
||||
assert map_finish_reason("compaction") == "length"
|
||||
@pytest.mark.parametrize(
|
||||
"provider_reason,expected",
|
||||
[
|
||||
("stop_sequence", "stop"),
|
||||
("end_turn", "stop"),
|
||||
("max_tokens", "length"),
|
||||
("tool_use", "tool_calls"),
|
||||
("compaction", "length"),
|
||||
("content_filtered", "content_filter"),
|
||||
],
|
||||
)
|
||||
def test_anthropic_finish_reasons(self, provider_reason: str, expected: str) -> None:
|
||||
assert map_finish_reason(provider_reason) == expected
|
||||
|
||||
|
||||
class TestMapFinishReasonGemini:
|
||||
|
||||
Reference in New Issue
Block a user