gateway: a routing group named for a model is listed by that id when the model's own row isn't (小八 on Discord)
v0.1.4377, Settings › Network and sharing › Model ids without the provider = Only: group/glm-5.2, group/glm-5.3, group/glm-5.3-flash, group/deepseek-v4.1-flash-1017 and group/sensenova-6.8-flash kept their prefix while other groups lost it (3126b0bac). Each is a group the user made, named for a model a provider serves. Cause: groupBare refused a group's own id whenever any provider entry (providerEntries, not the shown list) served a model by it, on the reasoning that the provider's glm-5.2 row would carry the bare id to the group. That row isn't always shown: a group that lists its members alone (Group.Unlists), a provider kept for routing groups (Provider.Unlisted) and an agent's hidden models all keep it out of /v1/models. Then nothing carried glm-5.2, and the group stayed group/glm-5.2. The check is gone. bareTarget already requires that a request for the id reaches this very group (the gateway routes a bare id GroupFor before Resolve: groupForIn tries a group of that exact id first), and when the model row is shown its bare id reaches the group first (BareEntries' reached), so the id is still listed once. The other way it could stay prefixed, a shown row whose ID is already "glm-5.2" (ids[id]), isn't real: every provider entry's ID is provider/model (sharedEntry) and every group's is group/<id>. Run (mote, mote-run, waited for load under its cores; at4a1ac8442+ this change, origin/main unchanged since): - go test -timeout 45m -count=1 ./internal/provider ./internal/gateway: ok (158s, 1158s) - GOOS=linux go vet -tags nogui ./...: ok; GOOS=windows go vet ./...: ok - gofmt -l on the changed Go files: nothing Broken by hand: the new TestBareIDsListGroupNamedForAModel (a group glm-5.2 of b/glm-5.2 and a/glm-5.2, listing its members alone) at the old bare.go fails "on: [group/glm-5.2 auto/glm-5.2 a/other-a other-a], want glm-5.2 once". With the fix, under Only glm-5.2 is listed once in group/glm-5.2's place, GET /v1/models/glm-5.2 answers, and a chat request for glm-5.2 (and group/glm-5.2) reaches the group's first member, b, not a as Resolve would. Not tried: 小八's own providers.json (which of the three ways hides their model rows is not known; Unlists is the one tested); a real client against a running magpie; the full ./... suite and the GUI suite (no GUI file changed); Windows and Linux runs beyond vet.
This commit is contained in:
@@ -3013,12 +3013,17 @@ the row of the entry that id reaches, with its label, under the bare id.
|
||||
not listed twice.
|
||||
- A routing group the user made is listed by its own id too, `fast` beside
|
||||
`group/fast` (`groupBare`; 小八 on Discord), after the models' bare ids,
|
||||
and under Only in `group/fast`'s place. Only where that id is the
|
||||
group's alone: not when a provider serves a model by it (that model's
|
||||
bare id is listed, reaching the group as `GroupFor` routes it), when it
|
||||
is listed already, when `GroupFor` of it reaches another group, or for a
|
||||
group magpie found (its `auto/<model>` row is listed under the model's
|
||||
bare id already). A group a model's bare id already reaches adds nothing.
|
||||
and under Only in `group/fast`'s place. Only where a request for that
|
||||
id reaches the group: not when it is listed already, when `GroupFor` of
|
||||
it reaches another group, or for a group magpie found (its
|
||||
`auto/<model>` row is listed under the model's bare id already). A
|
||||
group a model's bare id already reaches adds nothing: a group named for
|
||||
a model a provider serves, `glm-5.2`, is listed through that model's
|
||||
row while the row is shown, and by its own row when it isn't (the
|
||||
group lists its members alone, a provider kept for routing groups, the
|
||||
agent's hidden models), since `GroupFor` takes `glm-5.2` to the group
|
||||
before `Resolve` either way. Before, such a group stayed `group/glm-5.2`
|
||||
under Only (小八 on Discord, v0.1.4377).
|
||||
- The target must be in the list shown: a gateway key held to some models
|
||||
sees only the bare ids that reach one of its models, so a key held to
|
||||
`b/*` doesn't see `glm-5.3` that would go to `a`.
|
||||
|
||||
@@ -123,3 +123,74 @@ func TestBareIDsListUserGroups(t *testing.T) {
|
||||
t.Fatalf("group/fast under Only: %d by %q", code, by)
|
||||
}
|
||||
}
|
||||
|
||||
// 小八 on Discord, v0.1.4377: with Only on, group/glm-5.2 stayed while
|
||||
// other groups lost the prefix. Each such group is named for a model a
|
||||
// provider serves, and its members are listed through the group alone
|
||||
// (Group.Unlists), so no provider's glm-5.2 row is shown to carry the
|
||||
// bare id. A request for glm-5.2 reaches the group all the same (GroupFor
|
||||
// before Resolve), so the group is listed as glm-5.2, in its place.
|
||||
func TestBareIDsListGroupNamedForAModel(t *testing.T) {
|
||||
fresh(t)
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "a", Name: "A", Key: "k", Models: []string{"glm-5.2", "other-a"}},
|
||||
{ID: "b", Name: "B", Key: "k", Models: []string{"glm-5.2"}},
|
||||
} {
|
||||
f := &fake{t: t, ctype: "application/json", reply: `{"id":"from-` + p.ID + `","choices":[{"index":0,"message":{"role":"assistant","content":"hi"},"finish_reason":"stop"}]}`}
|
||||
up := httptest.NewServer(f)
|
||||
t.Cleanup(up.Close)
|
||||
p.Chat = up.URL + "/v1"
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// b first: a request that went by Resolve instead would reach a
|
||||
g := provider.Group{ID: "glm-5.2", Name: "GLM 5.2", Members: []string{"b/glm-5.2", "a/glm-5.2"}, Routing: provider.Ordered, Unlists: true}
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
get := func() []string { return listedIDs(t, httptest.NewRequest("GET", "/v1/models", nil)) }
|
||||
count := func(ids []string, id string) int {
|
||||
n := 0
|
||||
for _, x := range ids {
|
||||
if x == id {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
off := get()
|
||||
if !slices.Contains(off, "group/glm-5.2") || slices.Contains(off, "a/glm-5.2") || slices.Contains(off, "b/glm-5.2") {
|
||||
t.Fatalf("off: %v, want group/glm-5.2 and no member listed", off)
|
||||
}
|
||||
|
||||
if err := provider.SetBareIDs(true, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if on := get(); count(on, "glm-5.2") != 1 {
|
||||
t.Fatalf("on: %v, want glm-5.2 once", on)
|
||||
}
|
||||
|
||||
if err := provider.SetBareIDs(true, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
only := get()
|
||||
if slices.Contains(only, "group/glm-5.2") {
|
||||
t.Fatalf("Only: %v still lists group/glm-5.2", only)
|
||||
}
|
||||
if i, j := slices.Index(off, "group/glm-5.2"), slices.Index(only, "glm-5.2"); i != j || count(only, "glm-5.2") != 1 {
|
||||
t.Fatalf("Only: glm-5.2 at %d of %v, want once where group/glm-5.2 was, %d of %v", j, only, i, off)
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/v1/models/glm-5.2", nil))
|
||||
if rec.Code != 200 || !strings.Contains(rec.Body.String(), `"id":"glm-5.2"`) {
|
||||
t.Fatalf("GET /v1/models/glm-5.2: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
for _, m := range []string{"glm-5.2", "group/glm-5.2"} {
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/chat/completions", strings.NewReader(`{"model":"`+m+`","messages":[{"role":"user","content":"hi"}]}`)))
|
||||
if by := rec.Header().Get("X-Magpie-Provider"); rec.Code != 200 || by != "b" {
|
||||
t.Fatalf("%s: %d by %q, want the group's first member, b: %s", m, rec.Code, by, rec.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ import (
|
||||
// a model the list doesn't show (a gateway key held to other models, an
|
||||
// id like anthropic/claude-x that names a provider of the user's), isn't
|
||||
// listed by it. A routing group the user made is listed by its own id as
|
||||
// well (fast for group/fast), where nothing else goes by that id.
|
||||
// well (fast for group/fast, glm-5.2 for group/glm-5.2), where a
|
||||
// request for that id reaches the group.
|
||||
|
||||
// BareModelIDs says whether /v1/models lists models by their bare ids too.
|
||||
func BareModelIDs() bool { return settings.Shared().BareModelIDs }
|
||||
@@ -104,19 +105,21 @@ func BareEntries(shown []Entry) []Bare {
|
||||
// a request for it reaches it by: its own id, fast. Only where that is
|
||||
// unambiguous: not for a group magpie found (listed under its model's
|
||||
// bare id already, or by its auto/<model>), nor by an id listed already
|
||||
// or given to another row, one a provider serves a model by, or one
|
||||
// GroupFor takes elsewhere.
|
||||
// or given to another row, or one GroupFor takes elsewhere.
|
||||
//
|
||||
// A group named for a model a provider serves (glm-5.2) is listed so
|
||||
// too: a request for glm-5.2 reaches the group, GroupFor before Resolve,
|
||||
// whether or not the provider's glm-5.2 row is shown. When it is, that
|
||||
// row's bare id reaches the group first (BareEntries' reached); when it
|
||||
// isn't (the group lists its members alone, Group.Unlists; a provider
|
||||
// kept for routing groups; the agent's hidden models), the group's own
|
||||
// row carries the id, or Only left group/glm-5.2 (小八 on Discord).
|
||||
func groupBare(shown []Entry, all []Group, entries []Entry, ids, seen map[string]bool, j int) (Bare, bool) {
|
||||
e := shown[j]
|
||||
id := e.Group
|
||||
if !e.Named || id == "" || e.ID != GroupPrefix+id || strings.Contains(id, "/") || ids[id] || seen[id] {
|
||||
return Bare{}, false
|
||||
}
|
||||
for _, x := range entries {
|
||||
if x.Model == id || x.ID == id {
|
||||
return Bare{}, false
|
||||
}
|
||||
}
|
||||
if i := bareTarget(shown, all, entries, id); i < 0 || shown[i].Group != id {
|
||||
return Bare{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user