mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 11:09:56 +00:00
listAvailableModels prefers conf/models.yaml whenever one is loaded, and one always is in production — the static map in model_routes.go is the fallback for when it is not. So the Zen speech names only reached the fallback, and the catalog kept advertising the engine ids. Name the SKUs in the YAML too, with `upstream` carrying the id the speech service answers to, so the engine behind a product can change without renaming the product. The upstream ids stay callable and unlisted, as the static map already had them. TestSpeechCatalog checks the two agree. The listing benchmarks record what an answer costs: 70us for the configured routes, 1.4ms once a family lineup is merged in.
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package controllers
|
|
|
|
import "testing"
|
|
|
|
// speechSKUs is the speech lineup as the catalog sells it: the Zen name callers see,
|
|
// and the id the in-cluster speech service answers to.
|
|
var speechSKUs = map[string]string{
|
|
"zen-scribe": "whisper",
|
|
"zen-scribe-mini": "whisper-small",
|
|
"zen-voice-mini": "kokoro",
|
|
}
|
|
|
|
// TestSpeechCatalog asserts the shipped conf/models.yaml — the catalog /v1/models
|
|
// actually renders — sells the speech models under their Zen names and keeps the
|
|
// upstream ids callable but unlisted.
|
|
//
|
|
// The static map in model_routes.go is only the fallback: listAvailableModels
|
|
// prefers the YAML whenever one is loaded, which is always in production. So the
|
|
// two have to agree, and this is what checks that they do.
|
|
func TestSpeechCatalog(t *testing.T) {
|
|
if err := InitModelConfig("../conf/models.yaml"); err != nil {
|
|
t.Fatalf("load conf/models.yaml: %v", err)
|
|
}
|
|
cfg := GetModelConfig()
|
|
if cfg == nil {
|
|
t.Fatal("model config nil after init")
|
|
}
|
|
|
|
listed := map[string]bool{}
|
|
for _, m := range cfg.ListModels() {
|
|
listed[m.ID] = true
|
|
}
|
|
|
|
for name, upstream := range speechSKUs {
|
|
r := cfg.ResolveRoute(name)
|
|
if r == nil {
|
|
t.Errorf("%q did not resolve", name)
|
|
continue
|
|
}
|
|
if r.providerName != "speech" {
|
|
t.Errorf("%q provider = %q, want speech", name, r.providerName)
|
|
}
|
|
if r.upstreamModel != upstream {
|
|
t.Errorf("%q upstream = %q, want %q", name, r.upstreamModel, upstream)
|
|
}
|
|
if !listed[name] {
|
|
t.Errorf("%q is not in the /v1/models listing", name)
|
|
}
|
|
// The upstream id keeps working for callers already sending it, and stays
|
|
// out of the catalog so we advertise one name per model.
|
|
if cfg.ResolveRoute(upstream) == nil {
|
|
t.Errorf("upstream id %q stopped resolving", upstream)
|
|
}
|
|
if listed[upstream] {
|
|
t.Errorf("upstream id %q is advertised; only %q should be", upstream, name)
|
|
}
|
|
}
|
|
|
|
// The static fallback has to sell the same names, or the catalog changes shape
|
|
// the moment the YAML is missing.
|
|
for name, upstream := range speechSKUs {
|
|
route, ok := modelRoutes[name]
|
|
if !ok {
|
|
t.Errorf("static map is missing %q", name)
|
|
continue
|
|
}
|
|
if route.upstreamModel != upstream {
|
|
t.Errorf("static %q upstream = %q, want %q", name, route.upstreamModel, upstream)
|
|
}
|
|
if route.hidden {
|
|
t.Errorf("static %q is hidden; it is the name we sell", name)
|
|
}
|
|
if r, ok := modelRoutes[upstream]; ok && !r.hidden {
|
|
t.Errorf("static upstream id %q is advertised; it should be hidden", upstream)
|
|
}
|
|
}
|
|
}
|