TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1import { post, rawSSE, save, short } from "./lib.ts";23const results: Record<string, any> = {};4const base = (model: string, extra: any = {}) => ({ model, messages: [{ role: "user", content: "Say OK." }], max_tokens: 30, ...extra });56// glm-5-2 param acceptance7for (const [name, extra] of Object.entries({8 base: {},9 effort_none: { reasoning_effort: "none" },10 effort_low: { reasoning_effort: "low" },11 effort_medium: { reasoning_effort: "medium" },12 effort_xhigh: { reasoning_effort: "xhigh" },13 effort_max: { reasoning_effort: "max" },14 n_2: { n: 2 },15 temp_1_5: { temperature: 1.5 },16 stop: { stop: ["."] },17 seed: { random_seed: 1 },18 penalties: { presence_penalty: 1, frequency_penalty: 1 },19 json_schema: { response_format: { type: "json_schema", json_schema: { name: "ok", strict: true, schema: { type: "object", properties: { ok: { type: "boolean" } }, required: ["ok"], additionalProperties: false } } } },20 safe_prompt: { safe_prompt: true },21 prefix: { messages: [{ role: "user", content: "Say OK." }, { role: "assistant", content: "Sure:", prefix: true }] },22 system: { messages: [{ role: "system", content: "Be terse." }, { role: "user", content: "Say OK." }] },23})) {24 const r = await post("/chat/completions", base("glm-5-2", extra));25 const b: any = r.body;26 const c = b?.choices?.[0]?.message?.content;27 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)}`);28 if (name === "base") console.log(" glm headers", JSON.stringify(r.headers));29 results[`glm_${name}`] = r;30}31// glm stream shape (default effort)32const s = await rawSSE("/chat/completions", { model: "glm-5-2", messages: [{ role: "user", content: "Is 17 prime? One sentence." }], max_tokens: 300, stream: true });33const seq: string[] = [];34for (const e of s.events) {35 if (e.data === "[DONE]") continue;36 const c = e.data?.choices?.[0]?.delta?.content;37 const shape = c === undefined ? "undef" : typeof c === "string" ? "string" : Array.isArray(c) ? "array:" + c.map((x: any) => x.type).join(",") : typeof c;38 if (seq[seq.length - 1] !== shape) seq.push(shape);39}40console.log("glm stream", s.status, "events", s.events.length, "shapes", seq, "last", short(s.events[s.events.length - 2]?.data, 400));41results.glmStream = s;4243// reasoning_effort "max" on medium; default effort behaviour check (is default none?)44const mx = await post("/chat/completions", base("mistral-medium-latest", { reasoning_effort: "max" }));45console.log("medium effort=max", mx.status, short(mx.body, 250));46results.mediumMax = mx;4748// glm reasoning tool call49const tools = [{ type: "function", function: { name: "get_weather", description: "Weather for a city", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] } } }];50const 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 });51const td = gt.events.filter((e) => e.data?.choices?.[0]?.delta?.tool_calls).map((e) => e.data.choices[0].delta);52const 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; }))];53console.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));54results.glmTools = gt;5556// hidden system prompt size: empty-ish prompt token counts per model (safe_prompt vs not) on small57const a = await post("/chat/completions", base("mistral-small-latest"));58const b2 = await post("/chat/completions", base("mistral-small-latest", { safe_prompt: true }));59const c2 = await post("/chat/completions", base("mistral-large-latest"));60const d2 = await post("/chat/completions", base("mistral-large-latest", { safe_prompt: true }));61console.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);6263// stop sequence in output? is stop string included/excluded64const st = await post("/chat/completions", { model: "mistral-small-latest", messages: [{ role: "user", content: "Count: one, two, three, four, five." }], max_tokens: 40, stop: ["three"] });65console.log("stop excluded?", JSON.stringify((st.body as any).choices[0].message.content), (st.body as any).choices[0].finish_reason);6667// max_tokens > context -> ?68const mt = await post("/chat/completions", { model: "ministral-3b-latest", messages: [{ role: "user", content: "Hi" }], max_tokens: 200000 });69console.log("max_tokens 200k on 128k model", mt.status, short(mt.body, 250));70results.maxTokensOver = mt;7172// Rate-limit 429 body: not forced.73save("10-glm-followups.json", results);74