mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
test(streaming): exercise _simple_text_part empty sequence guards
This commit is contained in:
parent
f0fbcf7867
commit
3d6f54e431
1 changed files with 7 additions and 0 deletions
|
|
@ -902,6 +902,12 @@ def test_stream_chunk_builder_empty_choices_guard():
|
|||
Test that stream_chunk_builder does not crash with IndexError when
|
||||
streaming chunks contain empty choices lists (e.g. trailing usage chunks).
|
||||
"""
|
||||
from litellm.main import _simple_text_part
|
||||
|
||||
# Direct unit test exercising empty-sequence guards in _simple_text_part
|
||||
assert _simple_text_part([]) is None
|
||||
assert _simple_text_part([{"delta": {}}]) == ""
|
||||
|
||||
chunks = [
|
||||
{"id": "chat-test-1", "model": "gpt-4o", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Hello"}}]},
|
||||
{"id": "chat-test-1", "model": "gpt-4o", "choices": [{"index": 0, "delta": {"content": " world"}}]},
|
||||
|
|
@ -911,3 +917,4 @@ def test_stream_chunk_builder_empty_choices_guard():
|
|||
assert res is not None
|
||||
assert res["choices"][0]["message"]["content"] == "Hello world"
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue