nianshou5 (Discord) runs Trae's DeepSeek V4.1 Flash through the Our Free Model plugin (github:mu-zi-lee/magpie-our-free-model). Its variants are Trae's own names, light, high and extra_high, and dsh offered only default and high: dshModelLevels (and Pi's piThinkingLevels) matched a model's efforts to pi-ai's level names only, so light and extra_high were dropped. The gateway dropped them too: effortOf read "light" as no effort, and NearestEffort fitted an agent's low or xhigh to the plugin's high. catalog.EffortAliases names light as low and extra_high as xhigh (EffortLevel). NearestEffort places a model's levels by the level they name and returns the model's own word; the gateway's effortOf reads an alias as its level. dsh's reasoningEfforts and Pi's thinkingLevelMap map dsh's low/xhigh to the model's own word (modelEffort), which llm-pi-ai sends on the wire as written (resolveModelReasoning in dsh-llm-pi-ai reads each value as "the spelling dispatch sends"). Levels a user kept are untouched: only the names a model lists are mapped. Tests: TestDshOffersTraeNamedLevels (agent), TestNearestEffortTakesVendorWords (catalog), TestPluginThinkingOff's new fake-trae subtests (gateway, a real plugin host with the fake plugin listing light/high/extra_high). Broken by hand: modelEffort without the alias, dsh levels [high] (the report's picker); NearestEffort without EffortLevel, low/xhigh sent as high; effortOf without the alias, light/extra_high sent as nothing. Run on mote at this tree (basee4ccf67b1): go build, GOOS=linux and GOOS=windows go vet -tags nogui ./... ok; go test -tags nogui -timeout 45m ./... : 73 packages ok, three red that are red the same on origin/main7f32f0ec9run alone: internal/agent TestWSLColdPlaceOpensNothing (#3924), internal/tui TestTUIFetchesSubscriptionModels (#3919), internal/provider synctest crash in TestUnreadLoginsWriteErrorsKeepCredentials (#3632), so the rest of internal/provider didn't run. No GUI file changed. Rebased on7f32f0ec9(one agent file changed there): go build ./..., internal/catalog whole and gateway/agent -run Effort|Dsh|Pi|ThinkingOff|Level ok at this head. Not tried: a real dsh session against the user's plugin (no Our Free Model account here); dsh's parsing of a non-pi-ai wire value was read from its source, not run.
108 lines
6.0 KiB
Go
108 lines
6.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Factory's plugin, as the built-in (TestFactoryThinkingOff): a model whose
|
|
// variants have none is asked for none when an agent turns reasoning off,
|
|
// and one whose least is low is asked for low (#899).
|
|
func TestPluginThinkingOff(t *testing.T) {
|
|
t.Setenv("FAKE_OFF", "1")
|
|
var mu sync.Mutex
|
|
var sent []any
|
|
pid := besideFake(t, "factory", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var q map[string]any
|
|
b, _ := io.ReadAll(r.Body)
|
|
json.Unmarshal(b, &q)
|
|
mu.Lock()
|
|
sent = append(sent, q["reasoning_effort"])
|
|
mu.Unlock()
|
|
w.Header().Set("Content-Type", "text/event-stream")
|
|
io.WriteString(w, sse(`data: {"id":"c1","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"hi"},"finish_reason":"stop"}]}`, `data: [DONE]`))
|
|
}))
|
|
for _, tt := range []struct {
|
|
name, path, body string
|
|
want any
|
|
}{
|
|
{"chat none", "/v1/chat/completions", `{"model":"` + pid + `/fake-off","reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}`, "none"},
|
|
{"responses none", "/v1/responses", `{"model":"` + pid + `/fake-off","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "none"},
|
|
{"messages disabled", "/v1/messages", `{"model":"` + pid + `/fake-off","thinking":{"type":"disabled"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}`, "none"},
|
|
{"chat low", "/v1/chat/completions", `{"model":"` + pid + `/fake-off","reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}`, "low"},
|
|
// a client's "off" is none (plugins#334), in either API and as a
|
|
// model's suffix, never sent on as "off" nor as the least level on
|
|
{"chat off", "/v1/chat/completions", `{"model":"` + pid + `/fake-off","reasoning_effort":"off","messages":[{"role":"user","content":"hi"}]}`, "none"},
|
|
{"chat OFF spaced", "/v1/chat/completions", `{"model":"` + pid + `/fake-off","reasoning_effort" : " OFF ","messages":[{"role":"user","content":"hi"}]}`, "none"},
|
|
{"responses off", "/v1/responses", `{"model":"` + pid + `/fake-off","reasoning":{"effort":"off","summary":"auto"},"input":[{"role":"user","content":"hi"}]}`, "none"},
|
|
{"suffix off", "/v1/chat/completions", `{"model":"` + pid + `/fake-off:off","messages":[{"role":"user","content":"hi"}]}`, "none"},
|
|
{"no off, off", "/v1/chat/completions", `{"model":"` + pid + `/fake-on","reasoning_effort":"off","messages":[{"role":"user","content":"hi"}]}`, "low"},
|
|
{"no off", "/v1/responses", `{"model":"` + pid + `/fake-on","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "low"},
|
|
// a level in the vendor's own words, as dsh and Pi send it for
|
|
// their low and xhigh (modelEffort in internal/agent), reaches
|
|
// the plugin as it is (nianshou5)
|
|
{"chat light", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"light","messages":[{"role":"user","content":"hi"}]}`, "light"},
|
|
{"chat extra_high", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"extra_high","messages":[{"role":"user","content":"hi"}]}`, "extra_high"},
|
|
// and an agent's low and xhigh are sent in the model's words
|
|
{"chat low as light", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}`, "light"},
|
|
{"chat xhigh as extra_high", "/v1/chat/completions", `{"model":"` + pid + `/fake-trae","reasoning_effort":"xhigh","messages":[{"role":"user","content":"hi"}]}`, "extra_high"},
|
|
{"responses extra_high", "/v1/responses", `{"model":"` + pid + `/fake-trae","reasoning":{"effort":"extra_high"},"input":[{"role":"user","content":"hi"}]}`, "extra_high"},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
mu.Lock()
|
|
sent = nil
|
|
mu.Unlock()
|
|
postProto(t, New(), tt.path, tt.body)
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if len(sent) != 1 || sent[0] != tt.want {
|
|
t.Errorf("reasoning_effort sent %v, want %v", sent, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestOffAsNone: only an effort spelled "off" changes, to none; the rest
|
|
// of the body, numbers included, goes as it came, and another level or
|
|
// an "off" that isn't an effort is left alone (plugins#334).
|
|
func TestOffAsNone(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name string
|
|
from provider.Protocol
|
|
in, want string
|
|
}{
|
|
{"chat", provider.Chat, `{"model":"m","reasoning_effort":"off","max_tokens":12345678901}`, `{"max_tokens":12345678901,"model":"m","reasoning_effort":"none"}`},
|
|
{"responses", provider.Responses, `{"model":"m","reasoning":{"effort":"Off","summary":"auto","max_tokens":4096}}`, `{"model":"m","reasoning":{"effort":"none","max_tokens":4096,"summary":"auto"}}`},
|
|
{"chat reasoning object", provider.Chat, `{"model":"m","reasoning":{"effort":"off"}}`, `{"model":"m","reasoning":{"effort":"none"}}`},
|
|
{"low", provider.Chat, `{"model":"m","reasoning_effort":"low"}`, `{"model":"m","reasoning_effort":"low"}`},
|
|
{"offline", provider.Chat, `{"model":"m","reasoning_effort":"offline"}`, `{"model":"m","reasoning_effort":"offline"}`},
|
|
{"off in text", provider.Chat, `{"model":"m","messages":[{"role":"user","content":"effort\": \"off\""}]}`, `{"model":"m","messages":[{"role":"user","content":"effort\": \"off\""}]}`},
|
|
{"anthropic", provider.Anthropic, `{"model":"m","output_config":{"effort":"off"}}`, `{"model":"m","output_config":{"effort":"off"}}`},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := strings.TrimSpace(string(offAsNone(tt.from, []byte(tt.in))))
|
|
if got != tt.want {
|
|
t.Errorf("offAsNone(%s) = %s, want %s", tt.in, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestAskedAtOff: a model asked ":off" is asked at none, as ":none" is.
|
|
func TestAskedAtOff(t *testing.T) {
|
|
for _, id := range []string{"group/g:off", "group/g:OFF"} {
|
|
if m, e := askedAt(id); m != "group/g" || e != "none" {
|
|
t.Errorf("askedAt(%q) = %q, %q; want group/g, none", id, m, e)
|
|
}
|
|
}
|
|
if m, e := askedAt("group/g:offline"); m != "group/g:offline" || e != "" {
|
|
t.Errorf("askedAt(group/g:offline) = %q, %q", m, e)
|
|
}
|
|
}
|