diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index 900abf5a7..f92b14ffa 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -287,6 +287,9 @@ type mdModel struct { ID string `json:"id"` Name string `json:"name"` ReleaseDate string `json:"release_date"` + // Family is the line models.dev puts the model in (gpt-sol, mimo): + // the levels a new one it lists without any most likely takes + Family string `json:"family"` Temperature *bool `json:"temperature"` // false: rejects temperature/top_p Thinks bool `json:"reasoning"` Reasoning []struct { @@ -326,6 +329,34 @@ func (m mdModel) efforts() []string { return out } +// levels are the reasoning levels p gives m: its own, else, for one it +// says thinks but lists without levels — a model just added, as OpenAI's +// gpt-6.1-sol was (NextCommit on Discord) — those of the newest of p's +// thinking models of its family released by then (gpt-6-sol's). A family +// whose models all take a thinking switch alone (Xiaomi's mimo) gives +// none, as before (#214). +func (p mdProvider) levels(m mdModel) []string { + if e := m.efforts(); len(e) > 0 || !m.Thinks || m.Family == "" || m.budgeted() { + return e + } + var kin *mdModel + for _, x := range p.Models { + if x.Family != m.Family || !x.Thinks || x.ID == m.ID || len(x.efforts()) == 0 { + continue + } + if m.ReleaseDate != "" && x.ReleaseDate > m.ReleaseDate { + continue + } + if kin == nil || x.ReleaseDate > kin.ReleaseDate || x.ReleaseDate == kin.ReleaseDate && x.ID > kin.ID { + kin = &x + } + } + if kin == nil { + return nil + } + return kin.efforts() +} + // window is the tokens a prompt to m may hold: the input limit where // models.dev gives one (gpt-5's 272K of its 400K), else the whole context. // A row whose input limit sits above its window (Cloudflare AI Gateway's @@ -734,7 +765,7 @@ func Provider(id string) []Model { mm := Model{ID: m.ID, Name: m.Name, Provider: id, Released: m.ReleaseDate, Price: m.Cost, Temperature: m.Temperature, Images: slices.Contains(m.Modalities.Input, "image"), ImageInput: imageInput(m.Modalities.Input), Context: m.window(), Output: m.Limit.Output, InputModalities: m.Modalities.Input, OutputModalities: m.Modalities.Output} - mm.Efforts = m.efforts() + mm.Efforts = p.levels(m) mm.Reasoning = m.Thinks || len(mm.Efforts) > 0 out = append(out, mm) } @@ -1007,7 +1038,7 @@ func ListedBy(providers []string, id string) ([]string, bool) { if bareID(key) != want { continue } - if e := m.efforts(); len(e) > 0 || !m.budgeted() { + if e := all[pid].levels(m); len(e) > 0 || !m.budgeted() { return slices.Clone(e), true } } @@ -1016,6 +1047,56 @@ func ListedBy(providers []string, id string) ([]string, bool) { return nil, false } +// KinEfforts are the reasoning levels of a model none of the providers +// named lists, taken from the newest of their thinking models of the same +// name but for its version (gpt-6.1-sol's from gpt-6-sol, mimo-v2.7-flash's +// from mimo-v2.6-flash): a model newer than the catalog on this machine +// offers its line's levels, not none. False when none of them has one. +func KinEfforts(providers []string, id string) ([]string, bool) { + all := load() + shape, ok := versionless(bareID(id)) + if !ok { + return nil, false + } + var ( + levels []string + newest, from, name string + found bool + ) + for _, pid := range providers { + for key, m := range all[pid].Models { + if !m.Thinks && len(m.efforts()) == 0 || m.budgeted() { + continue + } + if s, ok := versionless(bareID(key)); !ok || s != shape { + continue + } + // the newest; of two the same day, the first provider's, then + // the greater id, whatever order the map gives + if !found || m.ReleaseDate > newest || m.ReleaseDate == newest && pid == from && key > name { + levels, newest, from, name, found = all[pid].levels(m), m.ReleaseDate, pid, key, true + } + } + } + return slices.Clone(levels), found +} + +// versionless is a model id with each of its version parts (6.1, v2.6) as +// "#", and whether it has one beside a name: gpt-#-sol. +func versionless(b string) (string, bool) { + parts := strings.Split(b, "-") + versioned, named := false, false + for i, s := range parts { + v := strings.TrimPrefix(s, "v") + if v != "" && strings.Trim(v, "0123456789.") == "" && v[0] != '.' { + parts[i], versioned = "#", true + } else { + named = true + } + } + return strings.Join(parts, "-"), versioned && named +} + // budgeted reports whether models.dev says the model takes a thinking // budget. func (m mdModel) budgeted() bool { diff --git a/internal/catalog/catalog_test.go b/internal/catalog/catalog_test.go index de1d64f2b..a4d035561 100644 --- a/internal/catalog/catalog_test.go +++ b/internal/catalog/catalog_test.go @@ -234,6 +234,65 @@ func TestListedBy(t *testing.T) { } } +// A model listed as thinking with no levels yet takes those of the newest +// of its family released by then (gpt-6.1-sol's from gpt-6-sol, not from +// the later gpt-7-sol), and a model the catalog doesn't list those of the +// newest of the same name but for its version. A family that takes a +// thinking switch alone gives none (#214), a budgeted model is left alone, +// and one that doesn't think takes none. +func TestFamilyLevels(t *testing.T) { + writeCatalog(t, `{ + "openai": {"models": { + "gpt-6.1-sol": {"id":"gpt-6.1-sol","family":"gpt-sol","reasoning":true,"release_date":"2026-09-29"}, + "gpt-6-sol": {"id":"gpt-6-sol","family":"gpt-sol","reasoning":true,"release_date":"2026-09-22","reasoning_options":[{"type":"effort","values":["none","low","medium","high","xhigh","max"]}]}, + "gpt-5.6-sol": {"id":"gpt-5.6-sol","family":"gpt-sol","reasoning":true,"release_date":"2026-07-09","reasoning_options":[{"type":"effort","values":["none","low","medium","high"]}]}, + "gpt-7-sol": {"id":"gpt-7-sol","family":"gpt-sol","reasoning":true,"release_date":"2027-01-01","reasoning_options":[{"type":"effort","values":["low","max"]}]}, + "gpt-4.1": {"id":"gpt-4.1","family":"gpt","release_date":"2025-04-14"}}}, + "xiaomi": {"models": { + "mimo-v2.6-flash": {"id":"mimo-v2.6-flash","family":"mimo","reasoning":true,"release_date":"2026-09-22","reasoning_options":[{"type":"toggle"}]}, + "mimo-v2.5": {"id":"mimo-v2.5","family":"mimo","reasoning":true,"release_date":"2026-04-22"}}}, + "anthropic": {"models": { + "claude-sonnet-4-5": {"id":"claude-sonnet-4-5","family":"claude-sonnet","reasoning":true,"reasoning_options":[{"type":"budget_tokens"}]}, + "claude-sonnet-4": {"id":"claude-sonnet-4","family":"claude-sonnet","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","high"]}]}}} + }`) + makers := []string{"anthropic", "openai", "xiaomi"} + for _, c := range []struct { + id, want string + ok bool + }{ + {"gpt-6.1-sol", "none,low,medium,high,xhigh,max", true}, + {"openai/GPT-6.1-Sol", "none,low,medium,high,xhigh,max", true}, + {"gpt-4.1", "", true}, + {"mimo-v2.6-flash", "", true}, + {"claude-sonnet-4-5", "", false}, + } { + got, ok := ListedBy(makers, c.id) + if strings.Join(got, ",") != c.want || ok != c.ok { + t.Errorf("ListedBy(%q) = %v, %v; want %q, %v", c.id, got, ok, c.want, c.ok) + } + } + for _, m := range Provider("openai") { + if m.ID == "gpt-6.1-sol" && (strings.Join(m.Efforts, ",") != "none,low,medium,high,xhigh,max" || !m.Reasoning) { + t.Errorf("Provider(openai)'s gpt-6.1-sol: %v, reasoning %v", m.Efforts, m.Reasoning) + } + } + for _, c := range []struct { + id, want string + ok bool + }{ + {"gpt-7.1-sol", "low,max", true}, + {"relay/gpt-7.1-sol", "low,max", true}, + {"mimo-v2.7-flash", "", true}, + {"gpt-7.1-terra", "", false}, + {"sol", "", false}, + } { + got, ok := KinEfforts(makers, c.id) + if strings.Join(got, ",") != c.want || ok != c.ok { + t.Errorf("KinEfforts(%q) = %v, %v; want %q, %v", c.id, got, ok, c.want, c.ok) + } + } +} + func TestFetchedImageCapabilityOverridesCatalog(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") diff --git a/internal/provider/family_efforts_test.go b/internal/provider/family_efforts_test.go new file mode 100644 index 000000000..48f2bbb99 --- /dev/null +++ b/internal/provider/family_efforts_test.go @@ -0,0 +1,135 @@ +package provider + +import ( + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/codexcat" +) + +// newModelCatalog is models.dev as it listed gpt-6.1-sol the day it was +// added: OpenAI's entry says it thinks, with no levels yet, while its +// family's gpt-6-sol and gpt-6-astra have theirs; Xiaomi's mimo line takes +// a thinking switch alone. +const newModelCatalog = `{ + "openai": {"models": { + "gpt-6.1-sol": {"id":"gpt-6.1-sol","family":"gpt-sol","reasoning":true,"release_date":"2026-09-29"}, + "gpt-6-sol": {"id":"gpt-6-sol","family":"gpt-sol","reasoning":true,"release_date":"2026-09-22","reasoning_options":[{"type":"effort","values":["none","low","medium","high","xhigh","max"]}]}, + "gpt-5.6-sol": {"id":"gpt-5.6-sol","family":"gpt-sol","reasoning":true,"release_date":"2026-07-09","reasoning_options":[{"type":"effort","values":["none","low","medium","high","xhigh"]}]}, + "gpt-6-astra": {"id":"gpt-6-astra","family":"gpt-astra","reasoning":true,"release_date":"2026-09-04","reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh","max"]}]}, + "gpt-4.1": {"id":"gpt-4.1","family":"gpt","reasoning":false,"release_date":"2025-04-14"}}}, + "xiaomi": {"models": { + "mimo-v2.6-flash": {"id":"mimo-v2.6-flash","family":"mimo","reasoning":true,"release_date":"2026-09-22","reasoning_options":[{"type":"toggle"}]}, + "mimo-v2.5": {"id":"mimo-v2.5","family":"mimo","reasoning":true,"release_date":"2026-04-22"}}}, + "requesty": {"models": { + "gpt-6.1-sol": {"id":"gpt-6.1-sol","reasoning":true}}} +}` + +func newModelHome(t *testing.T) { + t.Helper() + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(catalog.CachePath(), []byte(newModelCatalog), 0o644); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) +} + +// A model models.dev has just added, listed as thinking but without its +// levels yet, offers its family's (NextCommit on Discord: a relay's +// gpt-6.1-sol had no effort picker in Codex, gpt-6-astra had one), and so +// does one newer than the catalog on this machine. A family that takes a +// thinking switch alone still offers none (#214), and a model that doesn't +// reason none either. +func TestNewModelTakesItsFamilysLevels(t *testing.T) { + newModelHome(t) + if err := Save(Provider{ID: "relay", Name: "Relay", Chat: "https://relay.test/v1", Key: "k", + Models: []string{"gpt-6.1-sol", "gpt-6-astra", "gpt-6.2-sol", "mimo-v2.6-flash", "mimo-v2.7-flash", "gpt-4.1"}}); err != nil { + t.Fatal(err) + } + if err := catalog.SaveLive("relay", "https://relay.test/v1", []catalog.Model{ + {ID: "gpt-6.1-sol"}, {ID: "gpt-6-astra"}, {ID: "gpt-6.2-sol"}, {ID: "mimo-v2.6-flash"}, {ID: "mimo-v2.7-flash"}, {ID: "gpt-4.1"}}); err != nil { + t.Fatal(err) + } + openai, err := FromPreset("openai") + if err != nil { + t.Fatal(err) + } + openai.Key, openai.Models = "k", []string{"gpt-6.1-sol"} + if err := Save(openai); err != nil { + t.Fatal(err) + } + sol := "none,low,medium,high,xhigh,max" + got := map[string]string{} + for _, e := range Catalog() { + // without Codex's ultra, added where OpenAI offers it (ultra.go) + got[e.ID] = strings.TrimSuffix(strings.Join(e.Efforts, ","), ",ultra") + } + for id, want := range map[string]string{ + "relay/gpt-6.1-sol": sol, + "relay/gpt-6-astra": "low,medium,high,xhigh,max", + "relay/gpt-6.2-sol": sol, // newer than the catalog + "relay/mimo-v2.6-flash": "", + "relay/mimo-v2.7-flash": "", + "relay/gpt-4.1": "", + openai.ID + "/gpt-6.1-sol": sol, + } { + if g, ok := got[id]; !ok || g != want { + t.Errorf("%s: levels %q (listed %v), want %q", id, g, ok, want) + } + } + relay, err := Find("relay") + if err != nil { + t.Fatal(err) + } + if k := strings.Join(relay.Known("gpt-6.1-sol"), ","); k != sol { + t.Errorf("Known(gpt-6.1-sol) = %q, want %q", k, sol) + } + if relay.Levelless("gpt-6.1-sol") { + t.Error("gpt-6.1-sol reads as having no levels") + } + if !relay.Levelless("mimo-v2.6-flash") { + t.Error("mimo-v2.6-flash reads as having levels") + } + + // what Codex is handed: the picker's levels and a default + var cat struct { + Models []struct { + Slug string `json:"slug"` + Levels []struct { + Effort string `json:"effort"` + } `json:"supported_reasoning_levels"` + } `json:"models"` + } + if err := json.Unmarshal(codexcat.Catalog(CodexListed()), &cat); err != nil { + t.Fatal(err) + } + found := false + for _, m := range cat.Models { + if m.Slug != "relay/gpt-6.1-sol" { + continue + } + found = true + var ls []string + for _, l := range m.Levels { + ls = append(ls, l.Effort) + } + if strings.TrimSuffix(strings.Join(ls, ","), ",ultra") != sol { + t.Errorf("Codex's levels for relay/gpt-6.1-sol: %v, want %s", ls, sol) + } + } + if !found { + t.Error("relay/gpt-6.1-sol isn't in Codex's catalog") + } +} diff --git a/internal/provider/models.go b/internal/provider/models.go index ce51a89c6..b5c53db4a 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -979,7 +979,9 @@ func (p Provider) Levelless(model string) bool { // lists them, or — for a vendor models.dev doesn't list the model under (a // custom provider, a proxy) — its maker's, else the ones the others serving // it give. A model models.dev lists for this vendor without levels takes -// none: the vendor says it has none to pick from. +// none: the vendor says it has none to pick from — unless it says the +// model thinks and lists its family with levels (catalog's levels: a model +// just added, gpt-6.1-sol). func effortsOf(m catalog.Model) []string { if len(m.Efforts) > 0 || m.Provider != "" { return m.Efforts @@ -991,12 +993,20 @@ func effortsOf(m catalog.Model) []string { // word on: its maker's, when a vendor of magpie's presets makes it — none // for Xiaomi's mimo-v2.6-flash, which takes a thinking switch alone and // turns away the max resellers list for it (#214) — else those most of the -// providers giving any give it (a Volcengine endpoint's glm-5.3-flash). +// providers giving any give it (a Volcengine endpoint's glm-5.3-flash), +// else, for one newer than the catalog, its maker's line's +// (catalog.KinEfforts). func borrowedEfforts(id string) []string { if e, ok := catalog.ListedBy(makerCatalogs(), id); ok { return e } - return catalog.EffortsOf(id) + if e := catalog.EffortsOf(id); len(e) > 0 { + return e + } + // one newer than this machine's catalog: its maker's line's levels + // (gpt-6.1-sol, NextCommit on Discord) + e, _ := catalog.KinEfforts(makerCatalogs(), id) + return e } // makerCatalogs are the models.dev ids of the vendors among the presets