Dani Ariyanto on Discord (#feedback, 10-24): a custom provider's models (kenari/*:free) had no window, reply limit, vision or reasoning known, and there was no one place to say them. magpie model spec <provider/model> what it has, and whose each value is magpie model spec <provider/model> [--context <n>] [--output <n>] [--vision on|off|auto] [--reasoning <levels>|off|auto] magpie model spec '<provider>/*' --context <n> --output <n> magpie model spec <provider/model> --reset magpie model specs It writes the stores magpie model context/output/images/efforts write (providers.json contexts; settings.json modelOutputs, modelImages, modelEfforts, modelReasonless), so every reader that went by those goes by a spec: entryFor/EntryOf/Served, /v1/models, max_tokens, the GUI's /api/providers badges and chips, and the agents' model lists. Every part is checked before anything is written; a refused command writes nothing. Agents are told once. Readers that bypassed the stores and now honour them: - provider.Efforts returns the kept levels, so the gateway fits a request to them (fitEffort): xhigh asked of a model kept to low-high goes as high. This reverses #92 (47e12df41), which narrowed only the lists handed out; docs/subsystems/gateway-routing.md says so. - entryFor: levels given a model with none known make it Reasoning. - gateway AutoVision picks by the user's ModelImages (seesAt). - GUI gateway client: a reasonless model offers no level chips. Run at this tree (basea93190ae1): - go test -count=1 -timeout 45m ./internal/{provider,cli,gui,gateway, settings,tui,agent,catalog}: all ok (gateway 505s, agent 360s). - GUI: gateway-*.test.cjs, model-reasonless, plugin-gateway, i18n-keys (25 files, both engines, the new file at 1100 and 420 in en, zh, zh-TW, ja, de): 225/225 pass. app.js untouched. - gofmt -l empty; go vet darwin, linux -tags nogui, windows clean. - Sandbox HOME, built binary, `magpie web` on 47821/47820 and a fake Chat vendor on 47811: before, kenari/glm-5:free had no window or levels; after spec 128k/16k/on/low-high, /v1/models said 128000, 16000, image input, [low medium high]; max_tokens 100000 went as 16000, xhigh as high, low as low; qwen-x with --reasoning off was sent no reasoning field; /api/providers had context 128000, output 16000, images/imageSet, kept [low medium high], reasonless for qwen-x. A models.dev sync during the run (GLM-5 202752/131072) didn't move the spec; after --reset the vendor's values came back. Bad values, an unknown flag and --help wrote nothing (files hashed). Rebased ontoa6a3dbde8(the ZCode mover's min, one line): at the pushed head 5af093d8b's tree, ./internal/provider and ./internal/cli -timeout 45m ok, and the spec tests in gateway and gui ok. Broken by hand, each went red: AutoVision on raw sees; Efforts on the full list; the Reasoning line removed; output, vision or context not written; ParseLevels skipped; agents told twice; --context 0 taken; help printing modelUsage; old client.js; the GUI named() image and reasonless branches. Not tried / not changed: no full go test ./... (another session's full GUI suite was running). Codex's ChatGPT-model /models pass-through and the Codex effort dropdown read catalog.Codex(), not a spec. The TUI shows no spec badges. A Context-tab trace keeps the window it was recorded with. Pre-existing and the same on origin/maina6a3dbde8: a GLM-5 relay with no levels known has xhigh sent as high.
98 lines
3.8 KiB
Go
98 lines
3.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// magpie model spec (Dani Ariyanto on Discord): a model nothing knows is
|
|
// shown unknown on each part, takes a whole spec in one command, shows it
|
|
// as the user's, is listed by magpie model specs, and --reset puts it back.
|
|
// A bad number, level, vision answer or flag is refused with the usage
|
|
// and writes nothing; --help anywhere prints the usage and writes nothing.
|
|
func TestModelSpecCmd(t *testing.T) {
|
|
groupsHome(t)
|
|
files := func() string {
|
|
var out string
|
|
for _, f := range []string{"settings.json", "providers.json"} {
|
|
b, _ := os.ReadFile(filepath.Join(settings.Dir(), f))
|
|
out += string(b)
|
|
}
|
|
return out
|
|
}
|
|
out, err := runOut(t, "model", "spec", "a/only-a")
|
|
if err != nil || strings.Count(out, "neither the vendor's list nor models.dev says") != 4 {
|
|
t.Fatalf("unknown spec: %q %v", out, err)
|
|
}
|
|
if out, err = runOut(t, "model", "specs"); err != nil || !strings.Contains(out, "no model has a spec of yours yet") {
|
|
t.Fatalf("empty list: %q %v", out, err)
|
|
}
|
|
if out, err = runOut(t, "model", "spec", "a/only-a", "--context", "128k", "--output=16k", "--vision", "on", "--reasoning", "low-high"); err != nil {
|
|
t.Fatalf("set: %q %v", out, err)
|
|
}
|
|
for _, want := range []string{"saved", "128k", "16k", "on", "low, medium, high"} {
|
|
if !strings.Contains(out, want) && !strings.Contains(out, strings.ReplaceAll(want, ", ", ",")) {
|
|
t.Errorf("set shows no %q: %q", want, out)
|
|
}
|
|
}
|
|
if strings.Count(out, "yours · --") != 4 {
|
|
t.Errorf("each part not said to be the user's: %q", out)
|
|
}
|
|
if out, err = runOut(t, "model", "specs"); err != nil || !strings.Contains(out, "a/only-a") || !strings.Contains(out, "vision on") || !strings.Contains(out, "reasoning low,medium,high") {
|
|
t.Fatalf("list: %q %v", out, err)
|
|
}
|
|
|
|
before := files()
|
|
for _, bad := range [][]string{
|
|
{"model", "spec", "a/only-a", "--context", "abc"},
|
|
{"model", "spec", "a/only-a", "--context", "0"},
|
|
{"model", "spec", "a/only-a", "--output", "-5"},
|
|
{"model", "spec", "a/only-a", "--reasoning", "turbo"},
|
|
{"model", "spec", "a/only-a", "--reasoning", "high-low"},
|
|
{"model", "spec", "a/only-a", "--context", "1m", "--reasoning", "bogus"},
|
|
{"model", "spec", "a/only-a", "--vision", "maybe"},
|
|
{"model", "spec", "a/only-a", "--frobnicate", "1"},
|
|
{"model", "spec", "a/only-a", "--context"},
|
|
{"model", "spec", "a/only-a", "128k"},
|
|
{"model", "spec", "a/only-a", "--reset", "--context", "1m"},
|
|
{"model", "spec", "a/nope", "--context", "1m"},
|
|
{"model", "spec", "a/*", "--vision", "on"},
|
|
{"model", "spec", "*/only-a", "--context", "1m"},
|
|
{"model", "spec", "--context", "1m"},
|
|
} {
|
|
if out, err := runOut(t, bad...); err == nil {
|
|
t.Errorf("took %v: %q", bad, out)
|
|
}
|
|
if files() != before {
|
|
t.Fatalf("a refused %v wrote", bad)
|
|
}
|
|
}
|
|
for _, help := range [][]string{
|
|
{"model", "spec", "--help"},
|
|
{"model", "spec", "a/only-a", "--help"},
|
|
{"model", "spec", "a/only-a", "--context", "--help"},
|
|
{"model", "specs", "--help"},
|
|
} {
|
|
if out, err := runOut(t, help...); err != nil || !strings.Contains(out, "say any of them: --context 200000 or 1m") {
|
|
t.Errorf("%v: %q %v", help, out, err)
|
|
}
|
|
if files() != before {
|
|
t.Fatalf("%v wrote", help)
|
|
}
|
|
}
|
|
|
|
if out, err = runOut(t, "model", "spec", "a/only-a", "--reset"); err != nil || !strings.Contains(out, "context, output, vision, reasoning") {
|
|
t.Fatalf("reset: %q %v", out, err)
|
|
}
|
|
if out, err = runOut(t, "model", "specs"); err != nil || !strings.Contains(out, "no model has a spec of yours yet") {
|
|
t.Fatalf("list after reset: %q %v", out, err)
|
|
}
|
|
if _, err = runOut(t, "model", "spec", "a/only-a", "--reset"); err == nil || !strings.Contains(err.Error(), "no spec of yours to reset") {
|
|
t.Fatalf("second reset: %v", err)
|
|
}
|
|
}
|