mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
test(llm_translation): expect an empty choices list to convert instead of raising
This commit is contained in:
parent
35def27e7b
commit
17ca562b6a
1 changed files with 10 additions and 13 deletions
|
|
@ -1623,15 +1623,11 @@ class TestMissingChoicesGuard:
|
|||
|
||||
assert "no 'choices'" in exc_info.value.message
|
||||
|
||||
def test_convert_to_model_response_object_empty_choices_raises_api_error(self):
|
||||
"""Empty choices list raises APIError, same as missing/null choices.
|
||||
def test_convert_to_model_response_object_empty_choices_returns_empty_list(self):
|
||||
"""An empty choices list is a real provider answer, so it converts to choices=[] instead of raising.
|
||||
|
||||
Provider-specific repair (e.g. github_copilot synthesizing choices for
|
||||
Anthropic-native responses) happens before this guard, in the provider
|
||||
config; the core utility keeps treating empty choices as an error.
|
||||
See: https://github.com/BerriAI/litellm/issues/40276
|
||||
"""
|
||||
from litellm.exceptions import APIError
|
||||
|
||||
response_object = {
|
||||
"id": "msg_123",
|
||||
"model": "some-model",
|
||||
|
|
@ -1639,13 +1635,14 @@ class TestMissingChoicesGuard:
|
|||
"usage": {"prompt_tokens": 10, "completion_tokens": 1, "total_tokens": 11},
|
||||
}
|
||||
|
||||
with pytest.raises(APIError) as exc_info:
|
||||
convert_to_model_response_object(
|
||||
response_object=response_object,
|
||||
model_response_object=ModelResponse(),
|
||||
)
|
||||
result = convert_to_model_response_object(
|
||||
response_object=response_object,
|
||||
model_response_object=ModelResponse(),
|
||||
)
|
||||
|
||||
assert "no 'choices'" in exc_info.value.message
|
||||
assert isinstance(result, ModelResponse)
|
||||
assert result.choices == []
|
||||
assert result.usage.prompt_tokens == 10
|
||||
|
||||
def test_convert_to_model_response_object_null_choices_raises_api_error(self):
|
||||
"""choices=None raises APIError."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue