codex: /fast reaches a group or model whose fast mode isn't a ChatGPT account's
cute_lynx_36404 (Discord #feedback): turning on GPT fast mode (/fast, 加速)
inside Codex did nothing through magpie; only the Routing page's fast
default worked.
Cause: Codex sends service_tier only on a model whose catalog entry lists
it (codex-rs ModelInfo::service_tier_for_request drops any other).
provider.CodexTiers listed Fast on a routing group only when a member was
a ChatGPT account's gpt- model, and on a model of its own only for
codex/gpt, a relay's GPT (OwnTier), another magpie and plugin tiers. A
group whose fast members are an OpenAI or Anthropic key, Cursor, a
plugin's priority model or a relay's GPT, and an Anthropic key's Opus on
its own, were offered no tier, so Codex never sent one. The gateway
already takes the client's service_tier per request and says it in each
member's words (priority on OpenAI/ChatGPT/relays, speed fast for Opus on
api.anthropic.com, Cursor's fast variant, a plugin's tier) or drops it
where the member has no fast mode; the Routing default went another way
(the member's own fast), which is why only it worked.
Now a group with any provider.CanFast member is offered Fast through
m.Tiers ("priority"; m.Fast still means a ChatGPT member, which also
drives MultiAgent v1), and so is a model of its own that CanFast and no
tier above names. codexcat uses the named tiers for a provider added by
address when Codex's own entry has none for it (Opus behind an address
on api.anthropic.com). The served tier is recorded as before
(TierAsked/TierSent/TierServed); magpie prices no tier differently, by
the Routing default or by the client, which this doesn't change.
Run:
- TestCodexFastOfferedWhereAMemberHasIt (new, internal/gateway): red with
CodexTiers reverted (group/hard and an/claude-opus-5-5 list no tier),
red with only the codexcat line reverted (an/claude-opus-5-5); green
now.
- go test ./internal/codexcat; -run 'Tier|Fast|Codex.*Catalog|CodexList'
in internal/provider, internal/agent, internal/gateway: ok.
- Real codex-cli 0.162.1 in a sandbox HOME/CODEX_HOME, model_provider
magpie on a fake Responses upstream, catalog from codexcat.Catalog:
group/hard (Fast listed) with service_tier="fast" sent
service_tier "priority"; without it, none; group/cheap (no fast
member) with fast on sent none.
- go test ./internal/gateway/... ./internal/agent/... ./internal/provider/...
./internal/codexcat/... -timeout 45m at this tree, on origin/main
834935149: gateway ok (513s), agent ok (310s), codexcat ok; provider
FAIL twice on TestUnreadLoginsWriteErrorsKeepCredentials, "close of
synctest channel from outside bubble" in filememo.Forget, red on main
and filed as #3632; provider with that test skipped: ok (109s).
- gofmt -l clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows
go vet ./... clean.
Not tried: the Codex desktop app's /fast toggle itself, and a real
Anthropic or OpenAI key upstream at priority.
This commit is contained in:
@@ -227,7 +227,7 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any {
|
||||
// GPT models
|
||||
if slug, ok := strings.CutPrefix(m.ID, "codex/"); m.Fast || ok && strings.HasPrefix(slug, "gpt-") {
|
||||
e.Tiers = append(e.Tiers, fastTier)
|
||||
} else if m.OwnTier {
|
||||
} else if m.OwnTier && (len(m.Tiers) == 0 || len(ownTiers(own, m)) > 0) {
|
||||
e.Tiers = ownTiers(own, m)
|
||||
} else if len(m.Tiers) > 0 {
|
||||
// another magpie's model: the tiers it offers its own Codex
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// Codex sends /fast's service_tier only on a model whose entry lists it
|
||||
// (codex-rs ModelInfo::service_tier_for_request), so a routing group or a
|
||||
// model with a fast mode that isn't a ChatGPT account's GPT is offered
|
||||
// Fast in the list too, and one with no member that has a fast mode is
|
||||
// offered none (cute_lynx_36404 on Discord: /fast did nothing through
|
||||
// magpie, only the Routing page's default did).
|
||||
func TestCodexFastOfferedWhereAMemberHasIt(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "an", Name: "Anthropic", Key: "k", Anthropic: "https://api.anthropic.com", Models: []string{"claude-opus-5-5", "claude-sonnet-5"}},
|
||||
{ID: "zp", Name: "Zhipu", Key: "k", Chat: "http://zp.invalid/v1", Models: []string{"glm-5"}},
|
||||
} {
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, g := range []provider.Group{
|
||||
{ID: "hard", Name: "Hard", Members: []string{"zp/glm-5", "an/claude-opus-5-5"}, Routing: provider.Ordered},
|
||||
{ID: "cheap", Name: "Cheap", Members: []string{"zp/glm-5", "an/claude-sonnet-5"}, Routing: provider.Ordered},
|
||||
} {
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/v1/models", nil))
|
||||
var list struct {
|
||||
Data []struct {
|
||||
ID string `json:"id"`
|
||||
Tiers []struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"service_tiers"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {
|
||||
t.Fatalf("%v: %s", err, rec.Body)
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, m := range list.Data {
|
||||
s := ""
|
||||
for _, x := range m.Tiers {
|
||||
s += x.ID + " "
|
||||
}
|
||||
got[m.ID] = s
|
||||
}
|
||||
for id, want := range map[string]string{
|
||||
"group/hard": "priority ", "group/cheap": "",
|
||||
"an/claude-opus-5-5": "priority ", "an/claude-sonnet-5": "", "zp/glm-5": "",
|
||||
} {
|
||||
if s, ok := got[id]; !ok || s != want {
|
||||
t.Errorf("%s tiers %q (listed %v), want %q; list %v", id, s, ok, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -673,11 +673,31 @@ func CodexTiers(m *catalog.Model, e Entry, members func(id string) []Member) {
|
||||
m.Tiers = e.Tiers
|
||||
}
|
||||
if e.Group != "" {
|
||||
fast := false
|
||||
for _, mb := range members(e.ID) {
|
||||
if a := mb.Provider.Account; a != nil && a.Agent == "codex" && strings.HasPrefix(mb.Model, "gpt-") {
|
||||
m.Fast = true
|
||||
break
|
||||
}
|
||||
fast = fast || CanFast(mb.Provider, mb.Model)
|
||||
}
|
||||
// a group with another member that has a fast mode (an OpenAI or
|
||||
// Anthropic key's, a relay's GPT, Cursor's, a plugin's) is offered
|
||||
// Fast too: Codex sends /fast's service_tier only on a model whose
|
||||
// entry lists it, and the gateway asks each member for it in its
|
||||
// vendor's words, or not at all where it has none (cute_lynx_36404
|
||||
// on Discord: /fast did nothing through a group)
|
||||
if !m.Fast && fast {
|
||||
m.Tiers = []string{codexFastTier}
|
||||
}
|
||||
return
|
||||
}
|
||||
// so is a model of its own that has one, which no tier above names
|
||||
// (an Anthropic key's Opus, an OpenAI key's GPT, a Cursor account's)
|
||||
if len(m.Tiers) == 0 && CanFast(e.Provider, e.Model) {
|
||||
m.Tiers = []string{codexFastTier}
|
||||
}
|
||||
}
|
||||
|
||||
// codexFastTier is Fast's service tier as Codex sends it.
|
||||
const codexFastTier = "priority"
|
||||
|
||||
Reference in New Issue
Block a user