mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(bedrock): preserve assistant cache point boundaries
This commit is contained in:
parent
9202ac133a
commit
2ca368d27d
3 changed files with 5800 additions and 5759 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1719,7 +1719,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
anthropic_system_message_content["cache_control"] = system_message_block["cache_control"]
|
||||
anthropic_system_message_list.append(anthropic_system_message_content)
|
||||
elif isinstance(message["content"], list):
|
||||
content_start: int = len(anthropic_system_message_list)
|
||||
content_start: int = len(anthropic_system_message_list) # pyright: ignore[reportGeneralTypeIssues] # reset per system message
|
||||
for _content in message["content"]:
|
||||
# Skip empty text blocks - Anthropic API raises errors for empty text
|
||||
text_value = _content.get("text")
|
||||
|
|
|
|||
|
|
@ -185,6 +185,33 @@ async def test_bedrock_assistant_list_preserves_message_cache_control(block_cach
|
|||
assert "toolUse" in blocks[-2]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bedrock_assistant_message_cache_point_stays_before_following_assistant_text():
|
||||
messages: Final = [
|
||||
{"role": "user", "content": "hi"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": [{"type": "text", "text": "cached prefix"}],
|
||||
"cache_control": {"type": "ephemeral"},
|
||||
},
|
||||
{"role": "assistant", "content": [{"type": "text", "text": "uncached suffix"}]},
|
||||
]
|
||||
model: Final = "us.anthropic.claude-sonnet-4-5-20250929-v1:0"
|
||||
expected: Final = [
|
||||
{"text": "cached prefix"},
|
||||
{"cachePoint": {"type": "default"}},
|
||||
{"text": "uncached suffix"},
|
||||
]
|
||||
|
||||
sync_result: Final = _bedrock_converse_messages_pt(messages=messages, model=model, llm_provider="bedrock")
|
||||
async_result: Final = await BedrockConverseMessagesProcessor._bedrock_converse_messages_pt_async(
|
||||
messages=messages, model=model, llm_provider="bedrock"
|
||||
)
|
||||
|
||||
assert sync_result[-1]["content"] == expected
|
||||
assert async_result[-1]["content"] == expected
|
||||
|
||||
|
||||
def _get_gemini_function_response_inline_data_parts(result):
|
||||
assert isinstance(result, list), "expected Gemini parts list"
|
||||
assert len(result) == 1, "multimodal function responses should stay in one part"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue