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.
85 lines
3.3 KiB
Go
85 lines
3.3 KiB
Go
package provider
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// #597: a routing group of DeepSeek V4 Pro on Tencent's TokenHub and on its
|
|
// Token Plan (deepseek-v4-pro-202606, which nothing magpie reads knows)
|
|
// offered no reasoning levels, so Pi listed off alone for it and ran it
|
|
// without reasoning while magpie showed max. A model a provider serves that
|
|
// its vendor's list leaves out takes the levels the gateway fits an effort
|
|
// to (Provider.Efforts), and a member whose levels nothing knows takes
|
|
// whatever the agent asks rather than taking the others' away. A member
|
|
// known to have none still does.
|
|
func TestGroupLevelsWithUnknownMember(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", t.TempDir())
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
cache := t.TempDir()
|
|
t.Setenv("XDG_CACHE_HOME", cache)
|
|
os.MkdirAll(filepath.Join(cache, "magpie"), 0o755)
|
|
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}}}},
|
|
"tencent-tokenhub": {"models": {"hy3": {"id":"hy3","reasoning":true,"reasoning_options":[{"type":"effort","values":["none","high"]}]}}},
|
|
"plaincat": {"models": {"plain-chat": {"id":"plain-chat","limit":{"context":128000}}}}
|
|
}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
for _, p := range []Provider{
|
|
// TokenHub's models.dev list has its Hy models alone
|
|
{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"}},
|
|
{ID: "pl", Name: "Plain", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "plaincat", Models: []string{"plain-chat"}},
|
|
} {
|
|
if err := Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
want := []string{"low", "high", "max"}
|
|
entry := func(id string) Entry {
|
|
t.Helper()
|
|
e, ok := EntryOf(id)
|
|
if !ok {
|
|
t.Fatalf("%s not listed", id)
|
|
}
|
|
return e
|
|
}
|
|
// the catalog and the gateway agree on the model's levels
|
|
p, _ := Find("th")
|
|
if got := p.Efforts("deepseek-v4-pro"); !slices.Equal(got, want) {
|
|
t.Fatalf("gateway's levels: %v", got)
|
|
}
|
|
if e := entry("th/deepseek-v4-pro"); !slices.Equal(e.Efforts, want) {
|
|
t.Fatalf("catalog's levels: %v", e.Efforts)
|
|
}
|
|
for name, members := range map[string][]string{
|
|
"ds": {"tp/deepseek-v4-pro-202606", "th/deepseek-v4-pro"},
|
|
"plain": {"th/deepseek-v4-pro", "pl/plain-chat"},
|
|
"tp": {"tp/deepseek-v4-pro-202606"},
|
|
} {
|
|
if err := SaveGroup(Group{Name: name, Members: members}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if e := entry("group/ds"); !slices.Equal(e.Efforts, want) || !e.Reasoning {
|
|
t.Fatalf("ds: levels %v, reasoning %v", e.Efforts, e.Reasoning)
|
|
}
|
|
// a member listed without levels still takes them away, and a group
|
|
// of models nothing knows offers none
|
|
if e := entry("group/plain"); len(e.Efforts) != 0 {
|
|
t.Fatalf("plain: levels %v", e.Efforts)
|
|
}
|
|
if e := entry("group/tp"); len(e.Efforts) != 0 {
|
|
t.Fatalf("tp: levels %v", e.Efforts)
|
|
}
|
|
}
|