mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
test passing cache controls through anthropic msg
This commit is contained in:
parent
209c91ac03
commit
68e24fbf14
1 changed files with 45 additions and 0 deletions
|
|
@ -260,3 +260,48 @@ def test_anthropic_messages_tool_call():
|
|||
translated_messages[-1]["content"][0]["tool_use_id"]
|
||||
== "bc8cb4b6-88c4-4138-8993-3a9d9cd51656"
|
||||
)
|
||||
|
||||
|
||||
def test_anthropic_cache_controls_pt():
|
||||
messages = [
|
||||
# marked for caching with the cache_control parameter, so that this checkpoint can read from the previous cache.
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "What are the key terms and conditions in this agreement?",
|
||||
"cache_control": {"type": "ephemeral"},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Certainly! the key terms and conditions are the following: the contract is 1 year long for $10/mo",
|
||||
},
|
||||
# The final turn is marked with cache-control, for continuing in followups.
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "What are the key terms and conditions in this agreement?",
|
||||
"cache_control": {"type": "ephemeral"},
|
||||
}
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
translated_messages = anthropic_messages_pt(
|
||||
messages, model="claude-3-5-sonnet-20240620", llm_provider="anthropic"
|
||||
)
|
||||
|
||||
for i, msg in enumerate(translated_messages):
|
||||
if i == 0:
|
||||
assert msg["content"][0]["cache_control"] == {"type": "ephemeral"}
|
||||
elif i == 1:
|
||||
assert "cache_controls" not in msg["content"][0]
|
||||
elif i == 2:
|
||||
assert msg["content"][0]["cache_control"] == {"type": "ephemeral"}
|
||||
|
||||
print("translated_messages: ", translated_messages)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue