import { CHAT_MODELS, post, save, short } from "./lib.ts"; const TOOL = { type: "function", function: { name: "get_weather", description: "Get weather for a city", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] }, }, }; const variants: Record = { base: {}, temperature_0: { temperature: 0 }, temperature_1: { temperature: 1.0 }, temperature_1_5: { temperature: 1.5 }, temperature_2: { temperature: 2.0 }, top_p_0_5: { top_p: 0.5 }, top_k_5: { top_k: 5 }, max_tokens_5: { max_tokens: 5 }, max_completion_tokens_5: { max_completion_tokens: 5 }, stop_array: { stop: ["."] }, stop_string: { stop: "." }, random_seed_42: { random_seed: 42 }, seed_42: { seed: 42 }, presence_penalty_1: { presence_penalty: 1.0 }, presence_penalty_2_5: { presence_penalty: 2.5 }, frequency_penalty_1: { frequency_penalty: 1.0 }, frequency_penalty_neg_2_5: { frequency_penalty: -2.5 }, n_2: { n: 2 }, safe_prompt: { safe_prompt: true }, prompt_mode_reasoning: { prompt_mode: "reasoning" }, reasoning_effort_none: { reasoning_effort: "none" }, reasoning_effort_minimal: { reasoning_effort: "minimal" }, reasoning_effort_low: { reasoning_effort: "low" }, reasoning_effort_medium: { reasoning_effort: "medium" }, reasoning_effort_high: { reasoning_effort: "high" }, reasoning_effort_xhigh: { reasoning_effort: "xhigh" }, reasoning_effort_bogus: { reasoning_effort: "bogus" }, 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: { response_format: { type: "json_schema", json_schema: { name: "ok", strict: true, schema: { type: "object", properties: { ok: { type: "boolean" } }, required: ["ok"], additionalProperties: false }, }, }, }, parallel_tool_calls_false: { tools: [TOOL], parallel_tool_calls: false }, tool_choice_required: { tools: [TOOL], tool_choice: "required", messages: [{ role: "user", content: "Weather in Paris?" }] }, tool_choice_any: { tools: [TOOL], tool_choice: "any", messages: [{ role: "user", content: "Weather in Paris?" }] }, tool_choice_object: { tools: [TOOL], tool_choice: { type: "function", function: { name: "get_weather" } }, messages: [{ role: "user", content: "Weather in Paris?" }], }, logprobs: { logprobs: true }, developer_role: { messages: [{ role: "developer", content: "Be terse." }, { role: "user", content: "Say OK." }] }, system_role: { messages: [{ role: "system", content: "Be terse." }, { role: "user", content: "Say OK." }] }, unknown_param: { foo_bar: 1 }, prediction: { prediction: { type: "content", content: "OK" } }, service_tier_auto: { service_tier: "auto" }, service_tier_standard_only: { service_tier: "standard_only" }, prompt_cache_key: { prompt_cache_key: "polyllm-probe" }, stream_options_nonstream: { stream_options: { include_usage: true } }, assistant_prefix: { messages: [ { role: "user", content: "Say OK." }, { role: "assistant", content: "Sure thing:", prefix: true }, ], }, metadata: { metadata: { app: "polyllm" } }, }; async function pool(items: T[], n: number, fn: (t: T) => Promise) { let i = 0; await Promise.all( Array.from({ length: n }, async () => { while (i < items.length) await fn(items[i++]); }), ); } const results: Record> = {}; for (const model of CHAT_MODELS) { results[model] = {}; console.log(`\n=== ${model}`); await pool(Object.entries(variants), 5, async ([name, v]) => { const payload = { model, messages: [{ role: "user", content: "Say OK." }], max_tokens: 30, ...v }; const r = await post("/chat/completions", payload); const body: any = r.body; let info = ""; if (r.status === 200) { const ch = body.choices?.[0]; const c = ch?.message?.content; const shape = Array.isArray(c) ? "array:" + c.map((x: any) => x.type).join(",") : typeof c; info = `finish=${ch?.finish_reason} choices=${body.choices?.length} content=${shape} ${short(c, 80)} tool_calls=${ch?.message?.tool_calls ? ch.message.tool_calls.length : 0} usage=${JSON.stringify(body.usage)}${ch?.logprobs ? " logprobs=" + short(ch.logprobs, 80) : ""}`; } else { info = short(body, 400); } results[model][name] = { status: r.status, body: r.status === 200 ? { finish: body.choices?.[0]?.finish_reason, content: body.choices?.[0]?.message?.content, usage: body.usage, choices: body.choices?.length } : body }; console.log(`${name.padEnd(30)} ${r.status} ${info}`); }); } save("02-params.json", results);