TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1// (a) tiny non-streaming completion (default thinking), (b) streaming with include_usage, per model.2import { client, MODELS, rawSSE, save, errInfo } from "./lib.ts";34const out: Record<string, unknown> = {};5for (const model of MODELS) {6 const t0 = Date.now();7 try {8 const r = await client.chat.completions.create({9 model,10 messages: [{ role: "user", content: "What is 2+2? Answer in one short sentence." }],11 max_tokens: 200,12 });13 out[`${model}:nonstream`] = { ms: Date.now() - t0, response: r };14 console.log(model, "nonstream", Date.now() - t0, "ms", JSON.stringify(r.usage), "finish", r.choices[0].finish_reason, "reasoning?", !!(r.choices[0].message as any).reasoning_content);15 } catch (e) {16 out[`${model}:nonstream`] = errInfo(e);17 console.log(model, "nonstream ERR", JSON.stringify(errInfo(e)));18 }1920 const t1 = Date.now();21 const s = await rawSSE("/chat/completions", {22 model,23 messages: [{ role: "user", content: "Say hello in French, 5 words max." }],24 max_tokens: 200,25 stream: true,26 stream_options: { include_usage: true },27 });28 const deltaKeys = new Set<string>();29 let firstReasoningMs: number | null = null, firstContentMs: number | null = null;30 for (const ev of s.events) {31 if (ev === "[DONE]") continue;32 const d = ev.choices?.[0]?.delta;33 if (d) for (const k of Object.keys(d)) { deltaKeys.add(k); if (d.reasoning_content && firstReasoningMs === null) firstReasoningMs = 0; if (d.content && firstContentMs === null) firstContentMs = 0; }34 }35 out[`${model}:stream`] = { ms: Date.now() - t1, status: s.status, headers: s.headers, comments: s.comments, nEvents: s.events.length, deltaKeys: [...deltaKeys], first3: s.events.slice(0, 3), last4: s.events.slice(-4) };36 console.log(model, "stream", s.status, Date.now() - t1, "ms", s.events.length, "events; delta keys", [...deltaKeys], "comments", s.comments.length);37}38save("01-chat-stream.json", out);39