usage, gui: a reply its vendor let go in a burst over a couple of hundred milliseconds tells no speed, not 2,237 tok/s (John on Discord)
John's Kimi Code rows after v0.1.1119 (OpenCode, group/k3-glm, api.kimi.ai,
Chat, k3-256k): 550 tokens, 22 of them reasoning, in 16 s with the first
content at 5.2 s read 2,237 tok/s, and 395 tokens in 19 s 2,012. 528 answer
tokens at 2,237 tok/s is 236 ms: the burst the vendor let go at the end.
de5455b8 measured how long the content took to come (flow) and took the
window as no longer than it, so a burst sent in one write (flow ~1 ms) fell
under the 100 ms floor and told none, but a burst let go over 236 ms of
many events read its tokens over those 236 ms, under the 10,000 tok/s
ceiling. The time a burst takes to come is not the time it took to write.
usage.DecodeOf now tells no speed for a reply held back and let go at its
end, both ways the burst can show:
- its content came in under a quarter of its window (flow*4 < window):
the text came early, the tool call it wrote over the rest of the time
came at the end (window 10.6 s, flow 236 ms);
- it reasoned, and its answer came over 20 times faster than its
reasoning came between its first content and its first text: the text
came with the burst, so the window from it is the burst itself (22
reasoning tokens over 10.5 s, then 528 in 236 ms). Hidden reasoning
(OpenAI's, Claude's omitted) comes before the first content and leaves
that time short; streamed reasoning comes at its answer's pace.
Between the two the window is the whole window again, not the flow.
routing.js's decodeOf and app.js's ledDecode do the same; docs/reference.md
says it.
Tests: TestKimiHeldBurstTellsNoSpeed, a fake Kimi Code (Chat: four
reasoning_content deltas, then text and a tool call whose arguments come
as 40 writes 6 ms apart over the last 236 ms; usage 538/550/22), through
the real gateway for a Chat, a Responses and an Anthropic agent, with the
wait shortened (first content 1.3 s, end 4 s): the held call and the held
answer tell none (before: 2,112 to 2,237 tok/s on all three), a steady
50 tok/s answer after the same reasoning keeps ~50. TestKimiHeldBurstAtJohnsTimes
feeds firstToken the same streams at John's times (5.2 s, 16 s): before,
2,138 and 2,237 tok/s. TestJohnsRowsTellNoSpeed: his rows as records
(before: 2,237, 2,237, 2,015). routing-burst-speed and usage-speed gain
his rows and a steady 50 tok/s one; they fail on the old routing.js and
app.js ("2237 tok/s", "2,237 tok/s") and pass now in Chromium and WebKit,
en and zh, with reasoning-speed, routing-request-metrics,
usage-ledger-detail, click-scroll, gui-ja, gui-de and i18n-keys.
Run: go test -tags nogui ./internal/... (golang:1.26.8 in Docker, as a
non-root user: as root, internal/agent's TestAside* write-refusal tests
fail because root ignores the file modes they rely on, unrelated to this);
-race -count=5 of the new and the burst tests; go vet (linux, windows,
nogui) on internal/gateway and internal/usage. Not tried against the real
Kimi Code API: the owner's Kimi Code key answers 403 (subscription has no
access), so how Kimi Code lets the reply go is inferred from John's
numbers; which of the two shapes his rows were is not known, and both are
covered.
This commit is contained in:
+9
-7
@@ -261,13 +261,15 @@ first text (`usage.DecodeOf`): hidden reasoning is written before the stream
|
||||
shows anything, so counting it in a window that starts after it read
|
||||
gpt-6.1-sol at hundreds of tok/s. A reply that reasoned and then wrote only
|
||||
tool calls, one not streamed, and a burst (under 100 ms, or over 10,000 tok/s)
|
||||
tell no speed. The window is no longer than the reply's content took to come
|
||||
(`flow_ms`, from a tenth of its bytes to nine tenths, scaled to the whole): a
|
||||
vendor that sends the first words, holds the rest and lets it go in one burst
|
||||
gives a flow of next to none, so such a reply tells no speed instead of its
|
||||
tokens over the wait. History is read the same way, as it keeps the reasoning,
|
||||
the first text and the flow; a record from before the flow was kept is read
|
||||
over its whole window.
|
||||
tell no speed. So does a reply its vendor held back and let go in a burst at
|
||||
its end, however long the burst took to come: one whose content came in under
|
||||
a quarter of its window (`flow_ms`, from a tenth of its bytes to nine tenths,
|
||||
scaled to the whole), or that reasoned and whose answer would have come over
|
||||
20 times faster than its reasoning came before its first text (its text came
|
||||
with the burst). The time a burst takes to come is not the time it took to
|
||||
write, and that time isn't seen. History is read the same way, as it keeps the
|
||||
reasoning, the first text and the flow; a record from before the flow was kept
|
||||
is told by its reasoning's pace alone.
|
||||
|
||||
It lists **accounts** too: each Codex, Claude or other subscription account's
|
||||
tokens and cost, by the account that actually answered — the one that took
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
// John on Discord, again after v0.1.1119: Kimi Code (api.kimi.ai, Chat,
|
||||
// k3-256k) answering OpenCode read 2,237 tok/s for 550 tokens, 22 of them
|
||||
// reasoning, in 16 s with its first content at 5.2 s, and 2,012 tok/s for
|
||||
// 395 tokens in 19 s. The burst those replies came in was let go over a
|
||||
// couple of hundred milliseconds, many events, not in one write, so the
|
||||
// time it took to come passed for the time it took to write.
|
||||
|
||||
// kimiStep is what a fake Kimi Code writes at a moment after the request.
|
||||
type kimiStep struct {
|
||||
at time.Duration
|
||||
events []string
|
||||
}
|
||||
|
||||
// kimiTimed is a fake Kimi Code that writes each step at its moment.
|
||||
type kimiTimed struct {
|
||||
steps map[string][]kimiStep // by the model asked for
|
||||
}
|
||||
|
||||
func (k *kimiTimed) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
var steps []kimiStep
|
||||
for m, s := range k.steps {
|
||||
if strings.Contains(string(body), `"model":"`+m+`"`) {
|
||||
steps = s
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
f := w.(http.Flusher)
|
||||
for _, s := range steps {
|
||||
time.Sleep(time.Until(start.Add(s.at)))
|
||||
io.WriteString(w, strings.Join(s.events, "\n\n")+"\n\n")
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func kimiChunk(delta string) string {
|
||||
return `data: {"id":"chatcmpl-1","object":"chat.completion.chunk","created":1791500000,"model":"k3-256k","choices":[{"index":0,"delta":` + delta + `,"finish_reason":null}]}`
|
||||
}
|
||||
|
||||
func kimiEnd(finish string, out, reasoning int) []string {
|
||||
return []string{
|
||||
`data: {"id":"chatcmpl-1","object":"chat.completion.chunk","created":1791500000,"model":"k3-256k","choices":[{"index":0,"delta":{},"finish_reason":"` + finish + `"}],"usage":{"prompt_tokens":538,"completion_tokens":` + fmt.Sprint(out) + `,"total_tokens":` + fmt.Sprint(538+out) + `,"completion_tokens_details":{"reasoning_tokens":` + fmt.Sprint(reasoning) + `}}}`,
|
||||
`data: [DONE]`,
|
||||
}
|
||||
}
|
||||
|
||||
// kimiShape is one of the ways the reply can have come, each over the same
|
||||
// times: its first content (reasoning) at first, ended at end.
|
||||
type kimiShape struct {
|
||||
name string
|
||||
// the reply tells this speed, 0 for none
|
||||
want float64
|
||||
// reasoning: its usage's; steps gives its output's too
|
||||
reasoning int
|
||||
steps func(first, end time.Duration) (s []kimiStep, out int)
|
||||
}
|
||||
|
||||
// thought: 22 tokens of reasoning, in four deltas 30 ms apart from first.
|
||||
func kimiThought(first time.Duration) []kimiStep {
|
||||
var s []kimiStep
|
||||
for i := range 4 {
|
||||
s = append(s, kimiStep{first + time.Duration(i)*30*time.Millisecond, []string{kimiChunk(`{"reasoning_content":"The user wants the file written. "}`)}})
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// burst: the tool call the vendor held, let go over the last 236 ms in 40
|
||||
// writes of four argument deltas each (John's 550 tokens at 2,237 tok/s:
|
||||
// 528 answer tokens in 236 ms), optionally with the text before it.
|
||||
func kimiBurst(end time.Duration, text bool) []kimiStep {
|
||||
from := end - 236*time.Millisecond
|
||||
var s []kimiStep
|
||||
if text {
|
||||
s = append(s, kimiStep{from, []string{kimiChunk(`{"content":"I'll write the file now."}`)}})
|
||||
}
|
||||
s = append(s, kimiStep{from, []string{kimiChunk(`{"tool_calls":[{"index":0,"id":"write:0","type":"function","function":{"name":"write","arguments":""}}]}`)}})
|
||||
for i := range 40 {
|
||||
var evs []string
|
||||
for range 4 {
|
||||
evs = append(evs, kimiChunk(`{"tool_calls":[{"index":0,"function":{"arguments":"line of the file, "}}]}`))
|
||||
}
|
||||
s = append(s, kimiStep{from + time.Duration(i)*6*time.Millisecond, evs})
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
var kimiShapes = []kimiShape{
|
||||
// its text came after the thought, and the tool call it wrote over the
|
||||
// rest of the time came in a burst at the end: its flow (from its first
|
||||
// text) is the burst, its window from its first text the whole wait
|
||||
{"held call", 0, 22, func(first, end time.Duration) ([]kimiStep, int) {
|
||||
s := kimiThought(first)
|
||||
s = append(s, kimiStep{first + 200*time.Millisecond, []string{kimiChunk(`{"content":"I'll write the file."}`)}})
|
||||
s = append(s, kimiBurst(end, false)...)
|
||||
return append(s, kimiStep{end, kimiEnd("tool_calls", 550, 22)}), 550
|
||||
}},
|
||||
// its text came with the burst, long after its 22 reasoning tokens:
|
||||
// the window from its first text is the burst itself
|
||||
{"held answer", 0, 22, func(first, end time.Duration) ([]kimiStep, int) {
|
||||
s := kimiThought(first)
|
||||
s = append(s, kimiBurst(end, true)...)
|
||||
return append(s, kimiStep{end, kimiEnd("tool_calls", 550, 22)}), 550
|
||||
}},
|
||||
// a steady 50 tok/s answer after the same thought: one token every
|
||||
// 20 ms from 200 ms after the first content to the end
|
||||
{"steady", 50, 22, func(first, end time.Duration) ([]kimiStep, int) {
|
||||
s := kimiThought(first)
|
||||
n := 0
|
||||
for at := first + 200*time.Millisecond; at < end; at += 20 * time.Millisecond {
|
||||
s = append(s, kimiStep{at, []string{kimiChunk(`{"content":"word "}`)}})
|
||||
n++
|
||||
}
|
||||
return append(s, kimiStep{end, kimiEnd("stop", n+22, 22)}), n + 22
|
||||
}},
|
||||
}
|
||||
|
||||
// The reply's speed as each agent's protocol has it, through the real
|
||||
// gateway from a fake Kimi Code: the held replies tell none, the steady one
|
||||
// its 50 tok/s. The wait is shorter than John's (first content at 1.3 s,
|
||||
// the end at 4 s) to keep the test short; the burst is his, 236 ms.
|
||||
// Before, the held call read 1,790 tok/s and the held answer 2,237.
|
||||
func TestKimiHeldBurstTellsNoSpeed(t *testing.T) {
|
||||
fresh(t)
|
||||
const first, end = 1300 * time.Millisecond, 4000 * time.Millisecond
|
||||
agents := []struct{ path, body string }{
|
||||
{"/v1/chat/completions", `{"model":"kimi-code/%s","stream":true,"stream_options":{"include_usage":true},"messages":[{"role":"user","content":"write the file"}],"tools":[{"type":"function","function":{"name":"write","parameters":{"type":"object","properties":{"content":{"type":"string"}}}}}]}`},
|
||||
{"/v1/responses", `{"model":"kimi-code/%s","stream":true,"input":"write the file","tools":[{"type":"function","name":"write","parameters":{"type":"object","properties":{"content":{"type":"string"}}}}]}`},
|
||||
{"/v1/messages", `{"model":"kimi-code/%s","stream":true,"max_tokens":4000,"messages":[{"role":"user","content":"write the file"}],"tools":[{"name":"write","input_schema":{"type":"object","properties":{"content":{"type":"string"}}}}]}`},
|
||||
}
|
||||
// a model for each agent and shape, which the usage is told apart by
|
||||
model := func(a, i int) string { return fmt.Sprintf("k3-%d-%d", a, i) }
|
||||
k := &kimiTimed{steps: map[string][]kimiStep{}}
|
||||
var models []string
|
||||
for a := range agents {
|
||||
for i, sh := range kimiShapes {
|
||||
models = append(models, model(a, i))
|
||||
k.steps[model(a, i)], _ = sh.steps(first, end)
|
||||
}
|
||||
}
|
||||
up := httptest.NewServer(k)
|
||||
t.Cleanup(up.Close)
|
||||
p := provider.Provider{ID: "kimi-code", Name: "Kimi Code", Key: "k", Models: models, Chat: up.URL + "/coding/v1"}
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gw := httptest.NewServer(New().Handler())
|
||||
t.Cleanup(gw.Close)
|
||||
var wg sync.WaitGroup
|
||||
for ai, a := range agents {
|
||||
for i := range kimiShapes {
|
||||
m := model(ai, i)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
res, err := http.Post(gw.URL+a.path, "application/json", strings.NewReader(fmt.Sprintf(a.body, m)))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
b, _ := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
t.Errorf("%s %s: %d %s", a.path, m, res.StatusCode, b)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
recs := usage.Load(time.Time{})
|
||||
for ai, a := range agents {
|
||||
for i, sh := range kimiShapes {
|
||||
var rec *usage.Record
|
||||
for j := range recs {
|
||||
if strings.HasSuffix(recs[j].Model, "/"+model(ai, i)) || recs[j].Model == model(ai, i) {
|
||||
rec = &recs[j]
|
||||
}
|
||||
}
|
||||
if rec == nil {
|
||||
t.Errorf("%s %s: no usage", a.path, sh.name)
|
||||
continue
|
||||
}
|
||||
n, w := rec.Decode()
|
||||
got := 0.0
|
||||
if w > 0 {
|
||||
got = float64(n) * 1000 / float64(w)
|
||||
}
|
||||
ok := got == 0
|
||||
if sh.want > 0 {
|
||||
ok = got > sh.want*0.8 && got < sh.want*1.2
|
||||
}
|
||||
if !ok {
|
||||
t.Errorf("%s %s: %d tokens in %d ms read %.0f tok/s (out %d, reasoning %d, ms %d, ttft %d, first text %d, flow %d); want %v",
|
||||
a.path, sh.name, n, w, got, rec.Output, rec.Reasoning, rec.Millis, rec.TTFT, rec.FirstText, rec.Flow, sh.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The same three at John's own times (first content at 5.2 s, the end at
|
||||
// 16 s, 550 tokens of which 22 reasoning), read by firstToken as the
|
||||
// gateway reads a Chat stream, without waiting them out: the held ones
|
||||
// read 2,237 tok/s before, the held call by its flow and the held answer
|
||||
// by its window from its first text.
|
||||
func TestKimiHeldBurstAtJohnsTimes(t *testing.T) {
|
||||
const first, end = 5200 * time.Millisecond, 16000 * time.Millisecond
|
||||
for _, sh := range kimiShapes {
|
||||
t.Run(sh.name, func(t *testing.T) {
|
||||
f := firstToken{}
|
||||
steps, out := sh.steps(first, end)
|
||||
for _, s := range steps {
|
||||
// as if the request were s.at ago
|
||||
f.start = time.Now().Add(-s.at)
|
||||
f.see([]byte(strings.Join(s.events, "\n\n") + "\n\n"))
|
||||
}
|
||||
reasoning := sh.reasoning
|
||||
ttft, text := f.ms()
|
||||
ms := end.Milliseconds()
|
||||
flow := f.flowFor(reasoning)
|
||||
n, w := usage.DecodeOf(out, reasoning, ms, ttft, text, flow)
|
||||
got := 0.0
|
||||
if w > 0 {
|
||||
got = float64(n) * 1000 / float64(w)
|
||||
}
|
||||
ok := got == 0
|
||||
if sh.want > 0 {
|
||||
ok = got > sh.want*0.9 && got < sh.want*1.1
|
||||
}
|
||||
if !ok {
|
||||
t.Errorf("%d tokens in %d ms read %.0f tok/s (out %d, ttft %d, first text %d, flow %d); want %v", n, w, got, out, ttft, text, flow, sh.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The rows John posted, as their records hold them: 550 tokens (22
|
||||
// reasoning) in 16 s from a first content at 5.2 s, the answer's flow 236
|
||||
// ms, whether its text came early or with the burst; and 395 tokens in
|
||||
// 19 s at 2,012 tok/s, a flow of 196 ms (his row gives no first token; 5.2
|
||||
// s is taken). Before, they read 2,237 and 2,015 tok/s.
|
||||
func TestJohnsRowsTellNoSpeed(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
out, reasoning int
|
||||
ms, ttft, firstText, flow int64
|
||||
}{
|
||||
{"23:11:07, text early", 550, 22, 16000, 5200, 5400, 236},
|
||||
{"23:11:07, text with the burst", 550, 22, 16000, 5200, 15764, 236},
|
||||
{"23:12:56", 395, 0, 19000, 5200, 0, 196},
|
||||
} {
|
||||
if n, w := usage.DecodeOf(c.out, c.reasoning, c.ms, c.ttft, c.firstText, c.flow); w != 0 {
|
||||
t.Errorf("%s: %d tokens in %d ms read %d tok/s; want none", c.name, n, w, int64(n)*1000/w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15685,13 +15685,17 @@ const LED_COLS = [
|
||||
// usage.DecodeOf and routing.js's decodeOf tell them: one that reasoned
|
||||
// counts its answer from its first text, its reasoning written before
|
||||
// the stream showed any (tony on Discord); null when it tells no speed.
|
||||
// Its window is no longer than its content took to come (flow_ms): a
|
||||
// reply held back and sent in one burst tells none (John on Discord)
|
||||
// A reply held back and let go in a burst at its end tells none (John on
|
||||
// Discord): its content came in under a quarter of its window (flow_ms),
|
||||
// or its answer at over 20 times the pace its reasoning came before it
|
||||
const ledDecode = (r) => {
|
||||
if (ledFailed_(r) || !(r.ttft_ms > 0)) return null;
|
||||
const think = r.reasoning > 0, n = think ? r.out - r.reasoning : r.out, from = think ? r.first_text_ms : r.ttft_ms;
|
||||
const w = r.flow_ms > 0 ? Math.min(r.ms - from, r.flow_ms) : r.ms - from;
|
||||
return n > 0 && from > 0 && w >= 100 && n * 1000 <= 10000 * w ? { n, w } : null;
|
||||
const w = r.ms - from;
|
||||
if (!(n > 0 && from > 0 && w >= 100 && n * 1000 <= 10000 * w)) return null;
|
||||
if (r.flow_ms > 0 && r.flow_ms * 4 < w) return null;
|
||||
if (think && n * (r.first_text_ms - r.ttft_ms) > 20 * r.reasoning * w) return null;
|
||||
return { n, w };
|
||||
};
|
||||
// how fast a reply wrote, in tokens a second: 0 when it can't tell
|
||||
const ledRowSpeed = (r) => { const d = ledDecode(r); return d ? d.n / (d.w / 1000) : 0; };
|
||||
|
||||
@@ -257,12 +257,17 @@
|
||||
// the reasoning was written before the stream showed any, OpenAI's
|
||||
// encrypted and its summary sent when done, and counting it read
|
||||
// gpt-6.1-sol at 163 tok/s. The reply's reasoning is its served try's.
|
||||
// The window is no longer than its content took to come (flow): a reply
|
||||
// held back and sent in one burst tells no speed (John on Discord).
|
||||
// A reply held back and let go in a burst at its end tells no speed
|
||||
// (usage.DecodeOf, John on Discord: Kimi Code at 2,237 tok/s): its
|
||||
// content came in under a quarter of its window (flow), or its answer
|
||||
// at over 20 times the pace its reasoning came before its first text.
|
||||
function decodeOf(r, ms, ttft, firstText, flow = r.flow) {
|
||||
const think = reasoningOf(r), n = think > 0 ? r.out - think : r.out, from = think > 0 ? firstText : ttft;
|
||||
const w = flow > 0 ? Math.min(ms - from, flow) : ms - from;
|
||||
return n > 0 && ttft > 0 && from > 0 && w >= 100 && n * 1000 <= 10000 * w ? { n, w } : null;
|
||||
const w = ms - from;
|
||||
if (!(n > 0 && ttft > 0 && from > 0 && w >= 100 && n * 1000 <= 10000 * w)) return null;
|
||||
if (flow > 0 && flow * 4 < w) return null;
|
||||
if (think > 0 && n * (firstText - ttft) > 20 * think * w) return null;
|
||||
return { n, w };
|
||||
}
|
||||
const reasoningOf = (r) => r.reasoning ?? (r.usage?.length ? r.usage[r.usage.length - 1].reasoning || 0 : 0);
|
||||
const speedOf = (r, ms = r.ms, ttft = r.ttft, firstText = r.firstText, flow = r.flow) => {
|
||||
|
||||
@@ -20,11 +20,18 @@ const key = { id: "antigravity", provider: "antigravity", name: "Antigravity", k
|
||||
// and last, a reply whose first words came at 5.1 s and the rest held back
|
||||
// and sent at once (John on Discord: Kimi Code, 1,367 tok/s): its flow says
|
||||
// its content took 2 ms to come
|
||||
const timing = [[8264, 24360, 24359], [8264, 1500, 1000], [1200, 15000, 3000], [100, 3000, 1000], [100, 3000, 1000], [100, 3000, 1000], [2187, 6700, 5100, 2]];
|
||||
const routes = timing.map(([out, ms, ttft, flow], i) => ({
|
||||
// Then John's rows after that fix (Kimi Code again: 2,237 and 2,012 tok/s),
|
||||
// a burst let go over 236 ms and 196 ms: 550 tokens, 22 of them reasoning,
|
||||
// in 16 s with the first content at 5.2 s, its text early (5.4 s) and
|
||||
// with the burst (15.764 s); 395 tokens in 19 s. And a steady 50 tok/s
|
||||
// answer after the same reasoning, which keeps its speed.
|
||||
// [out, ms, ttft, flow, reasoning, firstText]
|
||||
const timing = [[8264, 24360, 24359], [8264, 1500, 1000], [1200, 15000, 3000], [100, 3000, 1000], [100, 3000, 1000], [100, 3000, 1000], [2187, 6700, 5100, 2],
|
||||
[550, 16000, 5200, 236, 22, 5400], [550, 16000, 5200, 236, 22, 15764], [395, 19000, 5200, 196], [552, 16000, 5200, 10600, 22, 5400]];
|
||||
const routes = timing.map(([out, ms, ttft, flow, reasoning, firstText], i) => ({
|
||||
id: 100 - i, seq: 100 - i, time: at(i), agent: "codex", model: "antigravity/gemini-3.8-flash", provider: "antigravity",
|
||||
order: [key], tries: [{ id: key.id, model: key.model, start: at(i), done: true, status: 200, ms, ttft, flow }],
|
||||
done: true, status: 200, ms, ttft, flow, tokens: out + 4087, out,
|
||||
order: [key], tries: [{ id: key.id, model: key.model, start: at(i), done: true, status: 200, ms, ttft, flow, firstText }],
|
||||
done: true, status: 200, ms, ttft, flow, firstText, reasoning, tokens: out + 4087, out,
|
||||
}));
|
||||
|
||||
function serve(lang) {
|
||||
@@ -101,9 +108,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.match(await story(2), want[lang].normal);
|
||||
assert.match(await story(3), want[lang].slow);
|
||||
// a burst after its first words: no speed, not 1,367 tok/s
|
||||
const held = await story(timing.length - 1);
|
||||
const held = await story(6);
|
||||
assert.doesNotMatch(held, want[lang].speed);
|
||||
assert.doesNotMatch(held, /1367|1,367/);
|
||||
// a burst let go over 236 ms after its text, or with it, and over
|
||||
// 196 ms: no speed, not 2,237 or 2,012 tok/s
|
||||
for (const [i, n] of [[7, /2237|2,237/], [8, /2237|2,237/], [9, /2015|2,015|2012|2,012/]]) {
|
||||
const s = await story(i);
|
||||
assert.doesNotMatch(s, want[lang].speed, `row ${i}: ${s}`);
|
||||
assert.doesNotMatch(s, n);
|
||||
}
|
||||
// a steady answer after the same reasoning keeps its 50 tok/s
|
||||
assert.match(await story(10), want[lang].slow);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,6 +33,14 @@ for (let i = 4; i < 30; i++) ROWS.push(row(i, "glm-fast", 135, 600));
|
||||
// one whose content came in a burst (flow_ms, John on Discord: a Kimi Code
|
||||
// reply read 1,367 tok/s): its tokens over the wait tell no speed
|
||||
ROWS[4].flow_ms = 2;
|
||||
// and John's after that fix (Kimi Code: 2,237 tok/s): 550 tokens, 22 of
|
||||
// them reasoning, in 16 s from a first content at 5.2 s, the rest let go
|
||||
// over 236 ms, its text early or with the burst; then a steady 50 tok/s
|
||||
// answer after the same reasoning
|
||||
const kimi = { out: 550, reasoning: 22, ms: 16000, ttft_ms: 5200, flow_ms: 236 };
|
||||
Object.assign(ROWS[5], kimi, { first_text_ms: 5400 });
|
||||
Object.assign(ROWS[6], kimi, { first_text_ms: 15764 });
|
||||
Object.assign(ROWS[7], kimi, { out: 552, first_text_ms: 5400, flow_ms: 10600 });
|
||||
|
||||
const FAST = { id: "glm-fast", calls: 28, input: 1, output: 3780, cache_read: 0, cache_write: 0, cost: 0.3, timed: 27, ttft_ms: 27 * 600, decode_ms: 27 * 1800, decode_out: 27 * 135 };
|
||||
const SLOW = { id: "kimi-slow", calls: 1, input: 1, output: 20, cache_read: 0, cache_write: 0, cost: 0.01, timed: 1, ttft_ms: 600, decode_ms: 2000, decode_out: 20 };
|
||||
@@ -123,6 +131,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal((await cell(1).textContent()).trim(), w.slow);
|
||||
assert.equal((await cell(3).textContent()).trim(), "—");
|
||||
assert.equal((await cell(4).textContent()).trim(), "—");
|
||||
assert.equal((await cell(5).textContent()).trim(), "—");
|
||||
assert.equal((await cell(6).textContent()).trim(), "—");
|
||||
assert.equal((await cell(7).textContent()).trim(), lang === "en" ? "50 tok/s" : "50 token/秒");
|
||||
|
||||
// the table fits the window; what it leaves out is in the details
|
||||
const wrap = p.locator("#ledWrap");
|
||||
|
||||
+38
-8
@@ -352,11 +352,29 @@ func DecodeWindow(out int, ms, ttft int64) int64 {
|
||||
// hold, and counting them read a 2,000-token think and a 200-token answer
|
||||
// in 1.5 s as 1,467 tok/s. Its time goes to the wait before the answer.
|
||||
// One with reasoning and no text (all tool calls) tells no speed. The
|
||||
// window is DecodeWindow's: 0 for a reply that tells none. flow, when
|
||||
// known (Record.Flow), is how long its content took to come, and the
|
||||
// window is no longer than it: a reply whose first words came at once
|
||||
// and the rest held back and sent in a burst at its end wrote nothing
|
||||
// in between, and its tokens over the wait read an impossible speed.
|
||||
// window is DecodeWindow's: 0 for a reply that tells none.
|
||||
//
|
||||
// A reply its vendor held back and let go in a burst at its end tells
|
||||
// none either (John on Discord: Kimi Code answering OpenCode read 1,367,
|
||||
// then 2,237 and 2,012 tok/s). The burst is told two ways, as the reply's
|
||||
// text came before it or with it:
|
||||
//
|
||||
// - flow, when known (Record.Flow), is how long its content took to come
|
||||
// from where its window starts. A window HeldShare times longer had
|
||||
// its content come in a small part of it: the rest was a wait while
|
||||
// the vendor wrote and held it. The time it took to come is not the
|
||||
// time it took to write (a burst let go over 236 ms read 528 tokens at
|
||||
// 2,237 tok/s), and that time is not seen, so it tells no speed. A
|
||||
// stream that came as it was written has a flow about its window.
|
||||
// - a reply that reasoned is timed from its first text, its reasoning
|
||||
// written before. When the answer would have been written over
|
||||
// ThinkPace times faster than its reasoning came before it, from the
|
||||
// first content to the first text, its first text came with the burst
|
||||
// and the wait before it was the answer being written and held (22
|
||||
// reasoning tokens over 10.5 s, then 528 answer tokens in 236 ms). A
|
||||
// reasoning hidden from the stream (OpenAI's, Claude's omitted) comes
|
||||
// before the first content and leaves this time short; one that
|
||||
// streams comes at the pace its answer does.
|
||||
func DecodeOf(out, reasoning int, ms, ttft, firstText, flow int64) (tokens int, w int64) {
|
||||
start := ttft
|
||||
if reasoning > 0 {
|
||||
@@ -365,15 +383,27 @@ func DecodeOf(out, reasoning int, ms, ttft, firstText, flow int64) (tokens int,
|
||||
if ttft <= 0 {
|
||||
return 0, 0
|
||||
}
|
||||
if flow > 0 && start > 0 && start+flow < ms {
|
||||
ms = start + flow
|
||||
}
|
||||
if w = DecodeWindow(out, ms, start); w == 0 {
|
||||
return 0, 0
|
||||
}
|
||||
if flow > 0 && flow*HeldShare < w {
|
||||
return 0, 0
|
||||
}
|
||||
if reasoning > 0 && int64(out)*(firstText-ttft) > ThinkPace*int64(reasoning)*w {
|
||||
return 0, 0
|
||||
}
|
||||
return out, w
|
||||
}
|
||||
|
||||
// HeldShare and ThinkPace tell a reply held back and let go in a burst
|
||||
// (DecodeOf): its content came in under a quarter of its window, or its
|
||||
// answer at over 20 times the pace its reasoning came. routing.js's
|
||||
// decodeOf and app.js's ledDecode have the same.
|
||||
const (
|
||||
HeldShare = 4
|
||||
ThinkPace = 20
|
||||
)
|
||||
|
||||
// Decode is the record's DecodeOf.
|
||||
func (r Record) Decode() (tokens int, w int64) {
|
||||
return DecodeOf(r.Output, r.Reasoning, r.Millis, r.TTFT, r.FirstText, r.Flow)
|
||||
|
||||
Reference in New Issue
Block a user