TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1// Probe 04: (f) vision with a tiny inline base64 PNG (2x2, generated in node), per model.2import { deflateSync } from "node:zlib";3import { ai, MODELS, SUFFIX, save, errInfo, shortText, withRetry, sleep, PACE_MS } from "./lib.js";45function crc32(buf: Buffer) {6 let c, crc = 0xffffffff;7 for (let n = 0; n < buf.length; n++) { c = (crc ^ buf[n]) & 0xff; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; crc = (crc >>> 8) ^ c; }8 return (crc ^ 0xffffffff) >>> 0;9}10function chunk(type: string, data: Buffer) {11 const len = Buffer.alloc(4); len.writeUInt32BE(data.length);12 const td = Buffer.concat([Buffer.from(type, "ascii"), data]);13 const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td));14 return Buffer.concat([len, td, crc]);15}16// 2x2 RGB: red, green / blue, white17const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(2, 0); ihdr.writeUInt32BE(2, 4); ihdr[8] = 8; ihdr[9] = 2; ihdr[10] = 0; ihdr[11] = 0; ihdr[12] = 0;18const raw = Buffer.from([0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 255, 255, 255, 255]);19const png = Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(raw)), chunk("IEND", Buffer.alloc(0))]);20const b64 = png.toString("base64");21console.log("png bytes", png.length, "b64", b64);2223const results: any = {};24for (const model of MODELS) {25 try {26 const res = await withRetry(() => ai.models.generateContent({27 model,28 contents: [{ role: "user", parts: [{ inlineData: { mimeType: "image/png", data: b64 } }, { text: "This is a tiny 2x2 pixel image. List the colours you can identify, comma-separated." }] }],29 config: { maxOutputTokens: 1500 },30 }));31 results[model] = { ok: true, text: shortText(res), usage: res.usageMetadata, finishReason: res.candidates?.[0]?.finishReason };32 } catch (e) { results[model] = { ok: false, error: errInfo(e) }; }33 await sleep(PACE_MS);34 console.log(model.padEnd(24), results[model].ok ? `OK "${results[model].text.slice(0, 60)}" promptTokens=${results[model].usage?.promptTokenCount} details=${JSON.stringify(results[model].usage?.promptTokensDetails)}` : `FAIL ${results[model].error.message.slice(0, 200)}`);35}36save(`04-vision${SUFFIX}.json`, results);37