import { MODELS, rawPost, save, short, sleep, WEATHER_TOOL } from "./lib.ts"; const base = (model: string) => ({ model, messages: [{ role: "user", content: "Reply with the single word: ok" }], max_tokens: 60 }); const variants: Array<[string, Record]> = [ ["temperature=0", { temperature: 0 }], ["temperature=0.5", { temperature: 0.5 }], ["temperature=1", { temperature: 1 }], ["temperature=1.5", { temperature: 1.5 }], ["temperature=2", { temperature: 2 }], ["top_p=0.5", { top_p: 0.5 }], ["top_p=0.95", { top_p: 0.95 }], ["max_completion_tokens=60 (no max_tokens)", { max_tokens: undefined, max_completion_tokens: 60 }], ["stop=[\\n]", { stop: ["\n"] }], ["stop=6 items", { stop: ["a", "b", "c", "d", "e", "f"] }], ["frequency_penalty=0.5", { frequency_penalty: 0.5 }], ["frequency_penalty=0", { frequency_penalty: 0 }], ["presence_penalty=0.5", { presence_penalty: 0.5 }], ["presence_penalty=0", { presence_penalty: 0 }], ["n=2", { n: 2 }], ["n=1", { n: 1 }], ["seed=42", { seed: 42 }], ["logprobs=true,top_logprobs=2", { logprobs: true, top_logprobs: 2 }], ["thinking=enabled", { thinking: { type: "enabled" } }], ["thinking=disabled", { thinking: { type: "disabled" } }], ["thinking=enabled,keep=all", { thinking: { type: "enabled", keep: "all" } }], ["reasoning_effort=low", { reasoning_effort: "low" }], ["reasoning_effort=high", { reasoning_effort: "high" }], ["reasoning_effort=max", { reasoning_effort: "max" }], ["reasoning_effort=medium", { reasoning_effort: "medium" }], ["reasoning_effort=none", { reasoning_effort: "none" }], ["response_format=json_object", { response_format: { type: "json_object" }, messages: [{ role: "user", content: "Return a JSON object with key ok set to true." }] }], ["response_format=json_schema strict", { response_format: { type: "json_schema", json_schema: { name: "ok", strict: true, schema: { type: "object", properties: { ok: { type: "boolean" } }, required: ["ok"], additionalProperties: false } } }, messages: [{ role: "user", content: "Return ok=true as JSON." }] }], ["tools+tool_choice=auto", { tools: [WEATHER_TOOL], tool_choice: "auto" }], ["tools+tool_choice=none", { tools: [WEATHER_TOOL], tool_choice: "none" }], ["tools+tool_choice=required", { tools: [WEATHER_TOOL], tool_choice: "required", messages: [{ role: "user", content: "Weather in Montreal?" }] }], ["tools+tool_choice=function", { tools: [WEATHER_TOOL], tool_choice: { type: "function", function: { name: "get_weather" } }, messages: [{ role: "user", content: "Weather in Montreal?" }] }], ["tools+parallel_tool_calls=false", { tools: [WEATHER_TOOL], parallel_tool_calls: false }], ["tools+parallel_tool_calls=true", { tools: [WEATHER_TOOL], parallel_tool_calls: true }], ["unknown param foo_bar", { foo_bar: 1 }], ["developer role", { messages: [{ role: "developer", content: "Be terse." }, { role: "user", content: "Reply with the single word: ok" }] }], ["max_tokens=1 (truncation)", { max_tokens: 1 }], ]; import { existsSync, readFileSync } from "node:fs"; const prevPath = new URL("./out/02-params.json", import.meta.url); const prev: Record = existsSync(prevPath) ? JSON.parse(readFileSync(prevPath, "utf8")) : {}; const onlyModels = process.argv.slice(2); const all: Record = { ...prev }; for (const model of MODELS) { if (onlyModels.length && !onlyModels.includes(model)) continue; const prevRows: any[] = prev[model] ?? []; const rows: any[] = []; for (const [label, patch] of variants) { const old = prevRows.find((r) => r.label === label); if (old && old.status === 200 || old && old.status === 400) { rows.push(old); continue; } // keep definitive results, redo 429s await sleep(700); const body: Record = { ...base(model), ...patch }; for (const k of Object.keys(body)) if (body[k] === undefined) delete body[k]; let r: any; try { r = await rawPost("/chat/completions", body); } catch (e: any) { r = { status: "EXC", body: String(e) }; } const ch = r.body?.choices?.[0]; const row = { label, status: r.status, finish: ch?.finish_reason ?? null, content: short(ch?.message?.content, 80), hasReasoning: typeof ch?.message?.reasoning_content === "string" && ch.message.reasoning_content.length > 0, toolCalls: ch?.message?.tool_calls?.length ?? 0, usage: r.body?.usage ?? null, error: r.status === 200 ? null : r.body?.error ?? r.body, nChoices: r.body?.choices?.length ?? null, logprobs: ch?.logprobs ? "present" : null, }; rows.push(row); console.log(`[${model}] ${label.padEnd(42)} ${r.status} finish=${row.finish} reasoning=${row.hasReasoning} tc=${row.toolCalls} ${r.status !== 200 ? short(row.error, 220) : short(row.content, 40)}`); } all[model] = rows; save("02-params", all); } save("02-params", all);