skingstyle48487 on X runs more than ten relays and asked for something like the "pelican test" to spot one that waters a model down. In a follow-up (2122694296054972815) they said speed, failures and the model's name show whether a relay is fast and stable, not whether the model got weaker. They asked for small tests with known answers, the share of right answers and of right tool calls, and relays compared side by side. On Usage › Requests › Model speed › Providers, each row has a Check… that opens a dialog. Opening it sends nothing; only its Check makes the calls. POST /api/relay-check (gateway.CheckRelay) makes 6 small streamed Chat Completions calls through the gateway, pinned to provider/model as an agent would, three at a time: - write 1 to 40; - 1234 × 5678, 987 × 654 and 2468 × 1357; - weather in Paris and time in Tokyo, each call offering both tools, so the right one has to be picked. Each part says what it found, never a verdict on the provider: - whether the answer was the expected one, and what came back; - the model the reply named, when the ledger would call it another model (usage.Swapped, not SameSpelled or ListedAs); - the provider that answered, when the call was handed on; - how many input tokens the 118-character prompt was counted as; - first token, tok/s and the whole time. The dialog heads the parts with "Answers right: n of m" and "Right tool calls: n of m". The numbers come from the gateway's own usage records (a tap in appendUsage keyed on the request's context), not from each protocol's reply. The tally of each provider's last check is kept in the window's storage. The Providers table then shows Answers and Tool calls columns: sortable, amber when short of all, a dash for providers not checked, so relays are compared side by side. The dialog code is a lazily loaded root script (relaycheck.js), as app.js has no room left. Run, at this head: - mote: go test -timeout 45m ./internal/gateway ./internal/gui ./internal/cli ./internal/usage: ok (the full ./... suite passed at 41d88731c, before the fixed-answer calls; mote and mica were each running another session's GUI suite at this head); - gofmt -l, GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: clean; - go test -run 'CheckRelay|ReadChatStream' -v ./internal/gateway (5 tests pass); - usage-model-speed.test.cjs, chromium and webkit, en, zh, zh-TW, ja and de at 400px: 12/12; - i18n-keys and old-webkit: their only reds are the three on origin/main, each filed (#6877 ", with an image", #5919 :has(), #6030 headerpresets.js); - TestCoreScriptBudget and the app.js budget: ok, not raised. Broken by hand: - taking tapUsage out of appendUsage turns TestCheckRelayAnsweredAsAsked and TestCheckRelaySaysWhatDiffers red; - dropping the tool-name check turns TestCheckRelayCountsEachAnswer red (get_weather for Tokyo read as right); - pressing Check as the dialog opens turns the GUI test red ("opening the dialog sends no call"). Not tried: - the whole GUI suite at this head (both machines busy with another session's suite); - a real relay (fakes only); - a context-window probe; - a comparison with the vendor's own count_tokens; - a periodic check (the check runs only on a press).
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package gui
|
||
|
||
import (
|
||
"encoding/json"
|
||
"errors"
|
||
"net/http"
|
||
"slices"
|
||
|
||
"github.com/yetone/magpie/internal/gateway"
|
||
)
|
||
|
||
// Settings › Models' Check (EV_John_Liu on X): each pipeline besides chat
|
||
// (image generation, speech-to-text, text-to-speech, web search) checked
|
||
// with one real call through the gateway, as an agent's would go. Each
|
||
// costs the user what the call costs, so only a press runs one.
|
||
func handlePipelineCheck(rw http.ResponseWriter, r *http.Request) {
|
||
var in struct{ Kind string }
|
||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||
fail(rw, err)
|
||
return
|
||
}
|
||
if !slices.Contains(gateway.Pipelines, in.Kind) {
|
||
fail(rw, errors.New("no such pipeline: "+in.Kind))
|
||
return
|
||
}
|
||
gw := served.Load()
|
||
if gw == nil {
|
||
fail(rw, errors.New("Another magpie serves the gateway: check there"))
|
||
return
|
||
}
|
||
writeJSON(rw, gw.CheckPipeline(r.Context(), in.Kind))
|
||
}
|
||
|
||
// handleRelayCheck checks one model on one provider with a few small real
|
||
// calls (gateway.CheckRelay), made only when the user presses Check.
|
||
func handleRelayCheck(rw http.ResponseWriter, r *http.Request) {
|
||
var in struct{ Provider, Model string }
|
||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||
fail(rw, err)
|
||
return
|
||
}
|
||
if in.Provider == "" || in.Model == "" {
|
||
fail(rw, errors.New("a check needs a provider and a model"))
|
||
return
|
||
}
|
||
gw := served.Load()
|
||
if gw == nil {
|
||
fail(rw, errors.New("Another magpie serves the gateway: check there"))
|
||
return
|
||
}
|
||
writeJSON(rw, gw.CheckRelay(r.Context(), in.Provider, in.Model))
|
||
}
|