Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test_is_chunk_non_empty_with_annotations

Ishaan Jaff792a2d61150b
diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py
index 56e64d18595..a11e5af12b2 100644
--- a/litellm/litellm_core_utils/streaming_handler.py
+++ b/litellm/litellm_core_utils/streaming_handler.py
@@ -799,6 +799,10 @@ class CustomStreamWrapper:
"provider_specific_fields" in response_obj
and response_obj["provider_specific_fields"] is not None
)
+ or (
+ "annotations" in model_response.choices[0].delta
+ and model_response.choices[0].delta.annotations is not None
+ )
):
return True
else:
@@ -939,7 +943,6 @@ class CustomStreamWrapper:
and model_response.choices[0].delta.audio is not None
):
return model_response
-
else:
if hasattr(model_response, "usage"):
self.chunks.append(model_response)
diff --git a/tests/litellm/litellm_core_utils/test_streaming_handler.py b/tests/litellm/litellm_core_utils/test_streaming_handler.py
index 75c4fc1035c..988d5336704 100644
--- a/tests/litellm/litellm_core_utils/test_streaming_handler.py
+++ b/tests/litellm/litellm_core_utils/test_streaming_handler.py
@@ -136,6 +136,40 @@ def test_is_chunk_non_empty(initialized_custom_stream_wrapper: CustomStreamWrapp
)
+def test_is_chunk_non_empty_with_annotations(
+ initialized_custom_stream_wrapper: CustomStreamWrapper,
+):
+ """Unit test if non-empty when annotations are present"""
+ chunk = {
+ "id": "e89b6501-8ac2-464c-9550-7cd3daf94350",
+ "object": "chat.completion.chunk",
+ "created": 1741037890,
+ "model": "deepseek-reasoner",
+ "system_fingerprint": "fp_5417b77867_prod0225",
+ "choices": [
+ {
+ "index": 0,
+ "delta": {
+ "content": None,
+ "annotations": [
+ {"type": "url_citation", "url": "https://www.google.com"}
+ ],
+ },
+ "logprobs": None,
+ "finish_reason": None,
+ }
+ ],
+ }
+ assert (
+ initialized_custom_stream_wrapper.is_chunk_non_empty(
+ completion_obj=MagicMock(),
+ model_response=ModelResponseStream(**chunk),
+ response_obj=MagicMock(),
+ )
+ is True
+ )
+
+
def test_optional_combine_thinking_block_in_choices(
initialized_custom_stream_wrapper: CustomStreamWrapper,
):