import { chat, save, MODELS, short } from "./lib.ts"; import { deflateSync } from "node:zlib"; // Build a 32x32 solid red PNG (no deps) 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), data]); const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td)); return Buffer.concat([len, td, crc]); } function png(w: number, h: number) { const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; // bit depth ihdr[9] = 2; // RGB const rows: Buffer[] = []; for (let y = 0; y < h; y++) { const row = Buffer.alloc(1 + w * 3); for (let x = 0; x < w; x++) { row[1 + x * 3] = 220; row[2 + x * 3] = 30; row[3 + x * 3] = 30; } rows.push(row); } return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(Buffer.concat(rows))), chunk("IEND", Buffer.alloc(0))]); } const dataUrl = `data:image/png;base64,${png(32, 32).toString("base64")}`; const out: Record = {}; for (const model of MODELS) { const r = await chat({ model, messages: [{ role: "user", content: [{ type: "text", text: "What colour is this image? One word." }, { type: "image_url", image_url: { url: dataUrl } }] }], max_completion_tokens: 60, }); const b: any = r.body; out[`${model}:png32`] = { status: r.status, content: short(b?.choices?.[0]?.message?.content, 100), usage: b?.usage, error: r.status !== 200 ? b : undefined }; console.log(model, "vision 32x32 png:", r.status, short(r.status === 200 ? { content: b?.choices?.[0]?.message?.content, usage: b?.usage } : b, 400)); } // external URL + detail on the vision-capable model const rUrl = await chat({ model: "qwen-3.8-27b", messages: [{ role: "user", content: [{ type: "text", text: "Describe." }, { type: "image_url", image_url: { url: "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png", detail: "low" } }] }], max_completion_tokens: 40, }); out["qwen:https-url"] = rUrl; console.log("qwen https url:", rUrl.status, short(rUrl.body, 300)); const rDetail = await chat({ model: "qwen-3.8-27b", messages: [{ role: "user", content: [{ type: "text", text: "Colour? One word." }, { type: "image_url", image_url: { url: dataUrl, detail: "high" } }] }], max_completion_tokens: 40, }); out["qwen:detail-high"] = { status: rDetail.status, body: rDetail.status === 200 ? short((rDetail.body as any)?.choices?.[0]?.message?.content, 100) : rDetail.body }; console.log("qwen detail=high:", rDetail.status, short(rDetail.body, 300)); save("05-vision.json", out);