mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-01 02:02:20 +00:00
fix: address two low-severity context_management edge cases
- streaming_iterator: keep `sent_content_block_finish` in sync with the compaction block's emitted start/delta/stop lifecycle and reset it when the next text block's start is queued. - bedrock _map_context_management_param: match dispatcher `_normalize_spec` behavior — only run the OpenAI→Anthropic mapper on list inputs; pass dict inputs through unchanged so already-Anthropic-format values aren't silently dropped. Co-authored-by: Yassin Kortam <yassin@berri.ai>
This commit is contained in:
parent
78fa1fb1e1
commit
2cc4ef2a97
2 changed files with 25 additions and 3 deletions
|
|
@ -287,10 +287,17 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
|
|||
):
|
||||
self.sent_compaction_block = True
|
||||
self._queue_compaction_block_events()
|
||||
# The compaction block emitted a complete start/delta/stop
|
||||
# lifecycle. Reflect that in the state machine so any
|
||||
# downstream check sees a consistent view; the flag is
|
||||
# reset to ``False`` when the next (text) block's
|
||||
# ``content_block_start`` is emitted below.
|
||||
self.sent_content_block_finish = True
|
||||
return self.chunk_queue.popleft()
|
||||
|
||||
if self.sent_content_block_start is False:
|
||||
self.sent_content_block_start = True
|
||||
self.sent_content_block_finish = False
|
||||
self.chunk_queue.append(
|
||||
{
|
||||
"type": "content_block_start",
|
||||
|
|
@ -502,10 +509,17 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
|
|||
):
|
||||
self.sent_compaction_block = True
|
||||
self._queue_compaction_block_events()
|
||||
# The compaction block emitted a complete start/delta/stop
|
||||
# lifecycle. Reflect that in the state machine so any
|
||||
# downstream check sees a consistent view; the flag is
|
||||
# reset to ``False`` when the next (text) block's
|
||||
# ``content_block_start`` is emitted below.
|
||||
self.sent_content_block_finish = True
|
||||
return self.chunk_queue.popleft()
|
||||
|
||||
if self.sent_content_block_start is False:
|
||||
self.sent_content_block_start = True
|
||||
self.sent_content_block_finish = False
|
||||
self.chunk_queue.append(
|
||||
{
|
||||
"type": "content_block_start",
|
||||
|
|
|
|||
|
|
@ -979,9 +979,17 @@ class AmazonConverseConfig(BaseConfig):
|
|||
def _map_context_management_param(
|
||||
self, value: Union[dict, list], optional_params: dict
|
||||
) -> None:
|
||||
mapped = AnthropicConfig.map_openai_context_management_to_anthropic(
|
||||
cast(Union[dict, list], value)
|
||||
)
|
||||
# Match the dispatcher's ``_normalize_spec`` behavior: only run the
|
||||
# OpenAI→Anthropic mapper for list inputs. Dict inputs are already in
|
||||
# Anthropic-native shape (``{"edits": [...]}``) and should pass
|
||||
# through unchanged so an Anthropic-format ``context_management``
|
||||
# value isn't silently dropped when the mapper can't classify it.
|
||||
if isinstance(value, list):
|
||||
mapped = AnthropicConfig.map_openai_context_management_to_anthropic(
|
||||
cast(Union[dict, list], value)
|
||||
)
|
||||
else:
|
||||
mapped = value
|
||||
# Skip when the mapper returned None for malformed input — leaving the
|
||||
# key out is safer than passing `context_management: null` downstream,
|
||||
# which Bedrock would reject and which can confuse intermediate checks
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue