fix(api): disable qwen3 thinking mode when tools are injected (Ollama)#329
Open
sridhar-3009 wants to merge 1 commit into
Open
fix(api): disable qwen3 thinking mode when tools are injected (Ollama)#329sridhar-3009 wants to merge 1 commit into
sridhar-3009 wants to merge 1 commit into
Conversation
qwen3-family models enable thinking mode via their chat template, not
via stream_options (which is already stripped when tools are present to
work around a Kimi issue). With 30+ built-in tools in the request the
reasoning trace grows very large and the streaming connection times out
before the final token arrives, surfacing as a generic "Request timed
out" error.
Add _is_qwen3_model() to detect qwen3 Ollama / HuggingFace model names
(handles tags like "qwen3:14b-64k" and namespace-prefixed names like
"Qwen/Qwen3-14B-Instruct"). When the model is qwen3 and tools are
present, pass chat_template_kwargs={"enable_thinking": False} — Ollama
forwards this to the model's Jinja chat template, which disables the
<think> block and lets the model respond directly.
Fixes HKUDS#320
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #320
qwen3-family models on Ollama enable thinking mode via their Jinja chat template, not viastream_options(which is already stripped when tools are present to work around a Kimi issue). When 30+ built-in tools are injected into the prompt the reasoning trace grows very large, and the OpenAI streaming connection times out before the final token arrives — surfacing as a generic"Request timed out"error even though the model and Ollama server are healthy.Diagnosis:
--bareskips tools and returns in ~3 s; directcurlwith no tools also works. Only the combination of qwen3 + tools triggers the hang.Fix: When the model is in the qwen3 family and tools are present, add
chat_template_kwargs={"enable_thinking": False}to the request params. Ollama forwardschat_template_kwargsto the model's Jinja chat template, which suppresses the<think>block so the model answers directly without a long reasoning trace.Adds
_is_qwen3_model()to detect:qwen3,qwen3:14b-64k,qwen3:7b, …Qwen/Qwen3-7B,Qwen/Qwen3-14B-Instruct, …Test plan
oh -p "..." --model qwen3:14b-64k --api-format openai --base-url http://localhost:11434/v1with tools — verify no timeout and model responds directly.qwen2.5-coder:7b(non-qwen3) — verifychat_template_kwargsis NOT added.--baremode still works unchanged (tools not injected →chat_template_kwargsnot added regardless of model).Qwen/Qwen3-7B(HuggingFace namespace) is also detected.