pinmmis on X (tweet 2115776439341506603): the same model from several
relays, each renamed to be told apart ("ds.4.1(WB)" for
deepseek-v4.1-flash), had none of models.dev's specs, and setting each
spec by hand per model was the only way.
The ids are the relay's own (magpie looks up the model's id, not a
display name), so this is not a display-name bug. The editor's
per-model "Same as" (settings' ModelSameAs) already merged routing
groups and priced the model; now it also gives the model that model's
window, reply limit, reasoning levels, thinking and images:
- catalog.UserSame, set by the settings package (sameas.go,
sameAsBare: ModelSameAs indexed by bare model id, memoised per
shared map), is asked by contextIn/lookupIn after the id as given
and before magpie's own guesses (renamed, normalFor). An id
models.dev lists stays its own; the user's own window, output,
levels and images settings still win (callers read them first).
The model named is looked up once, never sent back to UserSame (no
loops). KnowsAsWritten (usage telemetry) never hears it.
- Zero-config part: those lookups also read past a channel's tag in
brackets at an id's start or end (untagged: "deepseek-v4.1-flash
(WB)", "[WB] ...", fullwidth and CJK brackets). A "[...]" written
onto the id with no space is not a tag ("deepseek-v4.1-flash[fast]"
may be a variant, TestRenameNeverTakesAModelForAnother). Prices are
never borrowed this way (TestOtherSpellingIsNotPriced's rule); a
Same as's price is still SamePriceIn.
- "ds.4.1(WB)" itself is not guessed: ds/4.1 could be flash or pro.
- GUI: the Same as box's tooltip says what it now covers, in every
language; provider-same-as.test.cjs checks every language, not zh
only. No layout or API change.
- docs/subsystems/providers-accounts.md says it.
Run on mote via mote-run:
- at the same change on 2c89794ac: go test -tags nogui -timeout 45m
./internal/catalog ./internal/settings ./internal/provider
./internal/agent ./internal/gateway ./internal/gui ./internal/cli:
all ok (gateway 525s).
- at this commit (rebased on 2d11cde05, which touched provider and the
GUI): catalog, settings, provider, gui again: all ok
- node --test provider-same-as, i18n-keys, names-fold in chromium and
webkit, at this commit: 16 of 16 pass.
- gofmt -l clean; GOOS=linux/windows/darwin go vet -tags nogui of
catalog, settings, provider: clean.
- Real use: magpie built in a sandbox HOME on mote with the real
models.dev cache, a relay provider with ds.4.1(WB) (Same as
deepseek-v4.1-flash), ds.4.1(other) and "deepseek-v4.1-flash (WB)":
`magpie model spec` gives the first and third 1048576 / 384k /
vision on / low,high,max, the second unknown.
Broken by hand: userSame and untagged made to find nothing ->
TestUserSameGivesTheSpecs, TestTaggedIDHasTheModelsSpecs (17 errors)
and TestSameAsGivesAnUnlistedModelItsSpecs go red.
Not tried: a real relay request in the GUI app; Windows/Linux runs
(pure Go lookups, no OS paths); the whole GUI suite (only a tooltip
string changed).
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package settings
|
|
|
|
import (
|
|
"maps"
|
|
"reflect"
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// The catalog hears what the user said a model is the same as
|
|
// (ModelSameAs) for every spec it gives of a model it doesn't list by its
|
|
// own id: the window, the reply limit, the levels and images (pinmmis on
|
|
// X: a relay's model renamed "ds.4.1(WB)" had none of deepseek-v4.1-flash's).
|
|
func init() { catalog.UserSame = sameAsBare }
|
|
|
|
// sameMemo is the bare-id index of the ModelSameAs map last read, kept
|
|
// while Shared hands out that same map.
|
|
var sameMemo struct {
|
|
sync.Mutex
|
|
of map[string]string
|
|
index map[string]string
|
|
}
|
|
|
|
// sameAsBare is the model the user said a model of this bare id is the
|
|
// same as, at any provider: the first, by provider id, of those saying so.
|
|
func sameAsBare(bare string) (string, bool) {
|
|
same := Shared().ModelSameAs
|
|
if len(same) == 0 {
|
|
return "", false
|
|
}
|
|
sameMemo.Lock()
|
|
defer sameMemo.Unlock()
|
|
if sameMemo.of == nil || reflect.ValueOf(sameMemo.of).UnsafePointer() != reflect.ValueOf(same).UnsafePointer() {
|
|
index := map[string]string{}
|
|
for _, k := range slices.Sorted(maps.Keys(same)) {
|
|
_, model, ok := strings.Cut(k, "/")
|
|
v := strings.TrimSpace(same[k])
|
|
if !ok || model == "" || model == "*" || v == "" {
|
|
continue
|
|
}
|
|
b := strings.ToLower(model)
|
|
if i := strings.LastIndexByte(b, '/'); i >= 0 {
|
|
b = b[i+1:]
|
|
}
|
|
if _, had := index[b]; !had {
|
|
index[b] = v
|
|
}
|
|
}
|
|
sameMemo.of, sameMemo.index = same, index
|
|
}
|
|
v, ok := sameMemo.index[bare]
|
|
return v, ok
|
|
}
|