// Probe (e): structured output via response_format json_schema (strict). import { CHAT_MODELS, raw, save, short } from "./lib.ts"; const response_format = { type: "json_schema", json_schema: { name: "city_info", strict: true, schema: { type: "object", properties: { city: { type: "string" }, country: { type: "string" }, population_millions: { type: "number" } }, required: ["city", "country", "population_millions"], additionalProperties: false, }, }, }; const results: Record = {}; await Promise.all( CHAT_MODELS.map(async (model) => { const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model, messages: [{ role: "user", content: "Give info about Paris." }], response_format, max_completion_tokens: 300 }), }); const b: any = r.body; let parsed: any = null; try { parsed = JSON.parse(b.choices?.[0]?.message?.content ?? ""); } catch {} results[model] = { status: r.status, content: b.choices?.[0]?.message?.content, parsedOk: !!parsed, usage: b.usage, error: r.status !== 200 ? b : undefined }; console.log(model.padEnd(30), r.status, short(b.choices?.[0]?.message?.content ?? b, 200)); }), ); save("04-structured.json", results);