mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
test(prompt-caching): add coverage for message-level cache_control on string content
Add test verifying get_prompt_caching_ttl extracts TTL from cache_control when it appears as a sibling to a string content field rather than inside a content-block list.
This commit is contained in:
parent
3db1263070
commit
2c4db79e38
1 changed files with 12 additions and 0 deletions
|
|
@ -119,6 +119,18 @@ def test_prompt_caching_affinity_ttl_matches_cache_control(ttl: str | None, expe
|
|||
assert PromptCachingCache.get_prompt_caching_ttl(messages) == expected_affinity_ttl
|
||||
|
||||
|
||||
def test_message_level_cache_control_on_string_content_sets_affinity_ttl():
|
||||
"""cache_control can sit as a sibling of a string `content` field rather than inside a
|
||||
content-block list, e.g. {"role": "system", "content": "...", "cache_control": {...}}.
|
||||
get_prompt_caching_ttl must still pick it up."""
|
||||
messages = cast(
|
||||
List[AllMessageValues],
|
||||
[{"role": "system", "content": "cached", "cache_control": {"type": "ephemeral", "ttl": "1h"}}],
|
||||
)
|
||||
|
||||
assert PromptCachingCache.get_prompt_caching_ttl(messages) == 3600
|
||||
|
||||
|
||||
def test_mixed_cache_ttls_use_the_shortest_affinity_ttl():
|
||||
messages = cast(
|
||||
List[AllMessageValues],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue