diff --git a/internal/gateway/chat.go b/internal/gateway/chat.go index eb08166ad..852829958 100644 --- a/internal/gateway/chat.go +++ b/internal/gateway/chat.go @@ -7,6 +7,8 @@ import ( "net" "strings" "time" + + "github.com/yetone/magpie/internal/provider" ) // ---- OpenAI Chat Completions -------------------------------------------------- @@ -176,7 +178,9 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte { if r.System != "" { msgs = append(msgs, map[string]any{"role": "system", "content": r.System}) } - deepseek := strings.Contains(host, "deepseek") + // DeepSeek takes a turn's reasoning back, as Command Code's plugin does + // for a Go key, as the built-in replayed it to /alpha/generate + replay := strings.Contains(host, "deepseek") || host == provider.CommandCodePlanID // A tool message holds text only, so the images tools returned go to // the model in a user message after the tool messages, as the start of // the user's own message when one comes next: some models' chat @@ -231,7 +235,7 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte { if len(calls) > 0 { am["tool_calls"] = calls } - if deepseek && think != "" { + if replay && think != "" { am["reasoning_content"] = think } msgs = append(msgs, am) diff --git a/internal/gateway/plugin_parity_test.go b/internal/gateway/plugin_parity_test.go index 6d7a49c14..cc52b2b50 100644 --- a/internal/gateway/plugin_parity_test.go +++ b/internal/gateway/plugin_parity_test.go @@ -118,3 +118,22 @@ func TestCursorPluginFast(t *testing.T) { } } } + +// A Command Code Go conversation moved onto its plugin keeps its +// reasoning, as the built-in replayed it to /alpha/generate: its plugin +// reads reasoning_content. DeepSeek still gets it, others don't. +func TestCommandCodePluginReasoning(t *testing.T) { + reasoning := func(host string) any { + return chatBody(t, host)["messages"].([]any)[1].(map[string]any)["reasoning_content"] + } + for _, host := range []string{provider.CommandCodePlanID, "api.deepseek.com"} { + if got := reasoning(host); got != "pondered" { + t.Errorf("%s got reasoning %v", host, got) + } + } + for _, host := range []string{"api.openai.com", "cursor", "zed"} { + if got := reasoning(host); got != nil { + t.Errorf("%s got reasoning_content %v", host, got) + } + } +}