The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test_append_system_prompt_messages
Ishaan Jaffer772be1778a6a
diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.pyindex 477fd1396f7..8065304fd64 100644--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py@@ -759,3 +759,62 @@ def test_get_final_response_obj_with_empty_response_obj_and_list_init():assert len(result) == 2assert result[0].name == "Object1"assert result[1].name == "Object2"+++def test_append_system_prompt_messages():+ """+ Test append_system_prompt_messages prepends system message from kwargs to messages list.+ """+ from litellm.litellm_core_utils.litellm_logging import StandardLoggingPayloadSetup++ # Test case 1: system in kwargs with existing messages+ kwargs = {"system": "You are a helpful assistant"}+ messages = [{"role": "user", "content": "Hello"}]+ result = StandardLoggingPayloadSetup.append_system_prompt_messages(+ kwargs=kwargs, messages=messages+ )+ assert len(result) == 2+ assert result[0] == {"role": "system", "content": "You are a helpful assistant"}+ assert result[1] == {"role": "user", "content": "Hello"}++ # Test case 2: system in kwargs with None messages+ kwargs = {"system": "You are a helpful assistant"}+ result = StandardLoggingPayloadSetup.append_system_prompt_messages(+ kwargs=kwargs, messages=None+ )+ assert len(result) == 1+ assert result[0] == {"role": "system", "content": "You are a helpful assistant"}++ # Test case 3: system in kwargs with empty messages list+ kwargs = {"system": "You are a helpful assistant"}+ result = StandardLoggingPayloadSetup.append_system_prompt_messages(+ kwargs=kwargs, messages=[]+ )+ assert len(result) == 1+ assert result[0] == {"role": "system", "content": "You are a helpful assistant"}++ # Test case 4: duplicate system message should not be added+ kwargs = {"system": "You are a helpful assistant"}+ messages = [+ {"role": "system", "content": "You are a helpful assistant"},+ {"role": "user", "content": "Hello"},+ ]+ result = StandardLoggingPayloadSetup.append_system_prompt_messages(+ kwargs=kwargs, messages=messages+ )+ assert len(result) == 2+ assert result[0] == {"role": "system", "content": "You are a helpful assistant"}++ # Test case 5: no system in kwargs returns messages unchanged+ kwargs = {}+ messages = [{"role": "user", "content": "Hello"}]+ result = StandardLoggingPayloadSetup.append_system_prompt_messages(+ kwargs=kwargs, messages=messages+ )+ assert result == messages++ # Test case 6: None kwargs returns messages unchanged+ result = StandardLoggingPayloadSetup.append_system_prompt_messages(+ kwargs=None, messages=messages+ )+ assert result == messages