-
Notifications
You must be signed in to change notification settings - Fork 19.3k
fix: strip think tags from content when reasoning=False #33042
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
base: master
Are you sure you want to change the base?
fix: strip think tags from content when reasoning=False #33042
Conversation
- Add _strip_think_tags function to remove <think>...</think> blocks - Apply tag stripping in both sync and async streaming methods when reasoning=False - Fixes issue where thinking content appeared in response despite reasoning=False - Ensures clean responses when users explicitly disable reasoning mode
- Add _strip_think_tags function to remove <think>...</think> blocks - Apply tag stripping in both sync and async streaming methods when reasoning=False - Fixes issue where thinking content appeared in response despite reasoning=False - Ensures clean responses when users explicitly disable reasoning mode
The latest updates on your projects. Learn more about Vercel for GitHub. |
CodSpeed Instrumentation Performance ReportMerging #33042 will not alter performanceComparing Summary
Footnotes
|
- Change single quotes to double quotes in regex patterns - Add proper spacing after import statement - Ensures CI linting checks pass
hey @mdrxy, is there anything i need to update? |
yup also #33116 |
👀 |
See comment on issue |
- Move import re from function level to top-level imports - Ensures compliance with Python import style guidelines - Functionality remains unchanged
cb48cca
to
9a42e6d
Compare
- Keep our _strip_think_tags function implementation - Maintain double quotes and top-level import structure - Ensure compatibility with latest master changes - Fix verified to still work correctly after merge
@mdrxy done, sorry for that |
Description: Fix ChatOllama reasoning parameter not working as expected when set to False. When users explicitly disable reasoning by setting
reasoning=False
, thinking content (<think>...</think>
tags) was still appearing in the response body. This fix adds a_strip_think_tags
function that removes think tags from content whenreasoning=False
, ensuring clean responses without any reasoning content.Issue: Fixes #33041
Dependencies: None - this is a pure bug fix that doesn't require any new dependencies.
Additional Details:
Root Cause: The ChatOllama implementation correctly passed
False
to the Ollama API as thethink
parameter, but did not strip the<think>
tags from the response content. The code only extracted reasoning content toadditional_kwargs
whenreasoning=True
, but had no logic to strip think tags whenreasoning=False
.Solution:
_strip_think_tags()
function that removes<think>...</think>
blocks using regex_iterate_over_stream
) and async (_aiterate_over_stream
) streaming methods to strip think tags whenreasoning=False
Behavior After Fix:
reasoning=True
: Reasoning content extracted toadditional_kwargs["reasoning_content"]
, main content cleanreasoning=False
: Think tags stripped from main content, no reasoning content anywherereasoning=None
: Default behavior (think tags remain in main content)Testing:
_strip_think_tags
functioninvoke()
andstream()
methods properly strip think tags whenreasoning=False
reasoning=True
continues to work as expectedFiles Modified:
libs/partners/ollama/langchain_ollama/chat_models.py
(32 lines added)This fix ensures that when users explicitly set
reasoning=False
, they get clean responses without any thinking content, which was the expected behavior that was missing.