-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(ollama): Add think Field to ChatOllama for Controlling Thought Process in Responses #8494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hunter Lovell (hntrl)
merged 16 commits into
langchain-ai:main
from
rliu6915:add-think-field
Sep 1, 2025
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
742c933
add think as field
rliu6915 866f336
in invocationParams, add think as parameter
rliu6915 67c167c
add two sucessful tests to set think to true and false
rliu6915 10c0e97
add think in constructor
rliu6915 e615194
change test, when thinking is enanbled, the response from ollama chat…
rliu6915 ad65fc3
when think enabled, check thinking first for thought process
rliu6915 6b2c064
check thinking field
rliu6915 1bc79a8
Merge branch 'main' into add-think-field
rliu6915 2ffaa5b
Update libs/langchain-ollama/src/tests/chat_models_think.int.test.ts
rliu6915 619bd10
Update libs/langchain-ollama/src/tests/chat_models_think.int.test.ts
rliu6915 d70289e
ollama 0.5.15 introduced thinking mode
rliu6915 f492788
Merge branch 'add-think-field' of https://github.com/rliu6915/my-lang…
rliu6915 3cac2f8
update ollama to 0.5.17
rliu6915 be99b35
fix: yarn format:check
rliu6915 32b2bbf
Merge branch 'main' into add-think-field
hntrl 5d98bd5
cr
hntrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
libs/langchain-ollama/src/tests/chat_models_think.int.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { test, expect } from "@jest/globals"; | ||
| import { HumanMessage } from "@langchain/core/messages"; | ||
| import { ChatOllama } from "../chat_models.js"; | ||
|
|
||
| test("test deep seek model with think=false", async () => { | ||
| const ollama = new ChatOllama({ | ||
| model: "deepseek-r1:32b", | ||
| think: false, // Ensure the "think" field is explicitly set to false | ||
| maxRetries: 1, | ||
| }); | ||
|
|
||
| const res = await ollama.invoke([ | ||
| new HumanMessage({ | ||
| content: "Explain the process of photosynthesis briefly.", | ||
| }), | ||
| ]); | ||
|
|
||
| // Ensure the response is defined | ||
| expect(res).toBeDefined(); | ||
| expect(res.content).toBeDefined(); | ||
|
|
||
| const responseContent = res.content; | ||
|
|
||
| // Validate that the response does not include any <think>...</think> blocks | ||
| // s means allow . to match new line character | ||
| expect(responseContent).not.toMatch(/<think>.*?<\/think>/is); | ||
|
|
||
| // Ensure the response is concise and directly answers the question | ||
| expect(responseContent).toMatch(/photosynthesis/i); // Check it includes the topic | ||
| expect(responseContent.length).toBeGreaterThan(1); | ||
| }); | ||
|
|
||
| test("test deep seek model with think=true (default)", async () => { | ||
| const ollama = new ChatOllama({ | ||
| model: "deepseek-r1:32b", | ||
| maxRetries: 1, | ||
| }); | ||
|
|
||
| const res = await ollama.invoke([ | ||
| new HumanMessage({ | ||
| content: "Explain the process of photosynthesis briefly.", | ||
| }), | ||
| ]); | ||
|
|
||
| // Ensure the response is defined | ||
| expect(res).toBeDefined(); | ||
| expect(res.content).toBeDefined(); | ||
|
|
||
| const responseContent = res.content; | ||
|
|
||
| // Ensure the response is concise and directly answers the question | ||
| expect(responseContent).toMatch(/photosynthesis/i); // Check it includes the topic | ||
| expect(responseContent.length).toBeGreaterThan(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.