// Probe 04: (f) vision with a tiny inline base64 PNG (2x2, generated in node), per model. import { deflateSync } from "node:zlib"; import { ai, MODELS, SUFFIX, save, errInfo, shortText, withRetry, sleep, PACE_MS } from "./lib.js"; function crc32(buf: Buffer) { let c, crc = 0xffffffff; 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; } return (crc ^ 0xffffffff) >>> 0; } function chunk(type: string, data: Buffer) { const len = Buffer.alloc(4); len.writeUInt32BE(data.length); const td = Buffer.concat([Buffer.from(type, "ascii"), data]); const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td)); return Buffer.concat([len, td, crc]); } // 2x2 RGB: red, green / blue, white const 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; const raw = Buffer.from([0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 255, 255, 255, 255]); const 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))]); const b64 = png.toString("base64"); console.log("png bytes", png.length, "b64", b64); const results: any = {}; for (const model of MODELS) { try { const res = await withRetry(() => ai.models.generateContent({ model, 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." }] }], config: { maxOutputTokens: 1500 }, })); results[model] = { ok: true, text: shortText(res), usage: res.usageMetadata, finishReason: res.candidates?.[0]?.finishReason }; } catch (e) { results[model] = { ok: false, error: errInfo(e) }; } await sleep(PACE_MS); 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)}`); } save(`04-vision${SUFFIX}.json`, results);