TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1import { post, save, short } from "./lib.ts";23// Minimal one-page PDF with a secret word.4function pdf(text: string) {5 const objs: string[] = [];6 objs.push("<< /Type /Catalog /Pages 2 0 R >>");7 objs.push("<< /Type /Pages /Kids [3 0 R] /Count 1 >>");8 objs.push("<< /Type /Page /Parent 2 0 R /MediaBox [0 0 300 144] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>");9 const stream = `BT /F1 18 Tf 20 100 Td (${text}) Tj ET`;10 objs.push(`<< /Length ${stream.length} >>\nstream\n${stream}\nendstream`);11 objs.push("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>");12 let out = "%PDF-1.4\n";13 const offsets: number[] = [];14 objs.forEach((o, i) => {15 offsets.push(out.length);16 out += `${i + 1} 0 obj\n${o}\nendobj\n`;17 });18 const xref = out.length;19 out += `xref\n0 ${objs.length + 1}\n0000000000 65535 f \n`;20 for (const o of offsets) out += `${String(o).padStart(10, "0")} 00000 n \n`;21 out += `trailer\n<< /Size ${objs.length + 1} /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`;22 return Buffer.from(out, "latin1").toString("base64");23}2425const b64 = pdf("The secret word is pamplemousse.");26const results: Record<string, any> = {};27const ask = (model: string, doc: any) =>28 post("/chat/completions", {29 model,30 max_tokens: 60,31 messages: [{ role: "user", content: [{ type: "text", text: "What is the secret word in this document? Answer with the word only." }, doc] }],32 });3334results.base64Small = await ask("mistral-small-latest", { type: "document_url", document_url: `data:application/pdf;base64,${b64}`, document_name: "secret.pdf" });35console.log("small base64 pdf", results.base64Small.status, JSON.stringify(results.base64Small.body?.usage), short(results.base64Small.body?.choices?.[0]?.message?.content ?? results.base64Small.body, 300));3637results.urlSmall = await ask("mistral-small-latest", { type: "document_url", document_url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" });38console.log("small public pdf url", results.urlSmall.status, JSON.stringify(results.urlSmall.body?.usage), short(results.urlSmall.body?.choices?.[0]?.message?.content ?? results.urlSmall.body, 300));3940results.base64Ministral = await ask("ministral-8b-latest", { type: "document_url", document_url: `data:application/pdf;base64,${b64}` });41console.log("ministral-8b base64 pdf", results.base64Ministral.status, JSON.stringify(results.base64Ministral.body?.usage), short(results.base64Ministral.body?.choices?.[0]?.message?.content ?? results.base64Ministral.body, 300));4243results.base64Codestral = await ask("codestral-latest", { type: "document_url", document_url: `data:application/pdf;base64,${b64}` });44console.log("codestral base64 pdf", results.base64Codestral.status, short(results.base64Codestral.body?.choices?.[0]?.message?.content ?? results.base64Codestral.body, 300));4546results.fileType = await ask("mistral-small-latest", { type: "file", file_id: "00000000-0000-0000-0000-000000000000" });47console.log("file type bogus id", results.fileType.status, short(results.fileType.body, 300));4849save("07-document.json", results);50