mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
fix(core_helpers): map Anthropic model_context_window_exceeded stop reason to length
Anthropic returns stop_reason="model_context_window_exceeded" when generation stops because the context window filled up. _FINISH_REASON_MAP had no entry for it, so map_finish_reason logged a warning and returned "stop" — clients cannot distinguish a truncated response from a complete one, on both chat completions and the Responses API. Map it to "length" (consistent with max_tokens and the existing compaction entry) and cover it in the Anthropic parametrized finish-reason tests. Fixes #43012
This commit is contained in:
parent
118ce3cc91
commit
bbc265d912
2 changed files with 2 additions and 0 deletions
|
|
@ -199,6 +199,7 @@ _FINISH_REASON_MAP: Final[dict[str, OpenAIChatCompletionFinishReason]] = {
|
|||
"stop_sequence": "stop",
|
||||
"end_turn": "stop",
|
||||
"max_tokens": "length",
|
||||
"model_context_window_exceeded": "length",
|
||||
"tool_use": "tool_calls",
|
||||
"refusal": "content_filter",
|
||||
"compaction": "length",
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ class TestMapFinishReasonAnthropic:
|
|||
("stop_sequence", "stop"),
|
||||
("end_turn", "stop"),
|
||||
("max_tokens", "length"),
|
||||
("model_context_window_exceeded", "length"),
|
||||
("tool_use", "tool_calls"),
|
||||
("compaction", "length"),
|
||||
("content_filtered", "content_filter"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue