[PR #14412] [CLOSED] fix(openai): coerce unsupported think levels for openai-compat chat #40539

Closed
opened 2026-04-23 01:25:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14412
Author: @breynol01
Created: 2/25/2026
Status: Closed

Base: mainHead: fix/openai-compat-think-coercion


📝 Commits (1)

  • 6ff325a fix(openai): coerce unsupported think levels for openai-compat chat

📊 Changes

6 files changed (+206 additions, -0 deletions)

View changed files

📝 middleware/openai.go (+2 -0)
📝 middleware/openai_test.go (+49 -0)
📝 openai/openai.go (+4 -0)
📝 openai/openai_test.go (+66 -0)
📝 server/routes.go (+15 -0)
📝 server/routes_generate_test.go (+70 -0)

📄 Description

Summary

  • Set an openai_compat request context flag in OpenAI chat middleware and add parser-aware coercion in ChatHandler/GenerateHandler via coerceOpenAICompatThink.
  • Coerce non-harmony string think levels (high|medium|low) to boolean true only for OpenAI-compatible requests, preserving strict behavior for native API requests.
  • Add coverage for reasoning precedence conversion, OpenAI middleware context flagging, and coercion helper behavior in server tests.

Why

OpenAI-compatible /v1/chat/completions requests currently map reasoning_effort: \"high\" to a string think value, but boolean-only thinking models reject string think levels with think value \"high\" is not supported for this model.

This change keeps GPT-OSS/harmony level semantics intact while making boolean-only models treat level effort intent as "thinking enabled" in the OpenAI-compat path.

Validation

  • go test ./openai -run "FromChatRequest|Reasoning|Think" -v
  • go test ./middleware -run "ChatMiddleware|OpenAICompat" -v
  • go test ./server -run "TestCoerceOpenAICompatThink|TestGenerateChat/missing_thinking_capability" -v
  • Manual runtime check on patched build (qwen3:8b):
    • reasoning_effort: \"high\" now succeeds (previously failed)
    • reasoning_effort: \"none\" still disables thinking
    • omitted effort still uses default thinking 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/14412 **Author:** [@breynol01](https://github.com/breynol01) **Created:** 2/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/openai-compat-think-coercion` --- ### 📝 Commits (1) - [`6ff325a`](https://github.com/ollama/ollama/commit/6ff325ae34b954cd9482a6d8f3fd0fd9a898d771) fix(openai): coerce unsupported think levels for openai-compat chat ### 📊 Changes **6 files changed** (+206 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `middleware/openai.go` (+2 -0) 📝 `middleware/openai_test.go` (+49 -0) 📝 `openai/openai.go` (+4 -0) 📝 `openai/openai_test.go` (+66 -0) 📝 `server/routes.go` (+15 -0) 📝 `server/routes_generate_test.go` (+70 -0) </details> ### 📄 Description ## Summary - Set an `openai_compat` request context flag in OpenAI chat middleware and add parser-aware coercion in `ChatHandler`/`GenerateHandler` via `coerceOpenAICompatThink`. - Coerce non-harmony string think levels (`high|medium|low`) to boolean `true` only for OpenAI-compatible requests, preserving strict behavior for native API requests. - Add coverage for reasoning precedence conversion, OpenAI middleware context flagging, and coercion helper behavior in server tests. ## Why OpenAI-compatible `/v1/chat/completions` requests currently map `reasoning_effort: \"high\"` to a string `think` value, but boolean-only thinking models reject string think levels with `think value \"high\" is not supported for this model`. This change keeps GPT-OSS/harmony level semantics intact while making boolean-only models treat level effort intent as "thinking enabled" in the OpenAI-compat path. ## Validation - `go test ./openai -run "FromChatRequest|Reasoning|Think" -v` - `go test ./middleware -run "ChatMiddleware|OpenAICompat" -v` - `go test ./server -run "TestCoerceOpenAICompatThink|TestGenerateChat/missing_thinking_capability" -v` - Manual runtime check on patched build (`qwen3:8b`): - `reasoning_effort: \"high\"` now succeeds (previously failed) - `reasoning_effort: \"none\"` still disables thinking - omitted effort still uses default thinking behavior ## Related - ollama/ollama#12004 - ollama/ollama#12561 --- <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-23 01:25:08 -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#40539