SPB Git forge

spb/polyllm

Public
15commits 1branches 0releases
2.2 MBsize
maindefault branch
13 days agolast push
TypeScript 97.4% SQL 1% JavaScript 0.9% CSS 0.6%
5.0 KB · 61 lines typescript
Raw Blame History
1import { rawPost, rawGet, save, short, BASE } from "./lib.ts";23const out: Record<string, unknown> = {};4const tiny = { model: "kimi-k2.6", messages: [{ role: "user", content: "hi" }], max_tokens: 5, thinking: { type: "disabled" } };56// (g) invalid key7const bad = await rawPost("/chat/completions", tiny, {}, "sk-invalid-key-000000");8console.log("invalid key:", bad.status, JSON.stringify(bad.body), JSON.stringify(bad.headers));9out.invalidKey = bad;10const badModels = await rawGet("/models", "sk-invalid-key-000000");11console.log("invalid key GET /models:", badModels.status, JSON.stringify(badModels.body));12out.invalidKeyModels = badModels;13// no auth header14const noAuth = await fetch(`${BASE}/chat/completions`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(tiny) });15console.log("no auth:", noAuth.status, (await noAuth.text()).slice(0, 300));16// (h) unknown model17const unk = await rawPost("/chat/completions", { ...tiny, model: "kimi-k99" });18console.log("unknown model:", unk.status, JSON.stringify(unk.body));19out.unknownModel = unk;20// retired slugs21for (const m of ["kimi-k2.5", "kimi-k2-thinking", "moonshot-v1-8k", "kimi-latest", "kimi-k2-0905-preview"]) {22  const r = await rawPost("/chat/completions", { model: m, messages: [{ role: "user", content: "hi" }], max_tokens: 5 });23  console.log(`retired ${m}:`, r.status, short(r.body, 200));24  out[`retired:${m}`] = r;25}26// malformed body27const mal = await fetch(`${BASE}/chat/completions`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${process.env.KIMI_API_KEY}` }, body: "{\"model\":\"kimi-k2.6\",\"messages\":\"nope\"}" });28console.log("malformed messages:", mal.status, (await mal.text()).slice(0, 300));29// missing messages30const miss = await rawPost("/chat/completions", { model: "kimi-k2.6" });31console.log("missing messages:", miss.status, JSON.stringify(miss.body));32out.missingMessages = miss;3334// (j) max output limits: oversize max_tokens per model35for (const [model, mt] of [["kimi-k2.6", 40000], ["kimi-k2.6", 300000], ["kimi-k2.7-code", 300000], ["kimi-k2.7-code-highspeed", 300000], ["kimi-k3", 1048576], ["kimi-k3", 1048577], ["kimi-k3", 2000000]] as const) {36  const r = await rawPost("/chat/completions", { model, messages: [{ role: "user", content: "Reply: ok" }], max_tokens: mt });37  console.log(`max_tokens=${mt} on ${model}:`, r.status, r.status === 200 ? `finish=${(r.body as any).choices[0].finish_reason} usage=${JSON.stringify((r.body as any).usage)}` : short(r.body, 300));38  out[`maxTokens:${model}:${mt}`] = { status: r.status, body: r.status === 200 ? { usage: (r.body as any).usage } : r.body };39}40// context overflow: ~300k tokens of text to k2.6 (262144 ctx)41const big = "lorem ipsum dolor sit amet ".repeat(60000); // ~ 300k+ tokens42const ov = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "user", content: big + "\nReply ok." }], max_tokens: 5, thinking: { type: "disabled" } });43console.log("context overflow k2.6:", ov.status, short(ov.body, 300));44out.contextOverflow = ov;45// tool_choice forced function with thinking enabled on k2.6 (docs: 400)46const forced = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "user", content: "Weather in Montreal?" }], tools: [{ type: "function", function: { name: "get_weather", parameters: { type: "object", properties: { city: { type: "string" } } } } }], tool_choice: { type: "function", function: { name: "get_weather" } }, thinking: { type: "disabled" }, max_tokens: 200 });47console.log("k2.6 forced tool + thinking disabled:", forced.status, short((forced.body as any)?.choices?.[0]?.message?.tool_calls ?? forced.body, 200));48out.forcedToolNoThinking = forced;49// cache hit check: same >256-token prompt twice on k2.6 non-thinking50const long = "You are a helpful assistant. " + "The quick brown fox jumps over the lazy dog. ".repeat(80);51const c1 = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "system", content: long }, { role: "user", content: "Reply: ok" }], max_tokens: 5, thinking: { type: "disabled" } });52await new Promise((r) => setTimeout(r, 1500));53const c2 = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "system", content: long }, { role: "user", content: "Reply: ok" }], max_tokens: 5, thinking: { type: "disabled" } });54console.log("cache probe usage #1:", JSON.stringify((c1.body as any)?.usage), "#2:", JSON.stringify((c2.body as any)?.usage));55out.cache = { c1: (c1.body as any)?.usage, c2: (c2.body as any)?.usage, headers2: c2.headers };56// partial mode57const partial = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "user", content: "Name three colours." }, { role: "assistant", content: "Sure! The three colours are:", partial: true }], max_tokens: 60, thinking: { type: "disabled" } });58console.log("partial mode k2.6 non-thinking:", partial.status, short((partial.body as any)?.choices?.[0]?.message?.content ?? partial.body, 200));59out.partial = partial;60save("05-errors-limits", out);61