mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
fix(core_helpers): map generic 'error' finish_reason to 'stop' (#33972)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
265945dfcd
commit
aa1180c0c9
2 changed files with 16 additions and 0 deletions
|
|
@ -131,6 +131,9 @@ _FINISH_REASON_MAP: Final[dict[str, OpenAIChatCompletionFinishReason]] = {
|
|||
"content_filter": "content_filter",
|
||||
# Anthropic Sonnet 4
|
||||
"content_filtered": "content_filter",
|
||||
# Generic error passthrough (OpenRouter and other OpenAI-compatible providers
|
||||
# emit lowercase "error" when a provider fails mid-stream)
|
||||
"error": "stop",
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -192,6 +192,19 @@ class TestMapFinishReasonOpenAIPassthrough:
|
|||
assert map_finish_reason(reason) == reason
|
||||
|
||||
|
||||
class TestMapFinishReasonGenericError:
|
||||
def test_lowercase_error_is_explicitly_mapped(self):
|
||||
assert "error" in _FINISH_REASON_MAP
|
||||
assert map_finish_reason("error") == "stop"
|
||||
|
||||
def test_lowercase_error_does_not_warn(self, mocker):
|
||||
warn = mocker.patch(
|
||||
"litellm.litellm_core_utils.core_helpers.verbose_logger.warning"
|
||||
)
|
||||
assert map_finish_reason("error") == "stop"
|
||||
warn.assert_not_called()
|
||||
|
||||
|
||||
class TestMapFinishReasonUnknown:
|
||||
def test_unknown_value_defaults_to_stop(self):
|
||||
assert map_finish_reason("some_unknown_value") == "stop"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue