Skip to content

Commit 3d16da3

Browse files
committed
Add more tests for message formatting
1 parent a575573 commit 3d16da3

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

coverage-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

synalinks/src/modules/core/generator_test.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AnswerWithRationale(DataModel):
3131
)
3232
self.assertTrue(len(msgs) == 1)
3333

34-
def test_format_message(self):
34+
def test_format_message_with_instructions(self):
3535
class Query(DataModel):
3636
query: str
3737

@@ -49,6 +49,60 @@ class AnswerWithRationale(DataModel):
4949
Query(query="What is the french city of aerospace and robotics?")
5050
)
5151
self.assertTrue(len(msgs) == 2)
52+
53+
def test_format_message_with_examples(self):
54+
class Query(DataModel):
55+
query: str
56+
57+
class AnswerWithRationale(DataModel):
58+
rationale: str
59+
answer: str
60+
61+
language_model = LanguageModel(model="ollama_chat/deepseek-r1")
62+
63+
msgs = Generator(
64+
data_model=AnswerWithRationale,
65+
language_model=language_model,
66+
examples=\
67+
[
68+
(
69+
{"query": "What is the capital of France?"},
70+
{"rationale": "The capital of France is well known", "answer": "Paris"},
71+
)
72+
],
73+
).format_messages(
74+
Query(query="What is the french city of aerospace and robotics?")
75+
)
76+
self.assertTrue(len(msgs) == 2)
77+
78+
def test_format_message_with_examples_and_instructions(self):
79+
class Query(DataModel):
80+
query: str
81+
82+
class AnswerWithRationale(DataModel):
83+
rationale: str
84+
answer: str
85+
86+
language_model = LanguageModel(model="ollama_chat/deepseek-r1")
87+
88+
msgs = Generator(
89+
data_model=AnswerWithRationale,
90+
language_model=language_model,
91+
examples=\
92+
[
93+
(
94+
{"query": "What is the capital of France?"},
95+
{"rationale": "The capital of France is well known", "answer": "Paris"},
96+
)
97+
],
98+
instructions=\
99+
[
100+
"You are an helpfull assistant",
101+
],
102+
).format_messages(
103+
Query(query="What is the french city of aerospace and robotics?")
104+
)
105+
self.assertTrue(len(msgs) == 2)
52106

53107
@patch("litellm.completion")
54108
async def test_basic_functional_setup(self, mock_completion):

0 commit comments

Comments
 (0)