ollama: thinking, tool streaming, docs, tests (#31772)

* New `reasoning` (bool) param to support toggling [Ollama
thinking](https://ollama.com/blog/thinking) (#31573, #31700). If
`reasoning=True`, Ollama's `thinking` content will be placed in the
model responses' `additional_kwargs.reasoning_content`.
  * Supported by:
    * ChatOllama (class level, invocation level TODO)
    * OllamaLLM (TODO)
* Added tests to ensure streaming tool calls is successful (#29129)
* Refactored tests that relied on `extract_reasoning()`
* Myriad docs additions and consistency/typo fixes
* Improved type safety in some spots

Closes #29129
Addresses #31573 and #31700
Supersedes #31701
This commit is contained in:
Mason Daugherty
2025-07-07 13:56:41 -04:00
committed by GitHub
parent 0eb10f31c1
commit e686a70ee0
14 changed files with 630 additions and 213 deletions

View File

@@ -23,7 +23,7 @@ class TestChatOllama(ChatModelUnitTests):
@property
def chat_model_params(self) -> dict:
return {"model": "llama3-groq-tool-use"}
return {"model": MODEL_NAME}
def test__parse_arguments_from_tool_call() -> None:
@@ -51,7 +51,6 @@ def test_arbitrary_roles_accepted_in_chatmessages(
monkeypatch.setattr(Client, "stream", _mock_httpx_client_stream)
llm = ChatOllama(
base_url="http://whocares:11434",
model=MODEL_NAME,
verbose=True,
format=None,

View File

@@ -10,7 +10,7 @@ MODEL_NAME = "llama3.1"
def test_initialization() -> None:
"""Test embedding model initialization."""
OllamaEmbeddings(model="llama3", keep_alive=1)
OllamaEmbeddings(model=MODEL_NAME, keep_alive=1)
@patch("langchain_ollama.embeddings.validate_model")

View File

@@ -10,25 +10,25 @@ MODEL_NAME = "llama3.1"
def test_initialization() -> None:
"""Test integration initialization."""
OllamaLLM(model="llama3")
OllamaLLM(model=MODEL_NAME)
def test_model_params() -> None:
# Test standard tracing params
llm = OllamaLLM(model="llama3")
llm = OllamaLLM(model=MODEL_NAME)
ls_params = llm._get_ls_params()
assert ls_params == {
"ls_provider": "ollama",
"ls_model_type": "llm",
"ls_model_name": "llama3",
"ls_model_name": MODEL_NAME,
}
llm = OllamaLLM(model="llama3", num_predict=3)
llm = OllamaLLM(model=MODEL_NAME, num_predict=3)
ls_params = llm._get_ls_params()
assert ls_params == {
"ls_provider": "ollama",
"ls_model_type": "llm",
"ls_model_name": "llama3",
"ls_model_name": MODEL_NAME,
"ls_max_tokens": 3,
}