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%
3.6 KB · 60 lines typescript
Raw Blame History
1// Probe 06: error shapes — invalid key, no auth, unknown model, malformed body, bad image, streaming error, key endpoints with bad key.2import { raw, rawSSE, save, short } from "./lib.ts";3import { OPENAI, DEEPSEEK } from "./models.ts";45const results: any = {};6async function rec(name: string, p: Promise<any>) {7  const r = await p;8  results[name] = r;9  console.log(`\n[${name}] ${r.status} ${JSON.stringify(r.headers)}\n  ${short(r.body ?? r.error ?? r.events, 500)}`);10}1112const tiny = { model: OPENAI, messages: [{ role: "user", content: "hi" }], max_tokens: 5 };13await rec("invalid_key_chat", raw("/chat/completions", { method: "POST", body: JSON.stringify(tiny), key: "sk-or-v1-0000000000000000000000000000000000000000000000000000000000000000" }));14await rec("invalid_key_models", raw("/models", { key: "sk-or-v1-bad" }));15await rec("invalid_key_key_endpoint", raw("/key", { key: "sk-or-v1-bad" }));16await rec("no_auth_chat", raw("/chat/completions", { method: "POST", body: JSON.stringify(tiny), headers: { Authorization: "" } }));17await rec("unknown_model", raw("/chat/completions", { method: "POST", body: JSON.stringify({ ...tiny, model: "openai/gpt-99-turbo" }) }));18await rec("unknown_model_no_slash", raw("/chat/completions", { method: "POST", body: JSON.stringify({ ...tiny, model: "gpt-99" }) }));19await rec("unknown_variant", raw("/chat/completions", { method: "POST", body: JSON.stringify({ ...tiny, model: `${OPENAI}:nope` }) }));20await rec("malformed_messages", raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: OPENAI, messages: "nope" }) }));21await rec("malformed_json", raw("/chat/completions", { method: "POST", body: "{not json" }));22await rec("empty_messages", raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: OPENAI, messages: [] }) }));23await rec("bad_temperature", raw("/chat/completions", { method: "POST", body: JSON.stringify({ ...tiny, temperature: 7 }) }));24await rec(25  "image_on_text_only_model",26  raw("/chat/completions", {27    method: "POST",28    body: JSON.stringify({29      model: DEEPSEEK,30      max_tokens: 20,31      messages: [{ role: "user", content: [{ type: "text", text: "what is this" }, { type: "image_url", image_url: { url: "data:image/png;base64,iVBORw0KGgo=" } }] }],32    }),33  }),34);35await rec(36  "bad_image_data",37  raw("/chat/completions", {38    method: "POST",39    body: JSON.stringify({40      model: OPENAI,41      max_tokens: 20,42      messages: [{ role: "user", content: [{ type: "text", text: "what is this" }, { type: "image_url", image_url: { url: "data:image/png;base64,AAAA" } }] }],43    }),44  }),45);46await rec("stream_unknown_model", rawSSE("/chat/completions", { ...tiny, model: "openai/gpt-99-turbo", stream: true }));47await rec("stream_invalid_key", rawSSE("/chat/completions", { ...tiny, stream: true }, "sk-or-v1-bad"));48await rec("context_overflow", raw("/chat/completions", { method: "POST", body: JSON.stringify({ ...tiny, max_tokens: 999999999 }) }));49// max_tokens above the model's max_completion_tokens (128000 for gpt-5.4-nano)50await rec("max_tokens_above_limit", raw("/chat/completions", { method: "POST", body: JSON.stringify({ ...tiny, max_tokens: 300000 }) }));51// finish_reason on truncation52await rec("truncation", raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: DEEPSEEK, messages: [{ role: "user", content: "Write 200 words about rivers." }], max_tokens: 10, reasoning: { effort: "none" } }) }));53// generation endpoint with the id from the previous call54const genId = results.truncation?.body?.id;55if (genId) {56  await new Promise((r) => setTimeout(r, 1500));57  await rec("generation_lookup", raw(`/generation?id=${genId}`));58}59save("06-errors.json", results);60