standard-tests: double messages test (#29237)

This commit is contained in:
Erick Friis 2025-01-15 15:14:29 -08:00 committed by GitHub
parent 1051fa5729
commit 5eb4dc5e06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -557,6 +557,44 @@ class ChatModelIntegrationTests(ChatModelTests):
assert isinstance(result.content, str)
assert len(result.content) > 0
def test_double_messages_conversation(self, model: BaseChatModel) -> None:
"""
Test to verify that the model can handle double-message conversations.
This should pass for all integrations. Tests the model's ability to process
a sequence of double-system, double-human, and double-ai messages as context
for generating the next response.
.. dropdown:: Troubleshooting
First, debug
:meth:`~langchain_tests.integration_tests.chat_models.ChatModelIntegrationTests.test_invoke`
because this test also uses `model.invoke()`.
Second, debug
:meth:`~langchain_tests.integration_tests.chat_models.ChatModelIntegrationTests.test_conversation`
because this test is the "basic case" without double messages.
If that test passes those but not this one, you should verify that:
1. Your model API can handle double messages, or the integration should
merge messages before sending them to the API.
2. The response is a valid :class:`~langchain_core.messages.AIMessage`
"""
messages = [
SystemMessage("hello"),
SystemMessage("hello"),
HumanMessage("hello"),
HumanMessage("hello"),
AIMessage("hello"),
AIMessage("hello"),
HumanMessage("how are you"),
]
result = model.invoke(messages)
assert result is not None
assert isinstance(result, AIMessage)
assert isinstance(result.content, str)
assert len(result.content) > 0
def test_usage_metadata(self, model: BaseChatModel) -> None:
"""Test to verify that the model returns correct usage metadata.