Skip to content

Commit 5eb4dc5

Browse files
author
Erick Friis
authored
standard-tests: double messages test (#29237)
1 parent 1051fa5 commit 5eb4dc5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

libs/standard-tests/langchain_tests/integration_tests/chat_models.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,44 @@ def test_conversation(self, model: BaseChatModel) -> None:
557557
assert isinstance(result.content, str)
558558
assert len(result.content) > 0
559559

560+
def test_double_messages_conversation(self, model: BaseChatModel) -> None:
561+
"""
562+
Test to verify that the model can handle double-message conversations.
563+
564+
This should pass for all integrations. Tests the model's ability to process
565+
a sequence of double-system, double-human, and double-ai messages as context
566+
for generating the next response.
567+
568+
.. dropdown:: Troubleshooting
569+
570+
First, debug
571+
:meth:`~langchain_tests.integration_tests.chat_models.ChatModelIntegrationTests.test_invoke`
572+
because this test also uses `model.invoke()`.
573+
574+
Second, debug
575+
:meth:`~langchain_tests.integration_tests.chat_models.ChatModelIntegrationTests.test_conversation`
576+
because this test is the "basic case" without double messages.
577+
578+
If that test passes those but not this one, you should verify that:
579+
1. Your model API can handle double messages, or the integration should
580+
merge messages before sending them to the API.
581+
2. The response is a valid :class:`~langchain_core.messages.AIMessage`
582+
"""
583+
messages = [
584+
SystemMessage("hello"),
585+
SystemMessage("hello"),
586+
HumanMessage("hello"),
587+
HumanMessage("hello"),
588+
AIMessage("hello"),
589+
AIMessage("hello"),
590+
HumanMessage("how are you"),
591+
]
592+
result = model.invoke(messages)
593+
assert result is not None
594+
assert isinstance(result, AIMessage)
595+
assert isinstance(result.content, str)
596+
assert len(result.content) > 0
597+
560598
def test_usage_metadata(self, model: BaseChatModel) -> None:
561599
"""Test to verify that the model returns correct usage metadata.
562600

0 commit comments

Comments
 (0)