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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix caching on main branch (#8858)
Krish Dholakia3de420956962
diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.pyindex a5bc08ef1b6..a1d29f3284d 100644--- a/litellm/litellm_core_utils/streaming_handler.py+++ b/litellm/litellm_core_utils/streaming_handler.py@@ -714,7 +714,7 @@ class CustomStreamWrapper:def is_delta_empty(self, delta: Delta) -> bool:is_empty = True- if delta.content is not None:+ if delta.content:is_empty = Falseelif delta.tool_calls is not None:is_empty = False@@ -879,6 +879,9 @@ class CustomStreamWrapper:_is_delta_empty = self.is_delta_empty(delta=model_response.choices[0].delta)if _is_delta_empty:+ model_response.choices[0].delta = Delta(+ content=None+ ) # ensure empty delta chunk returned# get any function call argumentsmodel_response.choices[0].finish_reason = map_finish_reason(finish_reason=self.received_finish_reasondiff --git a/tests/local_testing/test_streaming.py b/tests/local_testing/test_streaming.pyindex 5301ba1efc3..f438fdc5c04 100644--- a/tests/local_testing/test_streaming.py+++ b/tests/local_testing/test_streaming.py@@ -4095,3 +4095,26 @@ def test_reasoning_content_completion(model):assert reasoning_content_existsexcept litellm.Timeout:pytest.skip("Model is timing out")+++def test_is_delta_empty():+ from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper+ from litellm.types.utils import Delta++ custom_stream_wrapper = CustomStreamWrapper(+ completion_stream=None,+ model=None,+ logging_obj=MagicMock(),+ custom_llm_provider=None,+ stream_options=None,+ )++ assert custom_stream_wrapper.is_delta_empty(+ delta=Delta(+ content="",+ role="assistant",+ function_call=None,+ tool_calls=None,+ audio=None,+ )+ )