Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions libs/partners/ollama/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading