remote-magpie/codex/gpt-6.1-sol had service_tiers [] in the local /v1/codex/models while the remote's own codex/gpt-6.1-sol had Fast: the local catalog only gave tiers to a provider added by its address (OwnTier, Preset == ""), and the gateway sent service_tier only to one. Now a remote magpie's /v1/models (asked with X-Magpie-Drawers) tells each model's service_tiers as its own Codex catalog offers them (codexcat.ServiceTiers over the same CodexCatalog/Entries as its /v1/codex/models). The local keeps the ids (catalog.Model.Tiers -> Entry.Tiers), codexListed hands them on for the remote's models, and codexcat.Entries offers them with Codex's own names. The gateway sends the tier Codex asked for to a remote magpie as it was asked (OwnTier, still dropped and remembered if refused); the remote serves it as its own Codex's turn. A remote from before this sends no tiers: unchanged. Run: - TestRemoteMagpieOffersItsTiers (gateway, the gateway as both computers over HTTP): fails without the codexListed change with `office/relay/gpt-6.1-sol offered "" ..., want "priority:Fast "`, and without the gateway change with `tier sent to the remote magpie [(none)], by it to its vendor [(none)]; want priority, priority`. - TestServiceTiersGoOnToAnotherMagpie (codexcat): a ChatGPT account's model with Codex's own entry tells priority+ultrafast, a relay's GPT Fast, glm none; fails when either the own-entry branch of ServiceTiers or the namedTiers branch of Entries is taken out. - gofmt -l clean; go vet -tags nogui for darwin, linux, windows on gateway, provider, codexcat, catalog, agent; go test -tags nogui of those five packages under a temp HOME: ok. Not tried with a real ChatGPT account behind a real remote magpie.
92 lines
3.3 KiB
Go
92 lines
3.3 KiB
Go
package codexcat
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// A model of a provider the user added by its address is offered the tiers
|
|
// Codex's own entry gives the same model, Ultrafast among them, and Fast on
|
|
// another GPT model; none on any other, nor on one not added by its address
|
|
// (hsiangron on X: Fast and Ultrafast weren't there to pick).
|
|
func TestOwnProviderTiers(t *testing.T) {
|
|
v1Home(t, `{"etag":"W/\"a\"","models":[{"slug":"gpt-6-sol","base_instructions":"x","service_tiers":[{"id":"priority","name":"Fast","description":"f"},{"id":"ultrafast","name":"Ultrafast","description":"u"}]}]}`)
|
|
ms := []catalog.Model{
|
|
{ID: "relay/gpt-6-sol", Name: "a", OwnTier: true},
|
|
{ID: "relay/gpt-6-sol-2026-09-01", Name: "b", OwnTier: true},
|
|
{ID: "relay/gpt-5.5", Name: "c", OwnTier: true},
|
|
{ID: "relay/glm-5", Name: "d", OwnTier: true},
|
|
{ID: "openrouter/gpt-6-sol", Name: "e"},
|
|
}
|
|
var got struct {
|
|
Models []struct {
|
|
Slug string `json:"slug"`
|
|
Tiers []struct {
|
|
ID string `json:"id"`
|
|
} `json:"service_tiers"`
|
|
} `json:"models"`
|
|
}
|
|
if err := json.Unmarshal(Catalog(ms), &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ids := map[string]string{}
|
|
for _, m := range got.Models {
|
|
s := ""
|
|
for _, x := range m.Tiers {
|
|
s += x.ID + " "
|
|
}
|
|
ids[m.Slug] = s
|
|
}
|
|
want := map[string]string{"relay/gpt-6-sol": "priority ultrafast ", "relay/gpt-6-sol-2026-09-01": "priority ultrafast ",
|
|
"relay/gpt-5.5": "priority ", "relay/glm-5": "", "openrouter/gpt-6-sol": ""}
|
|
for k, v := range want {
|
|
if ids[k] != v {
|
|
t.Errorf("%s offered %q, want %q", k, ids[k], v)
|
|
}
|
|
}
|
|
}
|
|
|
|
// What this magpie tells another that has it as its provider: the tiers
|
|
// its Codex is offered on each model — a ChatGPT account's own model with
|
|
// those of Codex's own entry, Ultrafast among them, a relay's GPT model
|
|
// Fast, none on any other — and that one's Codex is offered the same on
|
|
// the model, with Codex's own names (#1234).
|
|
func TestServiceTiersGoOnToAnotherMagpie(t *testing.T) {
|
|
v1Home(t, `{"etag":"W/\"a\"","models":[{"slug":"gpt-6.1-sol","base_instructions":"x","service_tiers":[{"id":"priority","name":"Fast","description":"f"},{"id":"ultrafast","name":"Ultrafast","description":"u"}]}]}`)
|
|
here := ServiceTiers([]catalog.Model{
|
|
{ID: "codex/gpt-6.1-sol", Name: "a"},
|
|
{ID: "relay/gpt-5.5", Name: "b", OwnTier: true},
|
|
{ID: "relay/glm-5", Name: "c", OwnTier: true},
|
|
})
|
|
ids := func(ts []tier) string {
|
|
s := ""
|
|
for _, x := range ts {
|
|
s += x.ID + ":" + x.Name + " "
|
|
}
|
|
return s
|
|
}
|
|
want := map[string]string{"codex/gpt-6.1-sol": "priority:Fast ultrafast:Ultrafast ", "relay/gpt-5.5": "priority:Fast ", "relay/glm-5": ""}
|
|
for k, v := range want {
|
|
if got := ids(here[k]); got != v {
|
|
t.Errorf("%s tells %q, want %q", k, got, v)
|
|
}
|
|
}
|
|
var there []catalog.Model
|
|
for _, id := range []string{"codex/gpt-6.1-sol", "relay/glm-5"} {
|
|
var list []string
|
|
for _, x := range here[id] {
|
|
list = append(list, x.ID)
|
|
}
|
|
there = append(there, catalog.Model{ID: "office/" + id, Name: id, Tiers: list})
|
|
}
|
|
got := ServiceTiers(there)
|
|
if s := ids(got["office/codex/gpt-6.1-sol"]); s != "priority:Fast ultrafast:Ultrafast " {
|
|
t.Errorf("the other magpie's Codex offered %q", s)
|
|
}
|
|
if s := ids(got["office/relay/glm-5"]); s != "" {
|
|
t.Errorf("a model offered no tier there is offered %q", s)
|
|
}
|
|
}
|