elis_pina (LoveEcho1145) on X: some APIs list a model more than once in their /models, and each copy was a row of its own. A provider asked at its base already merged copies by id (Provider.fetchOne's add), but one asked at the URL its list is at (ModelsURL), the add form's List, and every list fetched another way (accounts, Azure, Kilo, Cline, decision lists) kept them, in the pickers, /v1/models and the agents' lists. catalog.Unique keeps each id once: the first copy in its place, with what it leaves unsaid (a name other than the id, window, output, levels, price, APIs, tiers, magpie_via, keys) taken from the copies after it, as the lookups by id (LiveByID's callers) already took the first copy that said it. It runs at the parse of every upstream /models (catalog.fetchOne, all pages), at every save (saveLive: the list and each base's part, whoever fetched it), and at every read (readLive), so a list saved before reads each id once without waiting for a fetch. A list with no copies comes back as it is. Plugins' lists are keyed by id in host.js already. Keyed by id alone, as Provider.fetchOne and fetchPerKey merge already. Tests: TestFetchedListNamesEachModelOnce, TestSavedListNamesEachModelOnce (saved, sides, LiveByID, and a file written before with copies), TestUniqueLeavesAListWithoutCopies, TestProviderListsEachModelOnce (at base and at ModelsURL: Fetch, List, Available). Broken by hand: with Unique returning its input, the first two and the ModelsURL case of the last are red (Fetch/List/Available listed [gpt-5.6 glm-5.3 gpt-5.6 glm-5.3]); with readLive's Unique alone taken out, the saved-before case is red. Run on mica: gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./... ok; go test -timeout 45m ./... at b552edb12 (base6af327e2b): 100 packages ok, internal/plugin red on TestCancelledSignInSavesNothing, #5532 (filed, same tok-late output, passes -count=10 alone at this head). Rebased on87a0af212(changes only gateway test files and LESSONS since); at the pushed head internal/catalog and internal/provider ok, linux/windows vet of both ok. No GUI file changed and no API shape changed, so no GUI suite was run. Not tried: a real vendor that lists copies (the reporter named none).
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// #6582: an API whose model list names a model twice. A provider asked at
|
|
// the URL its list is at (ModelsURL), as one asked at its base, lists each
|
|
// model once: in Fetch's answer, the add form's List and Available, which
|
|
// the pickers, /v1/models and the agents' lists are made from.
|
|
func TestProviderListsEachModelOnce(t *testing.T) {
|
|
isolateFetchHome(t)
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
io.WriteString(w, `{"object":"list","data":[{"id":"gpt-5.6"},{"id":"glm-5.3"},{"id":"gpt-5.6"},{"id":"glm-5.3"}]}`)
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
for _, p := range []Provider{
|
|
{ID: "at-base", Name: "At base", Chat: srv.URL + "/v1", Key: "k"},
|
|
{ID: "at-url", Name: "At URL", Chat: srv.URL + "/v1", ModelsURL: srv.URL + "/v1/models", Key: "k"},
|
|
} {
|
|
if err := Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
q, err := Find(p.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
once := func(what string, ms []catalog.Model) {
|
|
t.Helper()
|
|
if len(ms) != 2 || ms[0].ID != "gpt-5.6" || ms[1].ID != "glm-5.3" {
|
|
ids := []string{}
|
|
for _, m := range ms {
|
|
ids = append(ids, m.ID)
|
|
}
|
|
t.Errorf("%s %s = %v, want [gpt-5.6 glm-5.3]", p.ID, what, ids)
|
|
}
|
|
}
|
|
ms, err := q.Fetch(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
once("Fetch", ms)
|
|
ls, err := q.List(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
once("List", ls)
|
|
q, _ = Find(p.ID)
|
|
once("Available", q.Available())
|
|
}
|
|
}
|