// (e) JSON mode with thinking on and off, per model; plus json_object without the word "json" in the prompt. import { raw, MODELS, save } from "./lib.ts"; const out: Record = {}; for (const model of MODELS) { for (const thinking of ["enabled", "disabled"] as const) { const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model, thinking: { type: thinking }, response_format: { type: "json_object" }, max_tokens: 200, messages: [ { role: "system", content: "Extract the person. Output json only, format: {\"name\": string, \"age\": number}" }, { role: "user", content: "Marie is 31 years old." } ] }) }); const b: any = r.body; let parsed: unknown = null; try { parsed = JSON.parse(b.choices?.[0]?.message?.content ?? ""); } catch {} out[`${model}|thinking=${thinking}`] = { status: r.status, content: b.choices?.[0]?.message?.content, parsed, reasoning_len: b.choices?.[0]?.message?.reasoning_content?.length ?? null, finish: b.choices?.[0]?.finish_reason, usage: b.usage, error: r.status !== 200 ? b : undefined }; console.log(model, thinking, r.status, JSON.stringify(b.choices?.[0]?.message?.content ?? b).slice(0, 200), "valid", parsed !== null); } } const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "deepseek-v4-flash", thinking: { type: "disabled" }, response_format: { type: "json_object" }, max_tokens: 100, messages: [{ role: "user", content: "Marie is 31 years old. Give her name and age." }] }) }); out["no-json-word"] = { status: r.status, body: r.body }; console.log("no json word in prompt →", r.status, JSON.stringify(r.body).slice(0, 300)); save("04-json.json", out);