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): stop advertising graded thinking levels the wire format drops (#3552)
DerrickLinusa9d71038b665
diff --git a/internal/models/api/openaicompletions/golden_test.go b/internal/models/api/openaicompletions/golden_test.goindex d7c4d3ba4..663ad3328 100644--- a/internal/models/api/openaicompletions/golden_test.go+++ b/internal/models/api/openaicompletions/golden_test.go@@ -225,6 +225,36 @@ func TestGolden(t *testing.T) {opts: &api.Options{Thinking: ptrBool(true)},want: map[string]any{"chat_template_kwargs": map[string]any{"enable_thinking": true}},},+ {+ // Without the effort opt-in the graded level the caller picked is+ // not expressible in this dialect: the branch carries only the+ // boolean and no reasoning_effort may leak onto the wire+ // (capabilities must not advertise rungs for the same reason).+ name: "vllm: graded effort request still carries only the boolean",+ mutate: func(c *Config) {+ c.Settings.ThinkingFormat = api.ThinkingFormatChatTemplateKwargs+ },+ opts: &api.Options{Thinking: ptrBool(true), ReasoningEffort: api.ReasoningHigh},+ want: map[string]any{+ "chat_template_kwargs": map[string]any{"enable_thinking": true},+ "reasoning_effort": nil,+ },+ },+ {+ // With the effort opt-in the graded level rides on top of the+ // switch, exactly like the enable_thinking dialect (#3552+ // review): capabilities keep the ladder for the same reason.+ name: "nim-style opt-in: chat_template_kwargs plus reasoning_effort",+ mutate: func(c *Config) {+ c.Settings.ThinkingFormat = api.ThinkingFormatChatTemplateKwargs+ c.Settings.SupportsReasoningEffort = true+ },+ opts: &api.Options{Thinking: ptrBool(true), ReasoningEffort: api.ReasoningHigh},+ want: map[string]any{+ "chat_template_kwargs": map[string]any{"enable_thinking": true},+ "reasoning_effort": "high",+ },+ },{name: "openrouter: reasoning effort object and enabled=false",mutate: func(c *Config) {diff --git a/internal/models/api/openaicompletions/request.go b/internal/models/api/openaicompletions/request.goindex a949891f5..7e57ca21b 100644--- a/internal/models/api/openaicompletions/request.go+++ b/internal/models/api/openaicompletions/request.go@@ -392,6 +392,9 @@ func (c *Client) applyThinking(body map[string]any, opts *api.Options, stream bo}case api.ThinkingFormatChatTemplateKwargs:body["chat_template_kwargs"] = map[string]any{"enable_thinking": enabled}+ if effort != "" {+ body[effortField] = effort+ }case api.ThinkingFormatOpenRouter:if enabled {reasoning := map[string]any{}diff --git a/internal/models/runtime/catalog_test.go b/internal/models/runtime/catalog_test.goindex fcecaafa5..05e1032f8 100644--- a/internal/models/runtime/catalog_test.go+++ b/internal/models/runtime/catalog_test.go@@ -65,6 +65,31 @@ func registerTestVendors(t *testing.T) {},ModelTypes: []types.ModelType{types.ModelTypeKnowledgeQA},})+ // acme-nim mirrors the NVIDIA NIM entries before #3489: a chat-template+ // switch that carries only the enable_thinking boolean, while the models+ // carry ladders the branch cannot encode.+ modelruntime.Register(&providers.Definition{+ ID: "acme-nim", Name: "Acme NIM", API: api.APIOpenAICompletions,+ ModelTypes: []types.ModelType{types.ModelTypeKnowledgeQA},+ Compat: providers.VendorCompat{OpenAICompletions: api.OpenAICompletionsCompat{+ MaxTokensField: api.Ptr("max_tokens"),+ ThinkingFormat: api.Ptr(api.ThinkingFormatChatTemplateKwargs),+ }},+ }, []models.ModelSpec{+ {+ ID: "acme-nim-glm", Reasoning: true,+ ThinkingLevels: api.ThinkingLevelMap{+ api.ReasoningOff: nil,+ api.ReasoningMinimal: api.StringPtr("low"),+ api.ReasoningHigh: api.StringPtr("high"),+ },+ },+ {+ ID: "acme-nim-effort", Reasoning: true,+ Compat: json.RawMessage(`{"supports_reasoning_effort": true}`),+ ThinkingLevels: api.ThinkingLevelMap{api.ReasoningHigh: api.StringPtr("high")},+ },+ }...)}func TestFindModel_ExactAliasAndGlob(t *testing.T) {@@ -273,6 +298,45 @@ func TestResolve_AlwaysOnModelCannotBeSwitchedOff(t *testing.T) {assert.NotContains(t, r.Capabilities().ThinkingLevels, api.ReasoningOff)}+// A chat-template switch carries only the enable_thinking boolean, so every+// graded rung is silently dropped on the wire — and a relay backend that does+// not know enable_thinking drops the boolean too. Capabilities must not+// advertise levels the wire format cannot express, or the UI renders a+// selector whose choice does nothing. #3489 fixed the two catalogued NIM+// entries with this defect; this pins the generic fallback and the+// boolean-only vendor shape in general.+func TestResolve_BooleanThinkingSwitchHidesGradedLevels(t *testing.T) {+ registerTestVendors(t)++ // Uncatalogued model on the generic vendor — a relay row. The empty level+ // map's missing-key pass-through used to advertise six rungs here.+ r, err := modelruntime.Resolve(modelruntime.Ref{+ Provider: "generic", Model: "glm-5.3", BaseURL: "https://relay.example.com/v1",+ })+ require.NoError(t, err)+ assert.False(t, r.Cataloged)+ assert.Equal(t, []api.ReasoningEffort{api.ReasoningOff, api.ReasoningAuto},+ r.Capabilities().ThinkingLevels, "only the boolean the switch can carry")++ // Catalogued model whose ladder the chat-template branch cannot encode:+ // the graded rungs stay hidden from the selector.+ r, err = modelruntime.Resolve(modelruntime.Ref{Provider: "acme-nim", Model: "acme-nim-glm"})+ require.NoError(t, err)+ caps := r.Capabilities()+ assert.Equal(t, []api.ReasoningEffort{api.ReasoningAuto}, caps.ThinkingLevels,+ "always-on entry: off was already hidden, graded rungs must not appear")+ assert.NotContains(t, caps.ThinkingLevels, api.ReasoningMinimal)+ assert.NotContains(t, caps.ThinkingLevels, api.ReasoningHigh)++ // A vendor that opts into a top-level effort field alongside the switch+ // keeps its ladder (the future combo #3489's entries moved to).+ r, err = modelruntime.Resolve(modelruntime.Ref{Provider: "acme-nim", Model: "acme-nim-effort"})+ require.NoError(t, err)+ caps = r.Capabilities()+ assert.Contains(t, caps.ThinkingLevels, api.ReasoningMinimal, "pass-through rung kept")+ assert.Contains(t, caps.ThinkingLevels, api.ReasoningHigh, "explicit ladder rung kept")+}+func TestResolve_RejectsUnknownCompatKeys(t *testing.T) {registerTestVendors(t)_, err := modelruntime.Resolve(diff --git a/internal/models/runtime/resolve.go b/internal/models/runtime/resolve.goindex 7e821233e..c6d454756 100644--- a/internal/models/runtime/resolve.go+++ b/internal/models/runtime/resolve.go@@ -324,6 +324,23 @@ func (r *Resolved) Capabilities() Capabilities {caps.MaxTokensField = "num_predict"}caps.ThinkingLevels = r.ThinkingLevels.SupportedLevels()+ // A chat-template switch carries only the enable_thinking boolean: every+ // graded rung is silently dropped on the wire (and a relay backend that+ // does not know enable_thinking drops the boolean too), so the selector+ // must not offer rungs the request cannot express. Vendors that opt into+ // a top-level effort field keep their ladders (#3489 moved its NIM+ // entries to that shape).+ if r.API == api.APIOpenAICompletions &&+ r.OpenAICompletions.ThinkingFormat == api.ThinkingFormatChatTemplateKwargs &&+ !r.OpenAICompletions.SupportsReasoningEffort {+ keep := make([]api.ReasoningEffort, 0, 2)+ for _, level := range caps.ThinkingLevels {+ if !level.Graded() {+ keep = append(keep, level)+ }+ }+ caps.ThinkingLevels = keep+ }return caps}