gateway: a key held to some models gets its model list as fast as one held to none, its groups read once a list, not once a group (#1762, LumenXY on X)
LumenXY's /v1/models over Tailscale took 12.4s with a gateway key held to
some models and 1.5s with an unheld one, so apps that list models timed
out and showed an empty list.
Cause (pprof, 1,000 models, 500 found groups): keyAllowed checked each
catalog entry on its own. Each group entry called provider.FindGroup,
which builds a new GroupFinder, so every provider's models were read again
(providerEntries, its files stat'ed and settings loaded) once a group.
That was 96% of the request. Each glob in the key's models was also
compiled to a regexp on every check, and a key held to accounts listed
each provider's accounts (Logins, from disk) once a model.
What changed:
- gateway/key_models.go: keyAllowed weighs a list through a keyList made
for that request alone. It has one GroupFinder and each provider's
AccountIDs read once. entryAllowed and accountServes are the same
checks over them. accountServes(who, p, model) stays for decide.go's
single check.
- access/models.go: globRe keeps each pattern's compiled expression. A
pattern compiles to the same expression whatever key holds it, so
nothing kept goes stale. The map is let go of whole past 4096 patterns.
- gui/groups.go: groupsState (the Routing page) called FindGroup once a
group too, the same class. It now uses one GroupFinder.
Every route that lists models goes through keyAllowed: /v1/models,
/v1/models/{id}, /v1beta/models, /v1/codex/models, Muse's list and the
deciders. The single-model checks (serve, count_tokens, embeddings,
System One, draw, video) ask one group and are unchanged. Nothing is kept
past a request, so a change to a key's models or accounts, a group's
members or an account's own models shows on the next request. No key
limit is loosened. The documented behaviour is unchanged, so no subsystem
page changes.
Tests:
- TestKeyListShowsWhatItDid compares keyAllowed with the old per-entry
check, kept in the test, for 14 keys over a catalog with found groups,
named and nested groups, a no-key provider and an account's own models.
The keys cover exact ids in any case, globs, group/<id>, group/*, a
group inside one named, accounts, and models with accounts.
- TestKeyListSeesChangesNextRequest goes through /v1/models and
/v1beta/models on one server while the key's models, the group's members,
the key's accounts and an account's models change.
- TestModelPatternsKeptCompiled checks each pattern keeps its own
expression and that past the cap works.
- Broken by hand, each went red: the accounts memo shared across providers
(ShowsWhatItDid), the GroupFinder kept across requests
(SeesChangesNextRequest), and the glob cache keyed by the pattern's first
letter (KeptCompiled).
Numbers, BenchmarkHeldKeyListsModels (2 providers x 500 models, 500 found
groups, M4 Pro):
- held to models: 2.36s before, 55ms after
- held to accounts: 2.35s before, 60ms after
- held to none: 43ms either way
Real use: sandbox magpie on 127.0.0.1:3486 with its own HOME, the same
1,500-entry catalog, a key held to 5 patterns, and curl 3x each:
- held key, /v1/models and /v1beta/models: 27.8-28.7s before, 0.18s after
- unheld key: 0.12s either way
- The held list (212 entries) and the unheld one (1500) were
byte-identical between the old and new builds.
- Changing the key's models while the server ran showed on the next
request (10 entries, then 212 again).
Run at origin/main 8f2a314cf:
- go test ./...: every package ok (49), no FAIL
- go test -race -count=3 on the access tests and -count=2 on TestKeyList*,
TestGatewayKeyModels* and TestGatewayKeyAccounts*
- gofmt -l and go vet ./... (darwin, GOOS=windows); GOOS=linux go vet
-tags nogui on access, gateway and gui
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// CleanModels is a key's model list as kept (#882): each pattern trimmed,
|
||||
@@ -68,7 +69,34 @@ func ModelAllowed(patterns []string, id string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// globs keeps each pattern's expression compiled, as a model list asks
|
||||
// for every model of it (#1762): a pattern is its expression whatever key
|
||||
// holds it, so none is ever stale. It is let go of whole past maxGlobs.
|
||||
var globs struct {
|
||||
sync.Mutex
|
||||
m map[string]*regexp.Regexp
|
||||
}
|
||||
|
||||
const maxGlobs = 4096
|
||||
|
||||
func globRe(p string) *regexp.Regexp {
|
||||
globs.Lock()
|
||||
re, ok := globs.m[p]
|
||||
globs.Unlock()
|
||||
if ok {
|
||||
return re
|
||||
}
|
||||
re = compileGlob(p)
|
||||
globs.Lock()
|
||||
if globs.m == nil || len(globs.m) >= maxGlobs {
|
||||
globs.m = map[string]*regexp.Regexp{}
|
||||
}
|
||||
globs.m[p] = re
|
||||
globs.Unlock()
|
||||
return re
|
||||
}
|
||||
|
||||
func compileGlob(p string) *regexp.Regexp {
|
||||
parts := strings.Split(p, "*")
|
||||
for i, s := range parts {
|
||||
parts[i] = regexp.QuoteMeta(s)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package access
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -87,3 +88,31 @@ func TestKeyModelsKept(t *testing.T) {
|
||||
t.Fatal("an empty list written", string(b))
|
||||
}
|
||||
}
|
||||
|
||||
// A pattern's expression is compiled once and kept (#1762): each pattern
|
||||
// keeps its own, asked in turn and again, and past the cap as before.
|
||||
func TestModelPatternsKeptCompiled(t *testing.T) {
|
||||
for range 2 {
|
||||
for _, c := range []struct {
|
||||
p, id string
|
||||
want bool
|
||||
}{
|
||||
{"plan/a*", "plan/abc", true},
|
||||
{"plan/b*", "plan/abc", false},
|
||||
{"plan/b*", "PLAN/B1", true},
|
||||
{"plan/a*", "plan/b1", false},
|
||||
{"*/x", "a/b/x", true},
|
||||
{"*/y", "a/b/x", false},
|
||||
} {
|
||||
if got := ModelAllowed([]string{c.p}, c.id); got != c.want {
|
||||
t.Errorf("%s by %s: %v", c.id, c.p, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := range maxGlobs + 10 {
|
||||
p := fmt.Sprintf("p%d/*", i)
|
||||
if !ModelAllowed([]string{p}, fmt.Sprintf("p%d/m", i)) || ModelAllowed([]string{p}, fmt.Sprintf("q%d/m", i)) {
|
||||
t.Fatal("past the cap", p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,20 +101,38 @@ func membersAllowed(who access.Identity, ms []provider.Member) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// keyList weighs a model list's entries for one request's key (#1762):
|
||||
// the routing groups are read once for the list, not once an entry —
|
||||
// each read is every provider's models, its files stat'ed again, and a
|
||||
// list of 1,000 models with 500 groups took seconds — and each
|
||||
// provider's accounts and keys once, not once a model. Nothing is kept
|
||||
// past the request, so the next sees a group, account or key's models
|
||||
// changed, as before.
|
||||
type keyList struct {
|
||||
who access.Identity
|
||||
find func(string) (provider.Group, []provider.Member, bool)
|
||||
refs map[string][]provider.AccountRef
|
||||
}
|
||||
|
||||
func newKeyList(who access.Identity) *keyList {
|
||||
return &keyList{who: who, find: provider.GroupFinder(), refs: map[string][]provider.AccountRef{}}
|
||||
}
|
||||
|
||||
// entryAllowed says the key is shown a model of the catalog — and some
|
||||
// account or key it may use serves it (#905): one the provider's
|
||||
// accounts are set not to serve (#474) is none of the key's.
|
||||
func entryAllowed(who access.Identity, e provider.Entry) bool {
|
||||
func (k *keyList) entryAllowed(e provider.Entry) bool {
|
||||
who := k.who
|
||||
if !who.Restricted() {
|
||||
return true
|
||||
}
|
||||
if e.Group != "" {
|
||||
g, ms, ok := provider.FindGroup(e.ID)
|
||||
g, ms, ok := k.find(e.ID)
|
||||
if !ok || !groupAllowed(who, g, ms) {
|
||||
return false
|
||||
}
|
||||
for _, m := range ms {
|
||||
if accountServes(who, m.Provider, m.Model) {
|
||||
if k.accountServes(m.Provider, m.Model) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -123,7 +141,21 @@ func entryAllowed(who access.Identity, e provider.Entry) bool {
|
||||
if !modelAllowed(who, e.Provider, e.Model) {
|
||||
return false
|
||||
}
|
||||
return accountServes(who, e.Provider, e.Model)
|
||||
return k.accountServes(e.Provider, e.Model)
|
||||
}
|
||||
|
||||
// accountServes is accountServes with p's accounts and keys read once
|
||||
// for the list.
|
||||
func (k *keyList) accountServes(p provider.Provider, model string) bool {
|
||||
if len(k.who.Accounts) == 0 {
|
||||
return true
|
||||
}
|
||||
refs, ok := k.refs[p.ID]
|
||||
if !ok {
|
||||
refs = p.AccountIDs()
|
||||
k.refs[p.ID] = refs
|
||||
}
|
||||
return accountServesOn(k.who, p, model, refs)
|
||||
}
|
||||
|
||||
// accountServes says some account or key the key may use serves the provider's
|
||||
@@ -133,7 +165,11 @@ func accountServes(who access.Identity, p provider.Provider, model string) bool
|
||||
if len(who.Accounts) == 0 {
|
||||
return true
|
||||
}
|
||||
refs := p.AccountIDs()
|
||||
return accountServesOn(who, p, model, p.AccountIDs())
|
||||
}
|
||||
|
||||
// accountServesOn is accountServes over refs, p's accounts and keys.
|
||||
func accountServesOn(who access.Identity, p provider.Provider, model string, refs []provider.AccountRef) bool {
|
||||
if len(refs) == 0 {
|
||||
// a provider with no account and no key (a local ollama): the
|
||||
// list holds a key to some accounts of the providers it names
|
||||
@@ -163,9 +199,10 @@ func keyAllowed(r *http.Request, es []provider.Entry) []provider.Entry {
|
||||
if !held {
|
||||
return es
|
||||
}
|
||||
k := newKeyList(who)
|
||||
out := make([]provider.Entry, 0, len(es))
|
||||
for _, e := range es {
|
||||
if entryAllowed(who, e) {
|
||||
if k.entryAllowed(e) {
|
||||
out = append(out, e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/access"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// listedBefore is keyAllowed as it was before #1762, every group read
|
||||
// and every provider's accounts listed again for each entry: what the
|
||||
// lists must still show.
|
||||
func listedBefore(who access.Identity, es []provider.Entry) []string {
|
||||
var out []string
|
||||
for _, e := range es {
|
||||
ok := !who.Restricted()
|
||||
if !ok && e.Group != "" {
|
||||
if g, ms, found := provider.FindGroup(e.ID); found && groupAllowed(who, g, ms) {
|
||||
ok = slices.ContainsFunc(ms, func(m provider.Member) bool { return accountServes(who, m.Provider, m.Model) })
|
||||
}
|
||||
} else if !ok {
|
||||
ok = modelAllowed(who, e.Provider, e.Model) && accountServes(who, e.Provider, e.Model)
|
||||
}
|
||||
if ok {
|
||||
out = append(out, e.ID)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func listedNow(who access.Identity, es []provider.Entry) []string {
|
||||
r := httptest.NewRequest("GET", "/v1/models", nil)
|
||||
r = r.WithContext(access.WithIdentity(r.Context(), who))
|
||||
var out []string
|
||||
for _, e := range keyAllowed(r, es) {
|
||||
out = append(out, e.ID)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// A key's model lists are read once a list since #1762, and show what
|
||||
// they did when every entry read them again: by a model's id in any
|
||||
// case, a pattern, a group named, every group, a group inside one named,
|
||||
// a found group, the key's accounts and an account's own models (#474).
|
||||
func TestKeyListShowsWhatItDid(t *testing.T) {
|
||||
fresh(t)
|
||||
var planMs, spareMs []string
|
||||
for i := range 40 {
|
||||
planMs = append(planMs, fmt.Sprintf("m%03d", i))
|
||||
spareMs = append(spareMs, fmt.Sprintf("m%03d", i+20)) // m020–m039 are both's: found groups
|
||||
}
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "plan", Name: "Plan", Chat: "https://plan.invalid/v1", Key: "k-plan", Keys: []provider.KeyAccount{{Key: "k-plan-2"}}, Models: planMs},
|
||||
{ID: "spare", Name: "Spare", Chat: "https://spare.invalid/v1", Key: "k-spare", Models: spareMs},
|
||||
{ID: "local", Name: "Local", Chat: "http://127.0.0.1:11434/v1", Models: []string{"tiny"}},
|
||||
} {
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := catalog.SaveLive("local", "http://127.0.0.1:11434/v1", []catalog.Model{{ID: "tiny"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, g := range []provider.Group{
|
||||
{Name: "Both", Members: []string{"plan/m001", "spare/m050"}, Routing: provider.Ordered},
|
||||
{Name: "Outer", Members: []string{"group/both", "plan/m002"}, Routing: provider.Ordered},
|
||||
{Name: "Solo", Members: []string{"plan/m003"}, Routing: provider.Ordered},
|
||||
{Name: "Narrow", Members: []string{"plan/m004", "plan/m000"}, Routing: provider.Ordered},
|
||||
} {
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// plan's first key serves m000 and m004 only, its second every model
|
||||
if err := provider.SetAccountModels("plan", provider.KeyID("k-plan"), []string{"m000", "m004"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
es := provider.Catalog()
|
||||
groups := 0
|
||||
for _, e := range es {
|
||||
if e.Group != "" {
|
||||
groups++
|
||||
}
|
||||
}
|
||||
if groups < 20 || !slices.ContainsFunc(es, func(e provider.Entry) bool { return e.ID == "local/tiny" }) {
|
||||
t.Fatalf("the catalog has %d groups: %v", groups, listedBefore(access.Identity{}, es))
|
||||
}
|
||||
planKey, plan2Key, spareKey := "plan/"+provider.KeyID("k-plan"), "plan/"+provider.KeyID("k-plan-2"), "spare/"+provider.KeyID("k-spare")
|
||||
for _, who := range []access.Identity{
|
||||
{},
|
||||
{Models: []string{"plan/*"}},
|
||||
{Models: []string{"PLAN/M00*", "spare/m05?", "Spare/M021"}},
|
||||
{Models: []string{"group/both"}},
|
||||
{Models: []string{"group/*"}},
|
||||
{Models: []string{"group/outer", "spare/m021"}},
|
||||
{Models: []string{"group/auto-m02*", "*/m03*"}},
|
||||
{Models: []string{"plan/m001", "spare/m050"}},
|
||||
{Accounts: []string{planKey}},
|
||||
{Accounts: []string{plan2Key, "spare/gone"}},
|
||||
{Accounts: []string{planKey, spareKey}},
|
||||
{Models: []string{"plan/*", "group/*"}, Accounts: []string{planKey}},
|
||||
{Models: []string{"group/narrow", "group/auto-m03*"}, Accounts: []string{planKey, "local/gone"}},
|
||||
{Accounts: []string{"local/gone"}},
|
||||
} {
|
||||
want, got := listedBefore(who, es), listedNow(who, es)
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("models %v accounts %v:\n got %v\nwant %v", who.Models, who.Accounts, got, want)
|
||||
}
|
||||
if who.Restricted() && len(want) == len(es) {
|
||||
t.Errorf("models %v accounts %v hold nothing back: %v", who.Models, who.Accounts, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A key's lists are read again each request (#1762): a change to the
|
||||
// key's models, a group's members or an account's own models shows on
|
||||
// the next list.
|
||||
func TestKeyListSeesChangesNextRequest(t *testing.T) {
|
||||
fresh(t)
|
||||
plan := &fake{t: t, ctype: "application/json", reply: `{}`}
|
||||
spare := &fake{t: t, ctype: "application/json", reply: `{}`}
|
||||
twoProviders(t, plan, spare)
|
||||
keys, secrets := newCaller(t, "Held")
|
||||
if _, err := access.Update("models-key", access.Change{Key: keys[0].ID, Models: []string{"group/g"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"plan/m1"}, Routing: provider.Ordered}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := New().Handler()
|
||||
listed := func() []string {
|
||||
t.Helper()
|
||||
var ids []string
|
||||
for _, path := range []string{"/v1/models", "/v1beta/models"} {
|
||||
r := httptest.NewRequest("GET", path, nil)
|
||||
r.Header.Set("Authorization", "Bearer "+secrets[0])
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, r)
|
||||
var l struct {
|
||||
Data []struct{ ID string }
|
||||
Models []struct{ Name string }
|
||||
}
|
||||
if w.Code != http.StatusOK || json.Unmarshal(w.Body.Bytes(), &l) != nil {
|
||||
t.Fatal(path, w.Code, w.Body.String())
|
||||
}
|
||||
for _, m := range l.Data {
|
||||
ids = append(ids, m.ID)
|
||||
}
|
||||
for _, m := range l.Models {
|
||||
ids = append(ids, "gemini:"+strings.TrimPrefix(m.Name, "models/"))
|
||||
}
|
||||
}
|
||||
slices.Sort(ids)
|
||||
return ids
|
||||
}
|
||||
if got := listed(); !slices.Equal(got, []string{"gemini:group/g", "group/g"}) {
|
||||
t.Fatalf("held to group g: %v", got)
|
||||
}
|
||||
// the group takes a member the key may not use alone: still listed,
|
||||
// the key names the group
|
||||
if err := provider.SaveGroup(provider.Group{ID: "g", Name: "G", Members: []string{"plan/m1", "spare/m2"}, Routing: provider.Ordered}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := listed(); !slices.Equal(got, []string{"gemini:group/g", "group/g"}) {
|
||||
t.Fatalf("group g grown: %v", got)
|
||||
}
|
||||
// the key now names plan's models: g has spare's too, and goes
|
||||
if _, err := access.Update("models-key", access.Change{Key: keys[0].ID, Models: []string{"plan/*"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := listed(); !slices.Equal(got, []string{"gemini:plan/m1", "plan/m1"}) {
|
||||
t.Fatalf("held to plan/*: %v", got)
|
||||
}
|
||||
// g loses spare's member: every member is the key's, and it is back
|
||||
if err := provider.SaveGroup(provider.Group{ID: "g", Name: "G", Members: []string{"plan/m1"}, Routing: provider.Ordered}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := listed(); !slices.Equal(got, []string{"gemini:group/g", "gemini:plan/m1", "group/g", "plan/m1"}) {
|
||||
t.Fatalf("group g narrowed: %v", got)
|
||||
}
|
||||
// held to plan's key, which is then set to serve another model only
|
||||
if _, err := access.Update("accounts-key", access.Change{Key: keys[0].ID, Accounts: []string{"plan/" + provider.KeyID("k")}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SetAccountModels("plan", provider.KeyID("k"), []string{"other"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := listed(); len(got) != 0 {
|
||||
t.Fatalf("plan's key serves m1 no more: %v", got)
|
||||
}
|
||||
if err := provider.SetAccountModels("plan", provider.KeyID("k"), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := listed(); len(got) != 4 {
|
||||
t.Fatalf("plan's key serves m1 again: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkHeldKeyListsModels is #1762's catalog: two providers of 500
|
||||
// models each serving the same ids, so magpie finds 500 groups for them,
|
||||
// listed for a key held to some models, one held to some accounts, and
|
||||
// one held to none.
|
||||
func BenchmarkHeldKeyListsModels(b *testing.B) {
|
||||
b.Setenv("XDG_CONFIG_HOME", b.TempDir())
|
||||
b.Setenv("XDG_CACHE_HOME", b.TempDir())
|
||||
var ms []string
|
||||
for i := range 500 {
|
||||
ms = append(ms, fmt.Sprintf("model-%03d", i))
|
||||
}
|
||||
for _, id := range []string{"plan", "spare"} {
|
||||
if err := provider.Save(provider.Provider{ID: id, Name: id, Key: "k-" + id, Chat: "https://" + id + ".invalid/v1", Models: ms}); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
s := settings.Load()
|
||||
s.LAN = true
|
||||
if err := settings.Save(s); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
var secrets []string
|
||||
for _, name := range []string{"Models", "Accounts", "Free"} {
|
||||
secret, err := access.Update("add-key", access.Change{Name: name})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
secrets = append(secrets, secret)
|
||||
}
|
||||
keys, _ := access.List()
|
||||
keys = keys[len(keys)-3:]
|
||||
if _, err := access.Update("models-key", access.Change{Key: keys[0].ID, Models: []string{
|
||||
"plan/model-00*", "spare/MODEL-1*", "plan/model-250", "group/auto-model-3*", "group/auto-model-499",
|
||||
}}); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, err := access.Update("accounts-key", access.Change{Key: keys[1].ID, Accounts: []string{"plan/" + provider.KeyID("k-plan")}}); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
h := New().Handler()
|
||||
for i, name := range []string{"models", "accounts", "free"} {
|
||||
b.Run(name, func(b *testing.B) {
|
||||
for b.Loop() {
|
||||
r := httptest.NewRequest("GET", "/v1/models", nil)
|
||||
r.Header.Set("Authorization", "Bearer "+secrets[i])
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"group/auto-model-499"`) {
|
||||
b.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -206,6 +206,9 @@ func groupsState() groupsJSON {
|
||||
out.Models = append(out.Models, modelRef{ID: e.ID, Name: e.Name, Provider: e.Provider.ID, PName: e.Provider.Name, Icon: e.Provider.Icon, Context: e.Context, Efforts: e.Efforts, CanFast: provider.CanFast(e.Provider, e.Model), OwnFast: provider.OwnFast(e.Provider, e.Model), Images: seesImages(e), ImagesUnknown: imagesUnknown(e)})
|
||||
}
|
||||
}
|
||||
// every provider's models read once for the groups, not once a group
|
||||
// (#1762)
|
||||
find := provider.GroupFinder()
|
||||
for _, g := range provider.Groups() {
|
||||
gj := groupJSON{Group: g, Info: []memberJSON{}, Holds: []string{}, Offers: []string{}, Shared: []string{}, Patterns: []provider.PatternHit{}}
|
||||
if gj.Members == nil {
|
||||
@@ -222,7 +225,7 @@ func groupsState() groupsJSON {
|
||||
break
|
||||
}
|
||||
}
|
||||
if _, ms, ok := provider.FindGroup(provider.GroupPrefix + g.ID); ok {
|
||||
if _, ms, ok := find(provider.GroupPrefix + g.ID); ok {
|
||||
for _, m := range ms {
|
||||
for _, v := range m.Groups() {
|
||||
if !slices.Contains(gj.Holds, v) {
|
||||
@@ -238,7 +241,7 @@ func groupsState() groupsJSON {
|
||||
m.Group = true
|
||||
for _, e := range served {
|
||||
if e.ID == id {
|
||||
_, ms, _ := provider.FindGroup(id)
|
||||
_, ms, _ := find(id)
|
||||
m.Ready, m.Name, m.Icon, m.On = true, e.Name, e.Provider.Icon, len(ms)
|
||||
m.Context, m.Images, m.ImagesUnknown = e.Context, seesImages(e), imagesUnknown(e)
|
||||
// the levels it offers agents: those every model in
|
||||
|
||||
Reference in New Issue
Block a user