gateway: Cindy is told each model by its name with its provider's (cdredfox on X)
Cindy's picker listed magpie's GLM-5.3-Flash three times, 千问 3.8-Flash
and DeepSeek-Flash twice each, with nothing to tell them apart. Cindy
0.1.94's model discovery (parseModelsListResponse in its app bundle)
names a row by display_name before name, and magpie's display_name is
the bare model name. /v1/models asked with Cindy's key (magpie-cindy, as
its import link gives it) now gives display_name the name the agents'
lists use, provider.LabelsFor("cindy", ...): "GLM-5.3-Flash · Zhipu",
"... · routing group" for auto/, following Cindy's Provider in model
names (the picker the Agents page already showed for Cindy, which
changed nothing there before), a name the user gave a model kept as
they wrote it. Every other client's display_name is unchanged. In Cindy
a discovered model's shown name follows discoveredMetadata.name, which
its 刷新模型列表 updates for existing models; a name the user typed in
Cindy (nameExplicit) still wins there.
Run:
- TestCindyDiscoveryNamesModelsApart (new): on, own and off, three
providers' GLM-5.3-Flash apart, a user's own name kept, another client
plain. Red on the old gateway.go ("on: Cindy told
map[... or/glm-5.3-flash:GLM-5.3-Flash zp/glm-5.3-flash:GLM-5.3-Flash]").
- Real use: this tree's magpie built and served in a sandbox HOME on
mica with two custom providers serving glm-5.3-flash; its /v1/models
with magpie-cindy fed to Cindy 0.1.94's own parseModelsListResponse
(extracted from /Applications/Cindy.app's app.asar): "GLM-5.3-Flash ·
OpenRouterX", "GLM-5.3-Flash · ZhipuX", "GLM-5.3-Flash · routing
group"; with magpie-pi's key all three still "GLM-5.3-Flash".
- Full suite on mica at base e730a14dc (go test -count=1 -timeout 45m ./...): 99 packages ok, no FAIL. go vet ./... (darwin), GOOS=windows go vet ./... and GOOS=linux go vet -tags nogui ./... clean; gofmt -l clean.
Not tried: Cindy's own window. Adding magpie there writes into the live
CindyGlobal folder, which has no account database on this Mac.
- After the rebase onto 9a3f95f3f's parent (two gateway commits): internal/gateway, internal/provider and internal/agent ok on mica.
This commit is contained in:
@@ -339,6 +339,14 @@ immutable with no WAL log, from a copy with one; a plain read-only open
|
||||
made `-wal` and `-shm` in Cindy's folder while it was closed), and one that
|
||||
can't be read, or a stopped WSL distro's, is unknown, never "not added"
|
||||
(`TestCindyHasClosedWALAndUnreadable`, `TestImportStatusUnreadableIsUnknown`).
|
||||
Cindy names each model its import's `modelsUrl` lists by `display_name`
|
||||
before `name` (`parseModelsListResponse` in its app, 0.1.94), so
|
||||
`/v1/models` asked with Cindy's key gives `display_name` the name the
|
||||
agents' lists use (`provider.LabelsFor("cindy", …)`: its provider's after
|
||||
it, by Cindy's Provider in model names, and a name the user gave kept);
|
||||
plain, three providers' GLM-5.3-Flash read the same in its picker
|
||||
(cdredfox on X, `TestCindyDiscoveryNamesModelsApart`). Another client's
|
||||
`display_name` stays the name alone.
|
||||
Reopening the link lets Lody handle duplicates.
|
||||
Bub requires its separately installed ACP plugin.
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// Cindy's model discovery (parseModelsListResponse in its app) names a row
|
||||
// by display_name before name, and showed magpie's GLM-5.3-Flash of three
|
||||
// providers three times the same (cdredfox on X). Cindy is told each model
|
||||
// by the name the agents' lists give it: with its provider's after it, and
|
||||
// with the provider left out, plain only where no other has that name. A
|
||||
// name the user gave a model is kept as they wrote it under "own". Another
|
||||
// client's display_name stays the name alone.
|
||||
func TestCindyDiscoveryNamesModelsApart(t *testing.T) {
|
||||
fresh(t)
|
||||
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
|
||||
data := `{"or":{"models":{"glm-5.3-flash":{"id":"glm-5.3-flash","name":"GLM-5.3-Flash"},"kimi":{"id":"kimi","name":"Kimi"}}},"zp":{"models":{"glm-5.3-flash":{"id":"glm-5.3-flash","name":"GLM-5.3-Flash"}}},"sf":{"models":{"glm-flash":{"id":"glm-flash","name":"GLM-5.3-Flash"}}}}`
|
||||
if err := os.WriteFile(catalog.CachePath(), []byte(data), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog.Reset()
|
||||
t.Cleanup(catalog.Reset)
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "or", Name: "OpenRouter", Catalog: "or", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-5.3-flash", "kimi"}},
|
||||
{ID: "zp", Name: "Zhipu", Catalog: "zp", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-5.3-flash"}},
|
||||
{ID: "sf", Name: "SiliconFlow", Catalog: "sf", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-flash"}},
|
||||
} {
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := provider.SetModelName("sf/glm-flash", "My Flash"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
list := func(cindy bool) map[string]string {
|
||||
req := httptest.NewRequest("GET", "/v1/models", nil)
|
||||
if cindy {
|
||||
// Cindy's import link gives it the cindy key (CindyLink)
|
||||
req.Header.Set("Authorization", "Bearer "+TokenFor("cindy"))
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
var out struct {
|
||||
Data []struct {
|
||||
ID string `json:"id"`
|
||||
Display string `json:"display_name"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, m := range out.Data {
|
||||
got[m.ID] = m.Display
|
||||
}
|
||||
return got
|
||||
}
|
||||
for _, c := range []struct{ mode, or, zp, sf, kimi string }{
|
||||
{provider.SuffixOn, "GLM-5.3-Flash · OpenRouter", "GLM-5.3-Flash · Zhipu", "My Flash · SiliconFlow", "Kimi · OpenRouter"},
|
||||
{provider.SuffixOwn, "GLM-5.3-Flash · OpenRouter", "GLM-5.3-Flash · Zhipu", "My Flash", "Kimi · OpenRouter"},
|
||||
{provider.SuffixOff, "GLM-5.3-Flash · OpenRouter", "GLM-5.3-Flash · Zhipu", "My Flash", "Kimi"},
|
||||
} {
|
||||
if err := provider.SetSuffixMode(c.mode); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := list(true)
|
||||
if got["or/glm-5.3-flash"] != c.or || got["zp/glm-5.3-flash"] != c.zp || got["sf/glm-flash"] != c.sf || got["or/kimi"] != c.kimi {
|
||||
t.Fatalf("%s: Cindy told %v", c.mode, got)
|
||||
}
|
||||
other := list(false)
|
||||
if other["or/glm-5.3-flash"] != "GLM-5.3-Flash" || other["zp/glm-5.3-flash"] != "GLM-5.3-Flash" || other["or/kimi"] != "Kimi" {
|
||||
t.Fatalf("%s: another client told %v", c.mode, other)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1808,6 +1808,13 @@ func (s *Server) listModels(w http.ResponseWriter, r *http.Request) {
|
||||
if agent == "dsh" {
|
||||
m["name"] = labels[i]
|
||||
}
|
||||
// for Cindy: the same name as its display_name, which its
|
||||
// model discovery (parseModelsListResponse) names a row by
|
||||
// before name, so magpie's GLM-5.3-Flash of three providers
|
||||
// read three times the same in its picker (cdredfox on X)
|
||||
if agent == "cindy" {
|
||||
m["display_name"] = labels[i]
|
||||
}
|
||||
if agent == "cursor-local" {
|
||||
cursorLocalModel(m, e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user