mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
fix(ollama): pop unsupported 'strict' argument in ChatOllama (#34114)
This commit is contained in:
@@ -774,6 +774,11 @@ class ChatOllama(BaseChatModel):
|
||||
**kwargs,
|
||||
}
|
||||
|
||||
# Filter out 'strict' argument if present, as it is not supported by Ollama
|
||||
# but may be passed by upstream libraries (e.g. LangChain ProviderStrategy)
|
||||
if "strict" in params:
|
||||
params.pop("strict")
|
||||
|
||||
if tools := kwargs.get("tools"):
|
||||
params["tools"] = tools
|
||||
|
||||
|
||||
@@ -410,3 +410,29 @@ def test_explicit_options_dict_preserved() -> None:
|
||||
|
||||
# Explicit options should be preserved as-is
|
||||
assert options == {"temperature": 0.5, "custom_param": None}
|
||||
|
||||
|
||||
def test_chat_ollama_ignores_strict_arg() -> None:
|
||||
"""Test that ChatOllama ignores the 'strict' argument."""
|
||||
response = [
|
||||
{
|
||||
"model": "test-model",
|
||||
"created_at": "2025-01-01T00:00:00.000000000Z",
|
||||
"done": True,
|
||||
"done_reason": "stop",
|
||||
"message": {"role": "assistant", "content": "Hello!"},
|
||||
}
|
||||
]
|
||||
|
||||
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 = response
|
||||
|
||||
llm = ChatOllama(model="test-model")
|
||||
# Invoke with strict=True
|
||||
llm.invoke([HumanMessage("Hello")], strict=True)
|
||||
|
||||
# Check that 'strict' was NOT passed to the client
|
||||
call_kwargs = mock_client.chat.call_args[1]
|
||||
assert "strict" not in call_kwargs
|
||||
|
||||
Reference in New Issue
Block a user