diff --git a/internal/reasoning/eino.go b/internal/reasoning/eino.go index 0d7a0a30..7dbc1306 100644 --- a/internal/reasoning/eino.go +++ b/internal/reasoning/eino.go @@ -56,6 +56,7 @@ func ApplyToEinoChatModelConfig(cfg *einoopenai.ChatModelConfig, oa *config.Open } if mode == "off" { + applyThinkingDisabled(cfg) return } effort := effectiveEffort(sr, client, allowClient) @@ -185,11 +186,21 @@ func resolveWireProfile(oa *config.OpenAIConfig, sr *config.OpenAIReasoningConfi } } -func applyDeepseek(cfg *einoopenai.ChatModelConfig, mode, effort string) { - // auto: enable thinking for DeepSeek line; on: same; auto without effort still opens thinking. - if mode == "off" { +func applyThinkingDisabled(cfg *einoopenai.ChatModelConfig) { + if cfg == nil { return } + if cfg.ExtraFields == nil { + cfg.ExtraFields = make(map[string]any) + } + if _, exists := cfg.ExtraFields["thinking"]; exists { + return + } + cfg.ExtraFields["thinking"] = map[string]any{"type": "disabled"} +} + +func applyDeepseek(cfg *einoopenai.ChatModelConfig, mode, effort string) { + // auto: enable thinking for DeepSeek line; on: same; auto without effort still opens thinking. if mode == "auto" || mode == "on" { if cfg.ExtraFields == nil { cfg.ExtraFields = make(map[string]any) diff --git a/internal/reasoning/eino_test.go b/internal/reasoning/eino_test.go index 1aae209e..5f23646f 100644 --- a/internal/reasoning/eino_test.go +++ b/internal/reasoning/eino_test.go @@ -49,6 +49,22 @@ func TestApplyOpenAICompat_xhighExtraField(t *testing.T) { } } +func TestApplyReasoningOff_disablesThinking(t *testing.T) { + cfg := &einoopenai.ChatModelConfig{} + oa := &config.OpenAIConfig{ + BaseURL: "https://api.openai.com/v1", + Model: "gpt-4o", + Reasoning: config.OpenAIReasoningConfig{ + Mode: "off", + }, + } + ApplyToEinoChatModelConfig(cfg, oa, nil) + th, ok := cfg.ExtraFields["thinking"].(map[string]any) + if !ok || th["type"] != "disabled" { + t.Fatalf("expected thinking disabled, got %#v", cfg.ExtraFields) + } +} + func TestApplyOpenAICompat_maxPassthrough(t *testing.T) { cfg := &einoopenai.ChatModelConfig{} oa := &config.OpenAIConfig{