Agent side (claude.go): new quiet fields opus_effort, sonnet_effort, haiku_effort, fable_effort and subagent_effort (the last with Codex's key and label, so the GUI's subagent-effort square serves both), offered only while Claude Code is routed through magpie, their levels the tier's model's (catalog Efforts, else Claude's own), validated against provider.MemberEfforts. A tier's effort stays with it through a model of its own, back to the main model's, and a new main model (a tier that follows the main model at an effort is written "main:level" and followed on a model change); the tier's model field still reads "" while it follows main; [1m] goes after the level; the context window and capability list read the model without it; clearing the effort writes the tier as before, and turning magpie off removes it all with the rest. The main model's effort is untouched.
GUI (app.js, i18n.js): the tier efforts are not fields of their own; the tiers' square lists each tier's model and then its effort, with the effort bars and, unset, "the effort Claude Code asks for" (「跟随 Claude Code 请求的推理强度」); an effort entry opens the effort slider (Default first), and the square's light and title follow the pick ("tiers: haiku (low)"). Claude Code's subagent-effort square says the same for unset, Codex's keeps its own wording, and the square is hidden while there are no levels (not through magpie). No click scrolls the page.
Not verified against a real Claude Code: that it passes a model id containing ":level" through to the gateway untouched (Bedrock-style ids with ":0" suggest it does). No request was made to a vendor. TestClaudeTierEffort (agent: fails without the change, "no opus_effort field"), TestModelAskedAtAnEffort (gateway: fails without, the model sent as "small:low") and tier-effort.test.cjs (WebKit, en and zh; fails on the old app.js) pass; TestClaudeTiers, TestClaudeSubagentModel, TestFixedMember*, and subagent-effort, claude-effort, panel-effort, agent-layout, omp-roles, click-scroll, agent-grip pass in WebKit (menu-scroll fails the same on the base: its fake API lacks /api/plugins/updates; Chromium's channel launch lacks ICU here). go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass.
91 lines
3.8 KiB
Go
91 lines
3.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A model asked for at an effort of its own, "<model>:<level>" — a Claude
|
|
// Code tier magpie set one on (#536) — is that model, asked for that effort
|
|
// at its nearest level whatever the agent asked, as a group's member fixed
|
|
// at one is (#189); the trace says it was fixed. A member's own effort wins
|
|
// over it, and a model whose own id ends in a level is taken whole.
|
|
func TestModelAskedAtAnEffort(t *testing.T) {
|
|
s, a, b := ruled(t)
|
|
if err := provider.SetModelEfforts("a/small", []string{"low", "medium", "high"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
post := func(model, extra string) (string, Route) {
|
|
t.Helper()
|
|
return postOK(t, s, "", strings.Replace(chat("hi", nil, 0, extra), `"model":"group/r"`, `"model":`+quote(model), 1))
|
|
}
|
|
for _, c := range []struct{ model, asked, want, fixed string }{
|
|
{"a/small:low", "high", "low", "low"},
|
|
{"a/small:low", "", "low", "low"}, // asked for none: given it anyway
|
|
{"a/small:xhigh", "low", "high", "xhigh"},
|
|
{"a/small", "medium", "medium", ""}, // none of its own: as asked
|
|
} {
|
|
extra := ""
|
|
if c.asked != "" {
|
|
extra = `,"reasoning_effort":"` + c.asked + `"`
|
|
}
|
|
out, r := post(c.model, extra)
|
|
sent := sentBody(t, a)
|
|
if !strings.Contains(out, "from ka") || sent["model"] != "small" || sent["reasoning_effort"] != c.want {
|
|
t.Fatalf("%s asked %q: sent %v (%s)", c.model, c.asked, sent, out)
|
|
}
|
|
if r.Model != "a/small" || len(r.Tries) != 1 || r.Tries[0].Fixed != c.fixed || r.Tries[0].Effort != c.want {
|
|
t.Fatalf("%s asked %q: traced %s %+v", c.model, c.asked, r.Model, r.Tries)
|
|
}
|
|
}
|
|
|
|
// as Claude Code asks: Anthropic's API, the tier's model marked [1m]
|
|
rec := httptest.NewRecorder()
|
|
req := httptest.NewRequest("POST", "/v1/messages", strings.NewReader(`{"model":"a/small:low[1m]","max_tokens":32000,"thinking":{"type":"adaptive"},"output_config":{"effort":"high"},"messages":[{"role":"user","content":"hi"}]}`))
|
|
req.Header.Set("anthropic-version", "2023-06-01")
|
|
s.Handler().ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("messages: %d %s", rec.Code, rec.Body)
|
|
}
|
|
if sent := sentBody(t, a); sent["model"] != "small" || sent["reasoning_effort"] != "low" {
|
|
t.Fatalf("messages sent %v", sent)
|
|
}
|
|
if r := lastRoute(s); r.Model != "a/small[1m]" && r.Model != "a/small" || r.Tries[0].Fixed != "low" {
|
|
t.Fatalf("messages traced %s %+v", r.Model, r.Tries)
|
|
}
|
|
|
|
// a group at an effort: its members without one of their own take it,
|
|
// one with its own keeps that
|
|
setMembers(t, []string{"a/small", "b/big"})
|
|
_, r := post("group/r:low", `,"reasoning_effort":"high"`)
|
|
if sent := sentBody(t, a); sent["reasoning_effort"] != "low" || r.Group == nil || r.Tries[0].Fixed != "low" {
|
|
t.Fatalf("group at low: sent %v traced %+v", sent, r.Tries)
|
|
}
|
|
setMembers(t, []string{"a/small:medium", "b/big"})
|
|
_, r = post("group/r:low", `,"reasoning_effort":"high"`)
|
|
if sent := sentBody(t, a); sent["reasoning_effort"] != "medium" || r.Tries[0].Fixed != "medium" {
|
|
t.Fatalf("member's own: sent %v traced %+v", sent, r.Tries)
|
|
}
|
|
|
|
// a model whose own id ends in a level is that model, at no effort fixed
|
|
pb, err := provider.Find("b")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "c", Name: "C", Key: "kc", Models: []string{"tiny:high"}, Chat: pb.Chat}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := catalog.SaveLive("c", pb.Chat, []catalog.Model{{ID: "tiny:high"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, r = post("c/tiny:high", `,"reasoning_effort":"low"`)
|
|
if sent := sentBody(t, b); sent["model"] != "tiny:high" || sent["reasoning_effort"] != "low" || r.Tries[0].Fixed != "" {
|
|
t.Fatalf("own colon: sent %v traced %+v", sent, r.Tries)
|
|
}
|
|
}
|