NoAPIFor found the protocols the provider speaks for every model it was asked about, and APIs did again through ModelAPI, so a list of N models built 2N Speaks slices. The providers' page, ExposedOf and servable ask it for each model of each provider: 16 MB of what twenty window polls allocated with real accounts (m2463 profile). NoAPI() finds the protocols once and gives a func for each model; APIs and ModelAPI take them through apisAmong and modelAPIAmong. NoAPIFor, APIs and ModelAPI answer as before. Test: TestNoAPIFindsTheProvidersAPIsOnce. 100 models of a relay, half listed on chat: Speaks looked up once (5 at most, for another test's look), the chat half kept, NoAPIFor the same for each. Run on mote, at this tree: - gofmt, go vet (darwin, windows, linux): ok - the new test with TestExposedOnlyOnTheAPIsTheProviderHas and TestListedAPIsCost, 3 times: ok - broken by hand (NoAPI back to a per-model NoAPIFor): red, "100 models looked up the provider's APIs 200 times" - go test ./internal/provider: ok - go test ./internal/gui (before the apisAmong step, which touches internal/provider only): every test ok except the known TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners (#3949) and TestColdTurnsTaken (#4510) Not run: an A/B with the real-account sandbox for this change alone.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// Which models a provider can't be asked for (#2094) is weighed for each
|
|
// model of a list, and the APIs the provider has a URL for are found once
|
|
// for the list, not once for each model.
|
|
func TestNoAPIFindsTheProvidersAPIsOnce(t *testing.T) {
|
|
oneHome(t)
|
|
p := Provider{ID: "relay", Name: "Relay", Key: "sk-x", Chat: "http://127.0.0.1:1/v1"}
|
|
var ms []catalog.Model
|
|
var chat []string
|
|
for i := range 100 {
|
|
m := catalog.Model{ID: fmt.Sprintf("m%02d", i), APIs: []string{"anthropic"}}
|
|
if i%2 == 0 {
|
|
m.APIs = []string{"chat"}
|
|
chat = append(chat, m.ID)
|
|
}
|
|
ms = append(ms, m)
|
|
}
|
|
if err := Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := catalog.SaveLive(p.ID, p.Chat, ms); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before := speaksLooked.Load()
|
|
var kept []string
|
|
for _, m := range p.servable(ms) {
|
|
kept = append(kept, m.ID)
|
|
}
|
|
// once, give or take a look another test left running takes
|
|
if n := speaksLooked.Load() - before; n > 5 {
|
|
t.Fatalf("100 models looked up the provider's APIs %d times", n)
|
|
}
|
|
if !slices.Equal(kept, chat) {
|
|
t.Fatalf("kept %v, want the models listed on chat %v", kept, chat)
|
|
}
|
|
for _, m := range ms {
|
|
if p.NoAPIFor(m.ID) != !slices.Contains(chat, m.ID) {
|
|
t.Fatalf("NoAPIFor(%s) = %v", m.ID, p.NoAPIFor(m.ID))
|
|
}
|
|
}
|
|
}
|