[PR #15327] server: fix thinking not enabled by default for /api/generate #25656

Open
opened 2026-04-19 18:20:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15327
Author: @kiyeonjeon21
Created: 4/4/2026
Status: 🔄 Open

Base: mainHead: fix/generate-thinking-init-order


📝 Commits (1)

  • deecf08 server: fix thinking not enabled by default for /api/generate

📊 Changes

1 file changed (+13 additions, -13 deletions)

View changed files

📝 server/routes.go (+13 -13)

📄 Description

Summary

Fixes #15268

The /api/generate endpoint was not enabling thinking by default for models with thinking capability (e.g., gemma4), while /api/chat worked correctly.

Root cause: builtinParser.Init(nil, nil, req.Think) was called before req.Think was defaulted to true for thinking-capable models. This meant the parser was always initialized with req.Think = nil unless the user explicitly passed think: true.

Fix: Reorder the parser initialization block to come after the thinking capability check, matching the ordering already used in the /api/chat endpoint.

Test plan

  • Existing tests pass (TestGenerate, TestGenerateChat, TestChatWithPromptEndingInThinkTag, TestGenerateWithBuiltinRenderer)
  • Verify with a thinking-capable model (e.g., gemma4):
    • POST /api/generate without think param → should include thinking output
    • POST /api/generate with think: false → should not include thinking output
    • POST /api/generate with think: true → should include thinking output (unchanged behavior)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/15327 **Author:** [@kiyeonjeon21](https://github.com/kiyeonjeon21) **Created:** 4/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/generate-thinking-init-order` --- ### 📝 Commits (1) - [`deecf08`](https://github.com/ollama/ollama/commit/deecf087a0ebb8a248fd644ec30f91722250a3cc) server: fix thinking not enabled by default for /api/generate ### 📊 Changes **1 file changed** (+13 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `server/routes.go` (+13 -13) </details> ### 📄 Description ## Summary Fixes #15268 The `/api/generate` endpoint was not enabling thinking by default for models with thinking capability (e.g., gemma4), while `/api/chat` worked correctly. **Root cause:** `builtinParser.Init(nil, nil, req.Think)` was called *before* `req.Think` was defaulted to `true` for thinking-capable models. This meant the parser was always initialized with `req.Think = nil` unless the user explicitly passed `think: true`. **Fix:** Reorder the parser initialization block to come *after* the thinking capability check, matching the ordering already used in the `/api/chat` endpoint. ## Test plan - [x] Existing tests pass (`TestGenerate`, `TestGenerateChat`, `TestChatWithPromptEndingInThinkTag`, `TestGenerateWithBuiltinRenderer`) - Verify with a thinking-capable model (e.g., gemma4): - `POST /api/generate` without `think` param → should include thinking output - `POST /api/generate` with `think: false` → should not include thinking output - `POST /api/generate` with `think: true` → should include thinking output (unchanged behavior) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-19 18:20:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#25656