zeewell on X (tweet 2116404121930432888): relays serve one model under
ids of their own (deepseek-v4.1-flash-1017, grok-4.6@500k). They want to
give each one their own id at the provider layer. magpie then lists,
routes, groups and finds groups by that id, and the upstream request
still carries the vendor's id.
Choice: a new per-model map, settings' ModelIDs
("<pid>/<local>": "<own id>"), served through the wire names that
already exist. ModelSameAs was not widened. It means "same as another
vendor's model": it lends specs and joins found groups. Making it rename
models everywhere would change every existing user's ids and refs.
ModelWires was not reinterpreted either, for the same reason. ModelIDs is
ModelWires turned round: a wire keeps magpie's id and changes the one
sent, and this keeps the one sent and changes magpie's. Settings.Wires()
merges each entry in as a wire name (wrapped by a "<pid>/*" wire). Every
place that sent a ModelWires name (gateway, usage ledger, request page,
UpstreamName, UpstreamNameAs) reads Wires(), so the upstream id needs no
new path. An explicit ModelWires entry for the same id wins.
- Listed by the local id: Available, liveIDs/liveByID, Serving and
ListPrice translate through OwnModelID. /v1/models, agents' lists,
Resolve, routing groups and found groups (auto/<local>, merged with
every other provider serving that id) all see the local id.
- Only a provider of the user's own (Account == nil) takes one. An
account's or a plugin's request is built from its list's id, which no
wire reaches.
- Two variants of one provider given one id: the latest given it wins,
and the earlier one is listed by its own id again. The CLI names it.
The editor refuses two rows given one id in one save. A model of the
provider's own id that a variant is listed by (plain grok-4.6 beside
grok-4.6@500k) is not listed while the variant has it.
- The user's values are never overridden. SetModelID moves picks,
contexts, fallbacks, groups' members/rules/fast/placed/off/weights/
classifier/pick, the pickers' lists, every per-model setting
(Settings.MoveModel) and gateway keys' models (provider.ModelMoved,
set by access) to the new id, but only where nothing is under the new
id yet. Agents' own files are not rewritten: an old provider/<own id>
still resolves and is sent as it is. Group match patterns and key
patterns stay as written.
- Key limits: a key held to either id passes for both (modelAllowed:
the ref, OwnModelID, ListedModelID). Group members use the same check.
- Usage: model = the listed id, served = the vendor's id from its reply.
The price is the own id's first.
CLI: magpie model id <provider/model> [<id>|--reset], magpie model ids.
GUI: Providers > a provider's editor > Names & levels > "Listed as",
beside Same as. It is staged with the editor's Save and taken back by
Restore default, in zh, zh-TW, ja and de. Accounts have no box.
Docs: providers-accounts.md, gateway-routing.md, and site start.html in
en, zh and ja.
Run (mote-run, at this tree rebased on 841326709):
- go test -tags nogui of internal/gateway, provider, settings, access,
usage and cli: ok. internal/gui: ok but for
TestSettingsSaveKeepsWhatItDoesNotSend's SearchAll, red on main since
b09349d17 (#4514, yiqiui's patch); its ModelIDs case passes.
- TestAutoVisionDoesNotBuildListsAgain: 457 allocations with 4 models,
458 with 400 (main 459), searcherModel within its 50. Reading
Shared() per list cost 3041; SharedModelIDs parses only modelIDs once
per file change, the settings path is built again only when what it is
built from changes, and Serving looks up the own id only when a key is
listed to some model.
- TestCoreScriptBudget: raised by 1,178 bytes for the Listed as box,
with a note.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet ok.
- GUI: provider-listed-as (en, zh, zh-TW, ja, de), provider-same-as,
provider-detect in Chromium on mote and WebKit on the Linux box (mote's
WebKit launch hangs, #4125): 9 of 9.
Broken by hand, each red: the wire name (wires), the list (list), a key
held to the own id (keyown), the key move hook (hook), liveIDs, liveByID,
moving refs (moverefs) and moving per-model settings (movemodel).
Not tried: a red for ListPrice's or Serving's own-id lookup; a real relay
with variant ids; Match patterns are not rewritten to the new id. The
full Go suite and the whole GUI suite are still running and their reds
get their own issues.
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package access
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A key held to a provider's model is held to it under the id it is
|
|
// listed by (provider.SetModelID): the key's own "<provider>/<model>"
|
|
// moves to the new id with the model, as the provider's picks and the
|
|
// routing groups' refs do, so the user's limit keeps meaning that model.
|
|
func init() { provider.ModelMoved = MoveModel }
|
|
|
|
// MoveModel gives every key's models that name from ("<provider>/<model>",
|
|
// letter case aside) to instead. A pattern ("relay/*") is the user's own
|
|
// and is left as written.
|
|
func MoveModel(from, to string) error {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
keys, err := load()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
changed := false
|
|
for i := range keys {
|
|
ms := keys[i].Models
|
|
var out []string
|
|
moved := false
|
|
for _, m := range ms {
|
|
if strings.EqualFold(m, from) {
|
|
m, moved = to, true
|
|
}
|
|
if !containsFold(out, m) {
|
|
out = append(out, m)
|
|
}
|
|
}
|
|
if moved {
|
|
keys[i].Models, changed = out, true
|
|
}
|
|
}
|
|
if !changed {
|
|
return nil
|
|
}
|
|
return save(keys)
|
|
}
|
|
|
|
func containsFold(ms []string, m string) bool {
|
|
for _, x := range ms {
|
|
if strings.EqualFold(x, m) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|