Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(models): honor OpenRouter native thinking for legacy defaults (#3807)
tsumon188d9026d8d3
diff --git a/internal/models/parity/parity_test.go b/internal/models/parity/parity_test.goindex 9c0de9649..6b563bf62 100644--- a/internal/models/parity/parity_test.go+++ b/internal/models/parity/parity_test.go@@ -315,6 +315,28 @@ func TestLegacyWireParity(t *testing.T) {opts: &api.Options{Thinking: ptrBool(true)},want: map[string]any{"chat_template_kwargs": map[string]any{"enable_thinking": true}},},+ {+ name: "openrouter legacy default keeps the native reasoning format",+ provider: "openrouter", model: "qwen/qwen3.7-flash",+ extra: map[string]string{models.ExtraThinkingControl: "none"},+ opts: &api.Options{Thinking: ptrBool(false)},+ want: map[string]any{+ "reasoning": map[string]any{"enabled": false},+ "chat_template_kwargs": nil,+ },+ divergence: "the pre-catalog editor persisted OpenRouter's default `none` on every remote row; " ++ "that default must not suppress the provider's native reasoning switch.",+ },+ {+ name: "openrouter non-default legacy format remains an explicit override",+ provider: "openrouter", model: "qwen/qwen3.7-flash",+ extra: map[string]string{models.ExtraThinkingControl: "chat_template_kwargs"},+ opts: &api.Options{Thinking: ptrBool(false)},+ want: map[string]any{+ "reasoning": nil,+ "chat_template_kwargs": map[string]any{"enable_thinking": false},+ },+ },{name: "moonshot v1 pins temperature to 1 and drops other sampling",provider: "moonshot", model: "moonshot-v1-8k",diff --git a/internal/models/runtime/legacy.go b/internal/models/runtime/legacy.goindex 5ecb00ae6..2c1cb1d44 100644--- a/internal/models/runtime/legacy.go+++ b/internal/models/runtime/legacy.go@@ -21,11 +21,23 @@ func inferAPIFromURL(baseURL string, current api.API) api.API {// applyLegacyThinkingControl maps the pre-catalog thinking_control value// onto the new settings. Unknown non-empty values keep the historical-// fallback (chat_template_kwargs).-func applyLegacyThinkingControl(s *api.OpenAICompletionsSettings, value string) {- switch strings.ToLower(strings.TrimSpace(value)) {- case "":- return+// fallback (chat_template_kwargs). It reports whether a stored value was+// applied, so the caller can still silence catalogued non-reasoning models+// when a legacy default is ignored.+func applyLegacyThinkingControl(s *api.OpenAICompletionsSettings, value string) bool {+ normalized := strings.ToLower(strings.TrimSpace(value))+ if normalized == "" {+ return false+ }+ // The pre-catalog editor persisted "none" as OpenRouter's default for+ // every remote model row. It was not an explicit request to suppress the+ // provider's newer native reasoning format, which is needed to honor the+ // caller's thinking=false setting. Keep honoring every non-default legacy+ // encoding as an explicit per-row override.+ if normalized == "none" && s.ThinkingFormat == api.ThinkingFormatOpenRouter {+ return false+ }+ switch normalized {case "none":s.ThinkingFormat = api.ThinkingFormatNonecase "enable_thinking":@@ -35,4 +47,5 @@ func applyLegacyThinkingControl(s *api.OpenAICompletionsSettings, value string)default:s.ThinkingFormat = api.ThinkingFormatChatTemplateKwargs}+ return true}diff --git a/internal/models/runtime/resolve.go b/internal/models/runtime/resolve.goindex c6d454756..c2b950849 100644--- a/internal/models/runtime/resolve.go+++ b/internal/models/runtime/resolve.go@@ -169,7 +169,9 @@ func resolveWithVendor(ref Ref, vendor *Provider) (*Resolved, error) {); err != nil {return nil, err}- applyLegacyThinkingControl(&completions, ref.Extra[models.ExtraThinkingControl])+ legacyThinkingControlApplied := applyLegacyThinkingControl(+ &completions, ref.Extra[models.ExtraThinkingControl],+ )out.OpenAICompletions = completionsresponses := api.DefaultOpenAIResponses()@@ -213,9 +215,9 @@ func resolveWithVendor(ref Ref, vendor *Provider) (*Resolved, error) {return nil, err}out.GoogleGenerativeAI = google- // An explicit legacy thinking_control is the operator saying "this row- // does think, send the switch this way", so it outranks the catalog.- if strings.TrimSpace(ref.Extra[models.ExtraThinkingControl]) == "" {+ // A non-default legacy thinking_control is an explicit per-row override.+ // An ignored provider default lets the catalog's reasoning metadata apply.+ if !legacyThinkingControlApplied {out.silenceThinkingForNonReasoningModel()}