mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
test(ollama): Add unit test for ChatOllama reasoning parameter (#34095)
This commit is contained in:
committed by
GitHub
parent
0e5e33ba03
commit
2a82fbc0ff
@@ -412,6 +412,43 @@ def test_explicit_options_dict_preserved() -> None:
|
||||
assert options == {"temperature": 0.5, "custom_param": None}
|
||||
|
||||
|
||||
def test_reasoning_param_passed_to_client() -> None:
|
||||
"""Test that the reasoning parameter is correctly passed to the Ollama client."""
|
||||
with patch("langchain_ollama.chat_models.Client") as mock_client_class:
|
||||
mock_client = MagicMock()
|
||||
mock_client_class.return_value = mock_client
|
||||
mock_client.chat.return_value = [
|
||||
{
|
||||
"model": "deepseek-r1",
|
||||
"created_at": "2025-01-01T00:00:00.000000000Z",
|
||||
"message": {"role": "assistant", "content": "I am thinking..."},
|
||||
"done": True,
|
||||
"done_reason": "stop",
|
||||
}
|
||||
]
|
||||
|
||||
# Case 1: reasoning=True in init
|
||||
llm = ChatOllama(model="deepseek-r1", reasoning=True)
|
||||
llm.invoke([HumanMessage("Hello")])
|
||||
|
||||
call_kwargs = mock_client.chat.call_args[1]
|
||||
assert call_kwargs["think"] is True
|
||||
|
||||
# Case 2: reasoning=False in init
|
||||
llm = ChatOllama(model="deepseek-r1", reasoning=False)
|
||||
llm.invoke([HumanMessage("Hello")])
|
||||
|
||||
call_kwargs = mock_client.chat.call_args[1]
|
||||
assert call_kwargs["think"] is False
|
||||
|
||||
# Case 3: reasoning passed in invoke
|
||||
llm = ChatOllama(model="deepseek-r1")
|
||||
llm.invoke([HumanMessage("Hello")], reasoning=True)
|
||||
|
||||
call_kwargs = mock_client.chat.call_args[1]
|
||||
assert call_kwargs["think"] is True
|
||||
|
||||
|
||||
def test_chat_ollama_ignores_strict_arg() -> None:
|
||||
"""Test that ChatOllama ignores the 'strict' argument."""
|
||||
response = [
|
||||
|
||||
Reference in New Issue
Block a user