A relay with many models behind one key can now have each model's API
set from a script, not only in the provider editor's Names, prices &
levels ("API this model is asked on"):
magpie model api <provider/model>... chat|responses|anthropic|gemini|auto
magpie model api <provider/model>... --reset (auto)
magpie model api <provider/model> what it is asked on
magpie model apis [<provider>] the settings; with a
provider, every model
It saves through provider.SetModelPrefs, the editor's Save, into
settings' modelAPIs, so a running gateway reads it on the next request
and the agents' model lists are told once. Choices are those the editor
offers (modelAPIs in app.js): the APIs the provider has a URL for, when
it has two or more; Vertex AI none. --help anywhere prints the usage. A
flag in place of a model, an unknown API, a model the provider doesn't
list, or an API it has no URL for is refused; several models are all
checked before any is written. A saved setting for a model the vendor
no longer lists can still be reset. Documented in docs/reference.md
("The API a model is asked on") and the gateway-routing page.
Run (mote, via mote-run, at this tree on 0e55a7593):
- go test -count=1 ./internal/cli/: ok (46.7s)
- TestModelAPICmd, TestModelAPIReachesTheRunningGateway: PASS. The
second starts gateway.New().Handler() first, asks relay/mixed (chat
completions), sets anthropic through the CLI, and the next request
goes to /v1/messages; after --reset back to chat.
- gofmt -l: nothing; go vet, GOOS=linux go vet -tags nogui,
GOOS=windows go vet of ./internal/cli; go build, GOOS=linux build
-tags nogui, GOOS=windows build: ok.
Broken by hand:
- the model/api(s) cases taken out of modelCmd: both tests FAIL
(unknown command "apis" / "api").
- each model written as it is checked instead of all checked first:
TestModelAPICmd FAIL "a refused command wrote:
map[relay/claude-y:anthropic relay/gpt-x:chat relay/mixed:chat]".
Not tried: a real relay account; the reporter's provider. The full
suite runs after the push.