Files

220 lines
11 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The landing's figures, each derived from a document the page reads and drawn only
* while that document still says it.
*
* the race the research API's coding.repair runs (lib/coding)
* the boards the research API's enso.* runs (lib/enso): GPQA Diamond, LiveCodeBench
* the prices the price list, GET /v1/pricing (lib/api/read)
* the clock the Decision Suite's cost row and the served decision.latency run (lib/kai)
* the prefill Zen 6's throughput, measured by Hanzo (components/zen/desks)
*
* Nothing here types a score, a price, a time or a count. What is typed is
* which rows a figure reads: the SKUs we sell, by the names both catalogs bill
* them under, and the served latency run's id.
*
* The one figure that divides two costs is lib/enso's: each run's tokens at
* the price list's rate for its own model id (`tile`), the same line the
* landing, /benchmarks and /enso draw. The boards here are drawn by accuracy
* and the price chart by the price list.
*/
import { rate, type Pricing } from './api/read'
import { ahead as solvedMore, gains, type Coding, type Side, type Speed } from './coding'
import { CODE, GPQA, NEW, SEEN, date, named, pct, sku, usd as cost, type Board as EnsoBoard, type Enso, type Routed, type Rung } from './enso'
import { ahead, faster, type Run, type Table } from './kai'
import { topped } from './tally'
/* ---- the race: Hanzo Dev and Claude Code on the same coding tasks ---- */
/** The names the coding runs' systems go by on a page. */
const AGENTS: Record<string, string> = { 'claude-code': 'Claude Code', 'hanzo-dev': 'Hanzo Dev' }
/** One side of the race: its run, its name, its median seconds and model calls a task, and how many tasks it solved. */
export type Lane = { run: string; name: string; seconds: number; calls: number | null; solved: number; of: number }
/**
* Both sides, the paired speed over the tasks both solved, the paths Hanzo Dev
* settled a task by that are resolved gains, and whether the solved counts are
* drawn (only while Hanzo Dev solved more).
*/
export type Race = { base: Lane; ours: Lane; speed: Speed; paths: Speed[]; solved: boolean; split: string; ended: string }
const lane = (s: Side): Lane | null =>
s.median == null ? null : { run: s.id, name: AGENTS[s.system] ?? s.system, seconds: s.median, calls: s.calls, solved: s.solved, of: s.of }
/** The race the coding runs hold, or null while either side has no median (lib/coding draws it only while the speed is a resolved gain). */
export function race(c: Coding | null): Race | null {
if (!c) return null
const base = lane(c.base)
const ours = lane(c.ours)
if (!base || !ours || !(ours.seconds < base.seconds)) return null
return { base, ours, speed: c.speed, paths: gains(c.paths).filter((p) => p.n != null && p.n > 0), solved: solvedMore(c), split: c.split, ended: c.ended }
}
/* ---- the boards: accuracy, run by run ---- */
/**
* A bar as a board draws it: its key, name, the accuracy it is drawn at,
* whether it is ours, the price-list id its lab's mark is read from (none for
* a row that names no lab), and what is said beside its figure.
*/
export type Bar = { key: string; system: string; name: string; accuracy: number; ours: boolean; mark: string | null; aside: string | null }
/** Bars under one heading; a board of one group has none. */
export type Group = { title: string | null; rows: Bar[] }
/** A board as the page draws it: its groups, what its window says of it, the lead it gives, and the line under it. */
export type Bars = {
id: string
label: string
groups: Group[]
aside: string | null
/** Who the board leads with, its figure, its count against the next row, the set it is on, and the day it was measured. */
lead: { who: string; figure: string; note: string; set: string | null; measured: string }
foot: string
}
const run = (r: Rung): Bar => ({ key: `${r.system}-${r.tag}`, system: r.system, name: named(r.system), accuracy: r.accuracy, ours: r.ours, mark: r.sku?.id ?? null, aside: null })
/**
* One board, read for the page: the router (`enso`) and the single models,
* kept only while the router outscores every one of them (lib/tally
* `topped`), so a rerun that loses the lead takes the board off the page.
*/
export function bars(e: Enso, id: string): Bars | null {
const b: EnsoBoard | undefined = e.boards.find((x) => x.id === id)
if (!b) return null
const rows = topped(
b.rows.filter((r) => !r.ours || r.system === 'enso').map((r) => ({ ...r, value: r.accuracy })),
(r) => r.ours,
)
const enso = rows.find((r) => r.ours)
const next = rows.find((r) => !r.ours)
if (!enso || !next || enso.correct == null || enso.n == null) return null
return {
id: b.id,
label: b.label,
groups: [{ title: null, rows: rows.map(run) }],
aside: `${enso.n} questions`,
lead: {
who: 'Enso',
figure: pct(enso.accuracy),
note: `${enso.correct} of ${enso.n} right, against ${pct(next.accuracy)} for ${next.system}, the next model on the same questions.`,
set: null,
measured: date(enso.ended),
},
foot: `Enso as enso-bench measured it on ${date(enso.ended)}, beside each single model on the same questions. Each bar is a run's accuracy.`,
}
}
const routed = (r: Routed, aside: string | null): Bar => ({ key: `${r.system}-${r.n}`, system: r.system, name: r.name, accuracy: r.accuracy, ours: r.ours, mark: null, aside })
const per1k = (r: Routed) => (r.per1k != null ? `${cost(r.per1k)} per 1k` : null)
/**
* GPQA Diamond as the landing leads with it: Enso routed on new questions,
* the tiers ahead of the best single model and that model, each with what
* 1,000 questions cost; beside them, the tiers on questions they have seen,
* each figure said with its set (lib/enso `routing`). Without a routing, the
* router's board.
*/
export function gpqa(e: Enso): Bars | null {
const r = e.routing
if (!r) return bars(e, GPQA)
const top = r.fresh[0]
return {
id: GPQA,
label: r.label,
groups: [
{ title: NEW, rows: [...r.fresh, r.best].map((x) => routed(x, per1k(x))) },
...(r.seen.length ? [{ title: SEEN, rows: r.seen.map((x) => routed(x, 'questions it has seen')) }] : []),
],
aside: null,
lead: {
who: top.name,
figure: pct(top.accuracy),
note: `${top.correct != null && top.n != null ? `${top.correct} of ${top.n} new questions` : 'New questions'} right, against ${pct(r.best.accuracy)} for the best single model on the same questions.`,
set: NEW,
measured: date(top.ended),
},
foot: 'Each bar is a research run. New questions are ones Enso had never seen, the same for every row; beside each, what 1,000 of them cost.',
}
}
export const livecode = (e: Enso) => bars(e, CODE)
/* ---- the price per million tokens ---- */
/** The SKUs we sell up front, by the name both the price list and the model list bill them under: `enso` is the one lib/enso prices the router's runs at. */
const OURS: Record<string, string> = { kai: 'Kai', enso: 'Enso', 'enso-flash': 'Enso Flash', 'enso-pro': 'Enso Pro' }
/** A row of the chart: dollars per million input and output tokens. */
export type Rate = { id: string; name: string; ours: boolean; input: number; output: number }
export type Prices = { rows: Rate[]; updated: string | null; top: number }
/**
* The chart: every single model GPQA Diamond's board measured, at the rate the
* price list states for the model id its runs are priced at (lib/enso `sku`),
* beside each SKU of ours the list prices, dearest output first. No row is left
* out for costing less than ours.
*/
export function prices(doc: Pricing, e: Enso): Prices | null {
const board = e.boards.find((b) => b.id === GPQA)
const field: Rate[] = (board?.rows ?? [])
.filter((r) => !r.ours)
.flatMap((r) => {
const m = sku(doc, r.system)
return m ? [{ id: m.id, name: m.name, ours: false, input: m.input, output: m.output }] : []
})
const ours: Rate[] = Object.entries(OURS).flatMap(([id, name]) => {
const p = rate(doc, id)
return p?.input != null && p.output != null ? [{ id, name, ours: true, input: p.input, output: p.output }] : []
})
if (!field.length || !ours.length) return null
const rows = [...new Map([...field, ...ours].map((r) => [r.id, r])).values()].sort((a, b) => b.output - a.output || b.input - a.input)
return { rows, updated: doc.updated ?? null, top: Math.max(...rows.map((r) => Math.max(r.input, r.output))) }
}
/** A rate as the chart prints it: a whole dollar bare, cents from a dollar up, and every digit the price list gives below one. */
export const usd = (v: number) => (Number.isInteger(v) ? `$${v}` : v >= 1 ? `$${v.toFixed(2)}` : `$${v}`)
/* ---- the clock: one decision ---- */
/** The served run: `kai serve` on GPU, runtime and HTTP transport, wall time at the client. */
const SERVED = { id: 'decision.latency-window2-dgx.cuda.n1.transport-kai', same: 'cached/runtime/cuda/n1', fresh: 'cached/http/cuda/n1' }
/**
* One decision timed four ways, each a p50 in milliseconds: cached in process
* on a GPU, served on GPU runtime and over HTTP transport, and one hosted API
* call; and how many times faster the cached one is than the hosted call.
*/
export type Clock = { cached: number; same: number | null; fresh: number | null; hosted: number; times: number; run: string | null }
const p50 = (r: Run | undefined, category: string) => r?.measures?.find((m) => m.category === category && m.metric === 'p50ms')?.value ?? null
/** The clock, once the cost row's latency runs are public; the served lanes only while their run is. */
export function clock(t: Table, runs: Run[]): Clock | null {
const time = t.tasks.find((x) => x.key === 'cost')?.timing
if (!time) return null
const gpu = time.cached[0]
const served = runs.find((r) => r.id === SERVED.id)
return {
cached: gpu,
same: p50(served, SERVED.same),
fresh: p50(served, SERVED.fresh),
hosted: time.hosted,
times: faster({ ...time, cached: [gpu, gpu] }),
run: served ? served.id : null,
}
}
/** A p50 as a sentence says it, in milliseconds: a tenth under ten, whole above. */
export const ms = (v: number) => (v < 10 ? v.toFixed(1) : `${Math.round(v)}`)
/* ---- the Decision Suite as a grid ---- */
/** The tasks of the suite Kai wins, each with the day it was set; null while the suite is not whole. */
export function tasks(t: Table, fixed: string): { label: string; set: string }[] | null {
return t.whole ? t.tasks.filter((x) => ahead(x)).map((x) => ({ label: x.label, set: x.added ?? fixed })) : null
}
/* ---- the prefill ---- */
/** The leading figure of a reading, the conservative end: `~2,400` reads 2400, `1,150–1,400` reads 1150. */
export const lead = (shown: string) => Number((/[\d,.]+/.exec(shown)?.[0] ?? '0').replace(/,/g, ''))