diff --git a/internal/gateway/search.go b/internal/gateway/search.go index b3c957fee..8caf435fc 100644 --- a/internal/gateway/search.go +++ b/internal/gateway/search.go @@ -602,6 +602,21 @@ func smallCands(p provider.Provider, keep func(catalog.Model) bool) []smallCand continue } } + if m.ID == provider.CodexAutoReview { + // Codex's reviewer, priced free for the reviews it runs, not + // a model to ask anything else of + continue + } + if m.Price == nil { + // a subscription's list carries no prices: Codex's starts + // with its flagship, gpt-6.1-sol, which every search and + // every image was asked of while gpt-6-luna sat below it + // (lucy_85908 on Discord). Its list price, as the Usage + // page counts it, says which is the cheap one + if pr, ok := p.ListPrice(m.ID); ok { + m.Price = &pr + } + } ms = append(ms, m) } return rankSmall(ms) @@ -628,6 +643,10 @@ func keptSmallCands(p provider.Provider, kind string, keep func(catalog.Model) b return smallKept.get(k, func() []smallCand { return smallCands(p, keep) }) } +// smallWords name a vendor's small tier: GPT-6's is Luna, the list has +// no mini (#604). +var smallWords = []string{"haiku", "mini", "flash", "luna"} + // rankSmall is ms in the order smallModel picks them, each one's pick of // those after it: on a router, a model of the big vendors first; then a // small one; then the cheaper; then the one listed first. @@ -648,7 +667,7 @@ func rankSmall(ms []catalog.Model) []smallCand { } rs[i] = ranked{smallCand{m.ID, cost}, ok && !slices.Contains([]string{"anthropic", "openai", "google", "x-ai"}, v), - !strings.Contains(l, "haiku") && !strings.Contains(l, "mini") && !strings.Contains(l, "flash")} + !slices.ContainsFunc(smallWords, func(w string) bool { return strings.Contains(l, w) })} } slices.SortStableFunc(rs, func(a, b ranked) int { if c := falseFirst(a.router, b.router); c != 0 { diff --git a/internal/gateway/search_codex_small_test.go b/internal/gateway/search_codex_small_test.go new file mode 100644 index 000000000..ad80a2b95 --- /dev/null +++ b/internal/gateway/search_codex_small_test.go @@ -0,0 +1,67 @@ +package gateway + +import ( + "testing" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" + "github.com/yetone/magpie/internal/settings" +) + +// A Codex account searches for a model that can't with its cheap model, +// not the flagship its list starts with: lucy_85908 (Discord, v0.1.2682) +// saw every search for a third-party model in Codex go to gpt-6.1-sol, +// 10,532 tokens in, on the Codex account's allowance. The list carries no +// prices, so the first was picked; the list price models.dev gives the +// models says gpt-6-luna is the cheap one. Without a catalog at all, a +// luna is GPT-6's small tier, as a mini is. A model the user names in +// Settings is still the one asked. +func TestCodexSearchesWithItsCheapModel(t *testing.T) { + codexSignedIn(t) + list := []catalog.Model{{ID: "gpt-6.1-sol"}, {ID: "gpt-6-astra"}, {ID: "gpt-6-sol"}, {ID: "gpt-6-luna"}, {ID: "gpt-5.6-sol"}, {ID: provider.CodexAutoReview}} + if err := catalog.SaveLive("codex", provider.CodexBase, list); err != nil { + t.Fatal(err) + } + pick := func() (string, string) { + p, m, ok := searcher() + if !ok { + t.Fatal("no searcher with a Codex account signed in") + } + return p.ID, m + } + + // no catalog: by the name + catalog.Reset() + if id, m := pick(); id != "codex" || m != "gpt-6-luna" { + t.Fatalf("searcher = %s/%s with no catalog, want codex/gpt-6-luna", id, m) + } + + // priced: the cheapest, whatever its name + writeCatalog(t, `{"openai":{"id":"openai","models":{ + "gpt-6.1-sol":{"id":"gpt-6.1-sol","cost":{"input":5,"output":30}}, + "gpt-6-astra":{"id":"gpt-6-astra","cost":{"input":10,"output":50}}, + "gpt-6-sol":{"id":"gpt-6-sol","cost":{"input":2.5,"output":15}}, + "gpt-6-luna":{"id":"gpt-6-luna","cost":{"input":0.25,"output":2}}, + "gpt-5.6-sol":{"id":"gpt-5.6-sol","cost":{"input":1.25,"output":10}}, + "gpt-5.6-luna":{"id":"gpt-5.6-luna","cost":{"input":0.1,"output":0.4}}}}}`) + if id, m := pick(); id != "codex" || m != "gpt-6-luna" { + t.Fatalf("searcher = %s/%s priced, want codex/gpt-6-luna", id, m) + } + // a list with no small tier: the cheapest by its price, not the first + if err := catalog.SaveLive("codex", provider.CodexBase, list[:3]); err != nil { + t.Fatal(err) + } + if id, m := pick(); id != "codex" || m != "gpt-6-sol" { + t.Fatalf("searcher = %s/%s priced with no luna, want the cheapest, codex/gpt-6-sol", id, m) + } + + // the user's own pick wins + st := settings.Load() + st.Searcher = "codex/gpt-6.1-sol" + if err := settings.Save(st); err != nil { + t.Fatal(err) + } + if id, m := pick(); id != "codex" || m != "gpt-6.1-sol" { + t.Fatalf("searcher = %s/%s, want the one Settings names, codex/gpt-6.1-sol", id, m) + } +} diff --git a/internal/gateway/small_kept_test.go b/internal/gateway/small_kept_test.go index 7b065ec10..52f792c95 100644 --- a/internal/gateway/small_kept_test.go +++ b/internal/gateway/small_kept_test.go @@ -276,7 +276,7 @@ func TestRankSmallIsPickSmall(t *testing.T) { } small := slices.DeleteFunc(slices.Clone(ms), func(m catalog.Model) bool { l := strings.ReplaceAll(strings.ToLower(m.ID), "gemini", "") - return !strings.Contains(l, "haiku") && !strings.Contains(l, "mini") && !strings.Contains(l, "flash") + return !strings.Contains(l, "haiku") && !strings.Contains(l, "mini") && !strings.Contains(l, "flash") && !strings.Contains(l, "luna") }) if id := cheapest(small); id != "" { return id @@ -285,7 +285,7 @@ func TestRankSmallIsPickSmall(t *testing.T) { } r := rand.New(rand.NewPCG(1, 2)) vendors := []string{"", "anthropic/", "openai/", "google/", "x-ai/", "meta/", "qwen/"} - names := []string{"claude-haiku-5", "gpt-6-mini", "gemini-3-flash", "gemini-3-pro", "big", "o9", "llama"} + names := []string{"claude-haiku-5", "gpt-6-mini", "gemini-3-flash", "gemini-3-pro", "gpt-6-luna", "big", "o9", "llama"} for range 2000 { var ms []catalog.Model for i := range r.IntN(8) + 1 {