Skip to content

fix(api): disable qwen3 thinking mode when tools are injected (Ollama)#329

Open
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/320-qwen3-thinking-mode-timeout
Open

fix(api): disable qwen3 thinking mode when tools are injected (Ollama)#329
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/320-qwen3-thinking-mode-timeout

Conversation

@sridhar-3009

Copy link
Copy Markdown

Summary

Closes #320

qwen3-family models on Ollama enable thinking mode via their Jinja chat template, not via stream_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: --bare skips tools and returns in ~3 s; direct curl with 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 forwards chat_template_kwargs to 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:

  • Ollama tags: qwen3, qwen3:14b-64k, qwen3:7b, …
  • HuggingFace namespaced names: Qwen/Qwen3-7B, Qwen/Qwen3-14B-Instruct, …

Test plan

  • oh -p "..." --model qwen3:14b-64k --api-format openai --base-url http://localhost:11434/v1 with tools — verify no timeout and model responds directly.
  • Same with qwen2.5-coder:7b (non-qwen3) — verify chat_template_kwargs is NOT added.
  • --bare mode still works unchanged (tools not injected → chat_template_kwargs not added regardless of model).
  • Qwen/Qwen3-7B (HuggingFace namespace) is also detected.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: qwen3 + full skill set + tools causes streaming timeout on Ollama (api-format=openai)

1 participant