mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(anthropic): skip content-less keepalive chunks in streaming bridge
A chunk with empty choices and no usage carries no content, billing, or finish reason, so translating it emitted a premature message_delta and broke Anthropic SSE ordering. Skip such keepalives in both the sync and async iterator loops; usage-only trailing chunks (choices=[] with usage) still flow through.
This commit is contained in:
parent
dc3a098f6a
commit
ac679561f5
1 changed files with 6 additions and 0 deletions
|
|
@ -388,6 +388,9 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
|
|||
if chunk == "None" or chunk is None:
|
||||
raise Exception
|
||||
|
||||
if not chunk.choices and getattr(chunk, "usage", None) is None:
|
||||
continue
|
||||
|
||||
should_start_new_block = self._should_start_new_content_block(chunk)
|
||||
if should_start_new_block:
|
||||
self._increment_content_block_index()
|
||||
|
|
@ -609,6 +612,9 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
|
|||
if chunk == "None" or chunk is None:
|
||||
raise Exception
|
||||
|
||||
if not chunk.choices and getattr(chunk, "usage", None) is None:
|
||||
continue
|
||||
|
||||
# Check if we need to start a new content block
|
||||
should_start_new_block = self._should_start_new_content_block(chunk)
|
||||
if should_start_new_block:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue