@@ -244,6 +244,9 @@ class MySignature(dspy.Signature):
244
244
# 1 system message, 2 few shot examples (1 user and assistant message for each example), 1 user message
245
245
assert len (messages ) == 6
246
246
247
+ assert "[[ ## completed ## ]]\n " in messages [2 ]["content" ]
248
+ assert "[[ ## completed ## ]]\n " in messages [4 ]["content" ]
249
+
247
250
assert {"type" : "image_url" , "image_url" : {"url" : "https://example.com/image1.jpg" }} in messages [1 ]["content" ]
248
251
assert {"type" : "image_url" , "image_url" : {"url" : "https://example.com/image2.jpg" }} in messages [3 ]["content" ]
249
252
assert {"type" : "image_url" , "image_url" : {"url" : "https://example.com/image3.jpg" }} in messages [5 ]["content" ]
@@ -350,3 +353,26 @@ def get_population(country: str, year: int) -> str:
350
353
# Tool arguments format should be included in the user message
351
354
assert "{'city': {'type': 'string'}}" in messages [1 ]["content" ]
352
355
assert "{'country': {'type': 'string'}, 'year': {'type': 'integer'}}" in messages [1 ]["content" ]
356
+
357
+
358
+ def test_chat_adapter_formats_conversation_history ():
359
+ class MySignature (dspy .Signature ):
360
+ question : str = dspy .InputField ()
361
+ history : dspy .History = dspy .InputField ()
362
+ answer : str = dspy .OutputField ()
363
+
364
+ history = dspy .History (
365
+ messages = [
366
+ {"question" : "What is the capital of France?" , "answer" : "Paris" },
367
+ {"question" : "What is the capital of Germany?" , "answer" : "Berlin" },
368
+ ]
369
+ )
370
+
371
+ adapter = dspy .ChatAdapter ()
372
+ messages = adapter .format (MySignature , [], {"question" : "What is the capital of France?" , "history" : history })
373
+
374
+ assert len (messages ) == 6
375
+ assert messages [1 ]["content" ] == "[[ ## question ## ]]\n What is the capital of France?"
376
+ assert messages [2 ]["content" ] == "[[ ## answer ## ]]\n Paris\n \n [[ ## completed ## ]]\n "
377
+ assert messages [3 ]["content" ] == "[[ ## question ## ]]\n What is the capital of Germany?"
378
+ assert messages [4 ]["content" ] == "[[ ## answer ## ]]\n Berlin\n \n [[ ## completed ## ]]\n "
0 commit comments