fix: simplify delta type checks in AnthropicStreamWrapper and update related tests

This commit is contained in:
ItsRoy69 2026-04-14 07:43:23 +05:30
parent 5e8a7ec19d
commit 3cb9200577
2 changed files with 4 additions and 23 deletions

View file

@ -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):

View file

@ -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
)