Files
magpie/internal/gateway/unknown_model.go
T
yetone e50a958014 gateway: an unknown model's 404 names the nearest ids, display names first, and how a model is named (MOMO on Discord)
MOMO asked for "Zen-Space-Bunny", the model's name as a picker shows
it, and the 404 said only "magpie knows no model" and then every id. It
named neither the id meant (opencode-zen-free/space-bunny-free, "Space
Bunny Free") nor the forms a model id can take.

What changed:
- provider/closest.go: Closest(asked, n) splits asked into lowercase
  letter and digit words and scores every catalog entry: a word in the
  display name (the user's or the vendor's) counts 4, in the model id 3,
  the provider's id or name 1 and only alongside one of the others; the
  whole of asked found in the name or id adds 4.
- gateway/unknown_model.go: unknownModel puts "did you mean …?" (up to
  3), then the forms (provider/model, a routing group's id or name, a
  bare model id and where an ambiguous one goes), then the ids as
  before. Used by the chat 404 and the embeddings 404. Switched-off,
  disabled-group and empty-group 404s are unchanged. Draw and video keep
  their own 404: their models are a different list, and the chat
  catalog's nearest ids would point at models that can't draw.
- docs: gateway-routing.md model resolution row.

Tests: unknown_model_test.go: "Zen-Space-Bunny" against
opencode-zen-free serving space-bunny-free named "Space Bunny Free" is
told that id first and the forms; a provider's name alone suggests
nothing; a display name ranks before an id with the same words. The
404 test fails with the gateway hooks reverted.

Run: gofmt -l; go vet -tags nogui on darwin, linux, windows for provider
and gateway; go test -tags nogui ./internal/provider ./internal/gateway
and the root package in a sandbox HOME.
2026-10-10 05:46:48 +08:00

29 lines
1.0 KiB
Go

package gateway
import (
"fmt"
"strings"
"github.com/yetone/magpie/internal/provider"
)
// unknownModel is what a request for a model magpie doesn't know is told
// (MOMO on Discord: "Zen-Space-Bunny" got a 404 that said neither how a
// model is named nor which one was meant): the ids nearest to it, the
// ways a model can be named, then every id there is. what is "" for a
// chat, or what the model was for (" to draw with").
func unknownModel(asked, what string) string {
msg := fmt.Sprintf("magpie knows no model %q%s", asked, what)
if near := provider.Closest(asked, 3); len(near) > 0 {
msg += "; did you mean " + strings.Join(near, ", ") + "?"
}
msg += " Name a model as provider/model (as /v1/models lists it), a routing group's id or name, or a bare model id" +
" (one served by several providers goes to the group magpie found for it, else to the first of them in the Providers order)"
if ids := provider.IDs(); len(ids) > 0 {
msg += "; it has " + strings.Join(ids, ", ")
} else {
msg += "; add a provider in magpie first"
}
return msg
}