Skip to content

Commit d74b49a

Browse files
committed
Fix test_message_text_property to work with both LangChain 0.3.x and 1.x
In LangChain 0.3.x, .text is a method (callable), while in 1.x it's a property. Update the test to handle both cases by checking if .text is callable and calling it if necessary. Verified: - Test passes with LangChain 0.3.80 - Test passes with LangChain 1.1.0
1 parent 7a15cb2 commit d74b49a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

libs/oci/tests/integration_tests/chat_models/test_langchain_compatibility.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,18 @@ def test_ai_message_type(chat_model):
334334

335335
@pytest.mark.requires("oci")
336336
def test_message_text_property(chat_model):
337-
"""Test that .text property works (LangChain 1.x change from .text())."""
337+
"""Test that .text works in both LangChain 0.3.x (method) and 1.x (property)."""
338338
response = chat_model.invoke([HumanMessage(content="Say hello")])
339339

340-
# LangChain 1.x: .text is a property, not a method
341340
# Both .content and .text should work
342341
assert response.content is not None
343-
# .text property should exist and return same as .content
342+
343+
# Handle both LangChain versions:
344+
# 0.3.x: .text is a method (callable)
345+
# 1.x: .text is a property
344346
if hasattr(response, "text"):
345-
assert response.text == response.content
347+
text_value = response.text() if callable(response.text) else response.text
348+
assert text_value == response.content
346349

347350

348351
@pytest.mark.requires("oci")

0 commit comments

Comments
 (0)