From 3cb920057790a0ccd3d33c95786bd4967ac32816 Mon Sep 17 00:00:00 2001 From: ItsRoy69 Date: Tue, 14 Apr 2026 07:43:23 +0530 Subject: [PATCH] fix: simplify delta type checks in AnthropicStreamWrapper and update related tests --- .../adapters/streaming_iterator.py | 9 +-------- .../test_anthropic_streaming_iterator.py | 18 +++--------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py index 8f08867d260..bdc6f656fe9 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -438,15 +438,8 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): if processed_chunk.get("type") != "content_block_delta": return False delta = processed_chunk.get("delta", {}) - delta_type = delta.get("type", "") - if delta_type == "input_json_delta": + if delta.get("type") == "input_json_delta": return bool(delta.get("partial_json")) - elif delta_type == "text_delta": - return bool(delta.get("text")) - elif delta_type == "thinking_delta": - return bool(delta.get("thinking")) - elif delta_type == "signature_delta": - return bool(delta.get("signature")) return False def _increment_content_block_index(self): diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_streaming_iterator.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_streaming_iterator.py index 930bfca92de..ad7bc7043bd 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_streaming_iterator.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_streaming_iterator.py @@ -308,7 +308,7 @@ def test_has_meaningful_delta(): is False ) - # text_delta with content -> meaningful + # text_delta is not emitted during block transitions assert ( wrapper._has_meaningful_delta( { @@ -317,18 +317,6 @@ def test_has_meaningful_delta(): "delta": {"type": "text_delta", "text": "hello"}, } ) - is True - ) - - # text_delta with empty string -> not meaningful - assert ( - wrapper._has_meaningful_delta( - { - "type": "content_block_delta", - "index": 0, - "delta": {"type": "text_delta", "text": ""}, - } - ) is False ) @@ -340,7 +328,7 @@ def test_has_meaningful_delta(): is False ) - # thinking_delta with content -> meaningful + # thinking_delta is not emitted during block transitions assert ( wrapper._has_meaningful_delta( { @@ -349,7 +337,7 @@ def test_has_meaningful_delta(): "delta": {"type": "thinking_delta", "thinking": "Let me think..."}, } ) - is True + is False )