From 7e46c519d9927bc4f73db7629b63ed44469bf782 Mon Sep 17 00:00:00 2001 From: Safwan Erooth Date: Fri, 24 Jul 2026 12:24:43 +0400 Subject: [PATCH] test(trim_messages): cover list-type system message content --- tests/test_litellm/test_utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index edc0cfed63e..d358ea5040c 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -31,6 +31,7 @@ from litellm.utils import ( get_prompt_cache_min_tokens, is_cached_message, is_prompt_caching_valid_prompt, + trim_messages, ) # Adds the parent directory to the system path @@ -50,6 +51,26 @@ def test_usage_openai_cache_write_tokens_populates_both_names(): assert usage.prompt_tokens_details.cache_creation_tokens == 800 +def test_trim_messages_system_message_list_content(): + messages = [ + { + "role": "system", + "content": [ + {"type": "text", "text": "You are a helpful assistant."}, + {"type": "text", "text": "Always answer in French."}, + ], + }, + {"role": "user", "content": "Hello there, how are you?"}, + ] + + trimmed_messages = trim_messages(messages, model="gpt-4", max_tokens=5) + + assert ( + trimmed_messages[0]["content"] + == "You are a helpful assistant.Always answer in French." + ) + + def test_usage_anthropic_cache_creation_maps_to_cache_write_tokens(): """Anthropic/Bedrock report the top-level cache_creation_input_tokens field. It must be normalized onto the OpenAI cache_write_tokens name as well as the