File size: 1,537 Bytes
f95a1f1
c1300fe
622d220
 
 
f80f41e
 
c1300fe
622d220
c1300fe
 
622d220
f80f41e
 
622d220
f80f41e
 
 
 
622d220
 
 
c1300fe
622d220
f80f41e
 
c1300fe
622d220
c1300fe
 
622d220
f80f41e
622d220
f80f41e
 
622d220
c1300fe
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from classes.base_models import ChatMessage


class TestMain:
    def test_convert_messages(self):
        from helpers.message_helper import convert_messages
        from champ.prompts import DEFAULT_SYSTEM_PROMPT_V3

        messages = [
            ChatMessage(role="user", content="Hello"),
            ChatMessage(role="assistant", content="Hi there!"),
        ]
        lang = "en"
        converted = convert_messages(messages, lang)
        assert converted == [
            {
                "role": "system",
                "content": DEFAULT_SYSTEM_PROMPT_V3.format(language="English"),
            },
            {"role": "user", "content": "Hello"},
            {"role": "assistant", "content": "Hi there!"},
        ]

    def test_convert_messages_langchain(self):
        from helpers.message_helper import convert_messages_langchain
        from langchain_core.messages import HumanMessage, AIMessage

        messages = [
            ChatMessage(role="user", content="Hello"),
            ChatMessage(role="assistant", content="Hi there!"),
        ]
        converted = convert_messages_langchain(messages)
        # Check types and content only
        expected_types = [HumanMessage, AIMessage]
        expected_contents = ["Hello", "Hi there!"]

        for msg, expected_type, expected_content in zip(
            converted, expected_types, expected_contents
        ):
            assert isinstance(msg, expected_type)
            assert msg.content == expected_content