import { post, rawSSE, save, short } from "./lib.ts"; const results: Record = {}; const base = (model: string, extra: any = {}) => ({ model, messages: [{ role: "user", content: "Say OK." }], max_tokens: 30, ...extra }); // glm-5-2 param acceptance for (const [name, extra] of Object.entries({ base: {}, effort_none: { reasoning_effort: "none" }, effort_low: { reasoning_effort: "low" }, effort_medium: { reasoning_effort: "medium" }, effort_xhigh: { reasoning_effort: "xhigh" }, effort_max: { reasoning_effort: "max" }, n_2: { n: 2 }, temp_1_5: { temperature: 1.5 }, stop: { stop: ["."] }, seed: { random_seed: 1 }, penalties: { presence_penalty: 1, frequency_penalty: 1 }, json_schema: { response_format: { type: "json_schema", json_schema: { name: "ok", strict: true, schema: { type: "object", properties: { ok: { type: "boolean" } }, required: ["ok"], additionalProperties: false } } } }, safe_prompt: { safe_prompt: true }, prefix: { messages: [{ role: "user", content: "Say OK." }, { role: "assistant", content: "Sure:", prefix: true }] }, system: { messages: [{ role: "system", content: "Be terse." }, { role: "user", content: "Say OK." }] }, })) { const r = await post("/chat/completions", base("glm-5-2", extra)); const b: any = r.body; const c = b?.choices?.[0]?.message?.content; console.log(`glm ${name.padEnd(14)} ${r.status} ${r.status === 200 ? `finish=${b.choices[0].finish_reason} shape=${Array.isArray(c) ? "arr(" + c.map((x: any) => x.type).join(",") + ")" : typeof c} ct=${b.usage?.completion_tokens} ${short(c, 100)}` : short(b, 250)}`); if (name === "base") console.log(" glm headers", JSON.stringify(r.headers)); results[`glm_${name}`] = r; } // glm stream shape (default effort) const s = await rawSSE("/chat/completions", { model: "glm-5-2", messages: [{ role: "user", content: "Is 17 prime? One sentence." }], max_tokens: 300, stream: true }); const seq: string[] = []; for (const e of s.events) { if (e.data === "[DONE]") continue; const c = e.data?.choices?.[0]?.delta?.content; const shape = c === undefined ? "undef" : typeof c === "string" ? "string" : Array.isArray(c) ? "array:" + c.map((x: any) => x.type).join(",") : typeof c; if (seq[seq.length - 1] !== shape) seq.push(shape); } console.log("glm stream", s.status, "events", s.events.length, "shapes", seq, "last", short(s.events[s.events.length - 2]?.data, 400)); results.glmStream = s; // reasoning_effort "max" on medium; default effort behaviour check (is default none?) const mx = await post("/chat/completions", base("mistral-medium-latest", { reasoning_effort: "max" })); console.log("medium effort=max", mx.status, short(mx.body, 250)); results.mediumMax = mx; // glm reasoning tool call const tools = [{ type: "function", function: { name: "get_weather", description: "Weather for a city", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] } } }]; const gt = await rawSSE("/chat/completions", { model: "glm-5-2", messages: [{ role: "user", content: "Weather in Montreal? Use the tool." }], tools, max_tokens: 300, stream: true }); const td = gt.events.filter((e) => e.data?.choices?.[0]?.delta?.tool_calls).map((e) => e.data.choices[0].delta); const shapes2 = [...new Set(gt.events.filter((e) => e.data !== "[DONE]").map((e) => { const c = e.data?.choices?.[0]?.delta?.content; return c === undefined ? "undef" : typeof c === "string" ? "string" : Array.isArray(c) ? "array:" + c.map((x: any) => x.type).join(",") : typeof c; }))]; console.log("glm tools stream", gt.status, "events", gt.events.length, "shapes", shapes2, "toolDeltas", short(td, 500), "finish", gt.events.map((e) => e.data?.choices?.[0]?.finish_reason).filter(Boolean)); results.glmTools = gt; // hidden system prompt size: empty-ish prompt token counts per model (safe_prompt vs not) on small const a = await post("/chat/completions", base("mistral-small-latest")); const b2 = await post("/chat/completions", base("mistral-small-latest", { safe_prompt: true })); const c2 = await post("/chat/completions", base("mistral-large-latest")); const d2 = await post("/chat/completions", base("mistral-large-latest", { safe_prompt: true })); console.log("prompt_tokens small", (a.body as any).usage.prompt_tokens, "small+safe", (b2.body as any).usage.prompt_tokens, "large", (c2.body as any).usage.prompt_tokens, "large+safe", (d2.body as any).usage.prompt_tokens); // stop sequence in output? is stop string included/excluded const st = await post("/chat/completions", { model: "mistral-small-latest", messages: [{ role: "user", content: "Count: one, two, three, four, five." }], max_tokens: 40, stop: ["three"] }); console.log("stop excluded?", JSON.stringify((st.body as any).choices[0].message.content), (st.body as any).choices[0].finish_reason); // max_tokens > context -> ? const mt = await post("/chat/completions", { model: "ministral-3b-latest", messages: [{ role: "user", content: "Hi" }], max_tokens: 200000 }); console.log("max_tokens 200k on 128k model", mt.status, short(mt.body, 250)); results.maxTokensOver = mt; // Rate-limit 429 body: not forced. save("10-glm-followups.json", results);