TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1// Probe 08: raw REST streaming protocol (alt=sse) and the default (no alt) JSON-array streaming, on one model.2import { KEY, MODELS, save } from "./lib.js";3const model = MODELS[0];4const body = JSON.stringify({ contents: [{ role: "user", parts: [{ text: "Say hello in five words, then think of nothing else." }] }], generationConfig: { maxOutputTokens: 1500, thinkingConfig: { includeThoughts: true, thinkingLevel: "LOW" } } });5const results: any = { model };6{7 const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${model}:streamGenerateContent?alt=sse`, { method: "POST", headers: { "x-goog-api-key": KEY, "content-type": "application/json" }, body });8 const raw = await res.text();9 const events = raw.split("\n\n").filter((s) => s.trim());10 results.sse = { status: res.status, contentType: res.headers.get("content-type"), transferEncoding: res.headers.get("transfer-encoding"), eventCount: events.length, firstEventRaw: events[0]?.slice(0, 1500), lastEventRaw: events.at(-1)?.slice(0, 1500), linePrefixes: [...new Set(events.flatMap((e) => e.split("\n").map((l) => l.split(":")[0])))] };11 console.log("SSE", res.status, results.sse.contentType, "events", events.length, "prefixes", results.sse.linePrefixes);12 console.log(events[0]?.slice(0, 600));13}14{15 const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${model}:streamGenerateContent`, { method: "POST", headers: { "x-goog-api-key": KEY, "content-type": "application/json" }, body });16 const raw = await res.text();17 results.noAlt = { status: res.status, contentType: res.headers.get("content-type"), startsWith: raw.slice(0, 120), endsWith: raw.slice(-60) };18 console.log("no-alt", res.status, results.noAlt.contentType, JSON.stringify(results.noAlt.startsWith));19}20save(`08-rest-sse-${model}.json`, results);21