The group offered no levels: its levels were what every member has, and a member whose levels magpie doesn't know (a Token Plan's deepseek-v4-pro-202606, which models.dev doesn't list) has none, so the intersection was empty and models.json had the group "reasoning": false. A model a provider was given that its vendor's models.dev list leaves out (TokenHub's deepseek-v4-pro, its list holding the Hy models alone) also had none in the catalog, where the gateway (Provider.Efforts) fits efforts to DeepSeek's low, high, max. Magpie's Pi field offered all seven levels whatever the model. - provider.Exposed: a picked model the vendor's list doesn't have takes the levels Provider.Known gives it (knownElsewhere), not none. - groupEntries: a member levelsUnknown (no levels, no account list, its vendor and maker don't list it, models.dev knows no model of its id — catalog.Knows) doesn't narrow the group's levels; the gateway sends it the effort as asked (fitEffort). A member listed with none still narrows them. - Pi/OmO thinking field: for a model of magpie's, Options are the levels Pi offers for the entry magpie writes (piSupported, as pi-ai's getSupportedThinkingLevels), and Get shows a level it doesn't offer as Pi's clamp of it (piClamp). Now Pi at max on that group sends reasoning_effort "max", relayed as max to both members (DeepSeek's levels have max; the unknown one is sent it as asked). New tests: TestGroupLevelsWithUnknownMember (provider), TestPiGroupThinkingIsWhatPiRuns and TestPiClamp (agent); each fails without the change (group entry "reasoning": false; catalog levels []; field offering all seven). TestMoveCursorEfforts gives its model levels, since Pi is offered off alone for one without. go vet, nogui/linux/windows builds and the full test suite pass but the known flake TestFXInState.
118 lines
4.2 KiB
Go
118 lines
4.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #597: Pi on a routing group of DeepSeek V4 Pro (TokenHub's, and the Token
|
|
// Plan's deepseek-v4-pro-202606 that nothing magpie reads knows) was
|
|
// written the group without reasoning, so its /thinking offered off alone,
|
|
// while magpie's thinking field offered every level and showed max — which
|
|
// Pi clamped to off, sending no reasoning_effort. The group now has its
|
|
// known member's levels, Pi's entry offers them, and magpie's field offers
|
|
// what Pi offers for the model and shows the level Pi runs it at.
|
|
func TestPiGroupThinkingIsWhatPiRuns(t *testing.T) {
|
|
home := syncHome(t)
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{
|
|
"deepseek": {"models": {"deepseek-v4-pro": {"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","reasoning":true,
|
|
"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","high","max"]}],"limit":{"context":1000000}}}}
|
|
}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
for _, p := range []provider.Provider{
|
|
{ID: "th", Name: "TokenHub", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "tencent-tokenhub", Models: []string{"deepseek-v4-pro"}},
|
|
{ID: "tp", Name: "Token Plan", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4-pro-202606"}},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "deepseek", Name: "腾讯DeepSeek", Members: []string{"tp/deepseek-v4-pro-202606", "th/deepseek-v4-pro"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "plan", Name: "Plan", Members: []string{"tp/deepseek-v4-pro-202606"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := pi(home)
|
|
if err := a.Field("model").Set("magpie/group/deepseek"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Field("effort").Set("max"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var file map[string]any
|
|
if err := json.Unmarshal([]byte(readFile(filepath.Join(home, ".pi", "agent", "models.json"))), &file); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var entry map[string]any
|
|
for _, raw := range file["providers"].(map[string]any)["magpie"].(map[string]any)["models"].([]any) {
|
|
if m := raw.(map[string]any); m["id"] == "group/deepseek" {
|
|
entry = m
|
|
}
|
|
}
|
|
if entry == nil || entry["reasoning"] != true {
|
|
t.Fatalf("group entry: %v", entry)
|
|
}
|
|
if got := piSupported(entry); !reflect.DeepEqual(got, []string{"low", "high", "max"}) {
|
|
t.Fatalf("Pi offers %v for the group: %v", got, entry["thinkingLevelMap"])
|
|
}
|
|
|
|
values := func(os []Option) []string {
|
|
var out []string
|
|
for _, o := range os {
|
|
out = append(out, o.Value)
|
|
}
|
|
return out
|
|
}
|
|
effort := a.Field("effort")
|
|
if got := values(effort.Options(map[string]string{"model": "magpie/group/deepseek"})); !reflect.DeepEqual(got, []string{"low", "high", "max"}) {
|
|
t.Fatalf("offered %v", got)
|
|
}
|
|
if got := effort.Get(); got != "max" {
|
|
t.Fatalf("shown %q, want max", got)
|
|
}
|
|
|
|
// on a group Pi can't reason with, max is shown as the off Pi runs at
|
|
if err := a.Field("model").Set("magpie/group/plan"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := values(effort.Options(map[string]string{"model": "magpie/group/plan"})); !reflect.DeepEqual(got, []string{"off"}) {
|
|
t.Fatalf("plan: offered %v", got)
|
|
}
|
|
if got := effort.Get(); got != "off" {
|
|
t.Fatalf("plan: shown %q, want off", got)
|
|
}
|
|
// a model of Pi's own keeps every level
|
|
if got := values(effort.Options(map[string]string{"model": "anthropic/claude-x"})); !reflect.DeepEqual(got, piLevels) {
|
|
t.Fatalf("own model: offered %v", got)
|
|
}
|
|
}
|
|
|
|
// Pi's clamp: the level itself, else the nearest above, else below.
|
|
func TestPiClamp(t *testing.T) {
|
|
for _, c := range []struct {
|
|
level string
|
|
offered []string
|
|
want string
|
|
}{
|
|
{"max", []string{"off"}, "off"},
|
|
{"max", []string{"low", "high", "max"}, "max"},
|
|
{"medium", []string{"low", "high", "max"}, "high"},
|
|
{"xhigh", []string{"off", "low", "medium", "high"}, "high"},
|
|
{"minimal", []string{"low", "high"}, "low"},
|
|
} {
|
|
if got := piClamp(c.level, c.offered); got != c.want {
|
|
t.Errorf("%s of %v: %s, want %s", c.level, c.offered, got, c.want)
|
|
}
|
|
}
|
|
}
|