mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 02:36:49 +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.
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// BenchmarkListAvailableModels measures what GET /v1/models costs per call against
|
|
// the real catalog. Every SDK asks for this list on startup, so its per-call cost is
|
|
// the ceiling on how many clients can come up at once.
|
|
func BenchmarkListAvailableModels(b *testing.B) {
|
|
if err := InitModelConfig("../conf/models.yaml"); err != nil {
|
|
b.Fatalf("load conf/models.yaml: %v", err)
|
|
}
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
if got := listAvailableModels(); len(got) == 0 {
|
|
b.Fatal("empty catalog")
|
|
}
|
|
}
|
|
}
|
|
|
|
// BenchmarkListModelsResponse measures the whole answer: build the list, wrap it, and
|
|
// marshal the bytes that go on the wire.
|
|
func BenchmarkListModelsResponse(b *testing.B) {
|
|
if err := InitModelConfig("../conf/models.yaml"); err != nil {
|
|
b.Fatalf("load conf/models.yaml: %v", err)
|
|
}
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
body, err := json.Marshal(modelListEnvelope(listAvailableModels()))
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
if len(body) == 0 {
|
|
b.Fatal("empty body")
|
|
}
|
|
}
|
|
}
|