Skip to content

Commit 772be17

Browse files
committed
test_append_system_prompt_messages
1 parent 01fd4d7 commit 772be17

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/test_litellm/litellm_core_utils/test_litellm_logging.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,62 @@ def __init__(self):
759759
assert len(result) == 2
760760
assert result[0].name == "Object1"
761761
assert result[1].name == "Object2"
762+
763+
764+
def test_append_system_prompt_messages():
765+
"""
766+
Test append_system_prompt_messages prepends system message from kwargs to messages list.
767+
"""
768+
from litellm.litellm_core_utils.litellm_logging import StandardLoggingPayloadSetup
769+
770+
# Test case 1: system in kwargs with existing messages
771+
kwargs = {"system": "You are a helpful assistant"}
772+
messages = [{"role": "user", "content": "Hello"}]
773+
result = StandardLoggingPayloadSetup.append_system_prompt_messages(
774+
kwargs=kwargs, messages=messages
775+
)
776+
assert len(result) == 2
777+
assert result[0] == {"role": "system", "content": "You are a helpful assistant"}
778+
assert result[1] == {"role": "user", "content": "Hello"}
779+
780+
# Test case 2: system in kwargs with None messages
781+
kwargs = {"system": "You are a helpful assistant"}
782+
result = StandardLoggingPayloadSetup.append_system_prompt_messages(
783+
kwargs=kwargs, messages=None
784+
)
785+
assert len(result) == 1
786+
assert result[0] == {"role": "system", "content": "You are a helpful assistant"}
787+
788+
# Test case 3: system in kwargs with empty messages list
789+
kwargs = {"system": "You are a helpful assistant"}
790+
result = StandardLoggingPayloadSetup.append_system_prompt_messages(
791+
kwargs=kwargs, messages=[]
792+
)
793+
assert len(result) == 1
794+
assert result[0] == {"role": "system", "content": "You are a helpful assistant"}
795+
796+
# Test case 4: duplicate system message should not be added
797+
kwargs = {"system": "You are a helpful assistant"}
798+
messages = [
799+
{"role": "system", "content": "You are a helpful assistant"},
800+
{"role": "user", "content": "Hello"},
801+
]
802+
result = StandardLoggingPayloadSetup.append_system_prompt_messages(
803+
kwargs=kwargs, messages=messages
804+
)
805+
assert len(result) == 2
806+
assert result[0] == {"role": "system", "content": "You are a helpful assistant"}
807+
808+
# Test case 5: no system in kwargs returns messages unchanged
809+
kwargs = {}
810+
messages = [{"role": "user", "content": "Hello"}]
811+
result = StandardLoggingPayloadSetup.append_system_prompt_messages(
812+
kwargs=kwargs, messages=messages
813+
)
814+
assert result == messages
815+
816+
# Test case 6: None kwargs returns messages unchanged
817+
result = StandardLoggingPayloadSetup.append_system_prompt_messages(
818+
kwargs=None, messages=messages
819+
)
820+
assert result == messages

0 commit comments

Comments
 (0)