mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-26 01:12:21 +00:00
test: add regression test for empty-choices guard in raise_on_model_repetition
Verifies that metadata-only chunks (choices=[]) from Vertex Gemini Flash with web_search_options do not crash raise_on_model_repetition with IndexError, and that _repeated_messages_count is correctly reset to 1 on those chunks.
This commit is contained in:
parent
a552da9ad2
commit
7260c3a727
1 changed files with 31 additions and 0 deletions
|
|
@ -1511,6 +1511,37 @@ def test_raise_on_model_repetition(
|
|||
wrapper.raise_on_model_repetition()
|
||||
|
||||
|
||||
def test_raise_on_model_repetition_empty_choices_no_crash(
|
||||
initialized_custom_stream_wrapper: CustomStreamWrapper,
|
||||
):
|
||||
"""
|
||||
Regression test: Vertex Gemini Flash with web_search_options emits
|
||||
metadata-only chunks with choices=[]. raise_on_model_repetition must
|
||||
not raise IndexError on those chunks, and must reset the repetition
|
||||
counter to 1 so subsequent real chunks are compared correctly.
|
||||
"""
|
||||
wrapper = initialized_custom_stream_wrapper
|
||||
|
||||
empty_chunk = ModelResponseStream(
|
||||
id="test",
|
||||
created=1741037890,
|
||||
model="test-model",
|
||||
choices=[], # metadata-only chunk — no choices
|
||||
)
|
||||
|
||||
# Two empty-choices chunks: should not crash and counter should stay at 1
|
||||
wrapper.chunks.append(empty_chunk)
|
||||
wrapper.chunks.append(empty_chunk)
|
||||
wrapper.raise_on_model_repetition() # must not raise IndexError
|
||||
assert wrapper._repeated_messages_count == 1
|
||||
|
||||
# Real content chunk after metadata chunks should still be compared correctly
|
||||
real_chunk = _make_chunk("hello world content")
|
||||
wrapper.chunks.append(real_chunk)
|
||||
wrapper.raise_on_model_repetition() # still must not raise
|
||||
assert wrapper._repeated_messages_count == 1
|
||||
|
||||
|
||||
def test_usage_chunk_after_finish_reason_updates_hidden_params(logging_obj):
|
||||
"""
|
||||
Test that provider-reported usage from a post-finish_reason chunk
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue