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%
4.7 KB · 53 lines typescript
Raw Blame History
1// Misc: undocumented thinking.type=adaptive, stream without include_usage, non-thinking stream delta shape, logprobs shape, image silently dropped on pro.2import { raw, rawSSE, save, pngDataUrl } from "./lib.ts";34const out: Record<string, unknown> = {};5const m = "deepseek-v4-flash";6const hard = "A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost? Number only.";7for (const [name, body] of Object.entries({8  "adaptive_easy": { thinking: { type: "adaptive" }, messages: [{ role: "user", content: "Reply with the single word: pong" }] },9  "adaptive_hard": { thinking: { type: "adaptive" }, messages: [{ role: "user", content: hard }] },10  "adaptive+effort_low": { thinking: { type: "adaptive" }, reasoning_effort: "low", messages: [{ role: "user", content: hard }] },11  "enabled_easy": { thinking: { type: "enabled" }, messages: [{ role: "user", content: "Reply with the single word: pong" }] },12})) {13  const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: m, max_tokens: 1500, ...body }) });14  const b: any = r.body;15  out[name] = { status: r.status, finish: b.choices?.[0]?.finish_reason, content: b.choices?.[0]?.message?.content, reasoning_len: b.choices?.[0]?.message?.reasoning_content?.length ?? null, usage: b.usage, error: r.status !== 200 ? b : undefined };16  console.log(name, r.status, JSON.stringify(b.usage?.completion_tokens_details), "rl", b.choices?.[0]?.message?.reasoning_content?.length ?? null, "→", JSON.stringify(b.choices?.[0]?.message?.content ?? b).slice(0, 120));17}18// stream WITHOUT include_usage19{20  const s = await rawSSE("/chat/completions", { model: m, messages: [{ role: "user", content: "Say hi." }], max_tokens: 100, stream: true, thinking: { type: "disabled" } });21  const last = s.events.slice(-3);22  out.stream_no_include_usage = { status: s.status, last, deltaKeysFirst: Object.keys((s.events[0] as any)?.choices?.[0]?.delta ?? {}) };23  console.log("stream no include_usage: usage on finish chunk?", JSON.stringify((last[0] as any)?.usage ?? (last[1] as any)?.usage), "first delta", JSON.stringify((s.events[0] as any)?.choices?.[0]?.delta));24}25// stream thinking disabled + include_usage: do deltas still carry reasoning_content key?26{27  const s = await rawSSE("/chat/completions", { model: m, messages: [{ role: "user", content: "Say hi." }], max_tokens: 100, stream: true, stream_options: { include_usage: true }, reasoning_effort: "none" });28  out.stream_effort_none = { status: s.status, first2: s.events.slice(0, 2), last3: s.events.slice(-3) };29  console.log("stream effort=none first delta", JSON.stringify((s.events[0] as any)?.choices?.[0]?.delta), "last", JSON.stringify(s.events.slice(-2)).slice(0, 500));30}31// logprobs shape32{33  const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: m, messages: [{ role: "user", content: "Say hi." }], max_tokens: 5, thinking: { type: "disabled" }, logprobs: true, top_logprobs: 2 }) });34  out.logprobs = { status: r.status, logprobs: (r.body as any).choices?.[0]?.logprobs };35  console.log("logprobs", JSON.stringify((r.body as any).choices?.[0]?.logprobs).slice(0, 400));36}37// image on pro: is it dropped? ask a question only answerable from the image38{39  const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "deepseek-v4-pro", thinking: { type: "disabled" }, max_tokens: 60, messages: [{ role: "user", content: [{ type: "text", text: "Is there an image attached to this message? Answer yes or no and say what you received." }, { type: "image_url", image_url: { url: pngDataUrl(32, 32) } }] }] }) });40  out.pro_image_dropped = { status: r.status, content: (r.body as any).choices?.[0]?.message?.content, usage: (r.body as any).usage };41  console.log("pro image →", r.status, JSON.stringify(out.pro_image_dropped).slice(0, 400));42  const r2 = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "deepseek-v4-pro", thinking: { type: "disabled" }, max_tokens: 5, messages: [{ role: "user", content: [{ type: "text", text: "Is there an image attached to this message? Answer yes or no and say what you received." }] }] }) });43  out.pro_text_only_tokens = (r2.body as any).usage;44  console.log("pro same text w/o image prompt_tokens", (r2.body as any).usage?.prompt_tokens, "vs with image", (r.body as any).usage?.prompt_tokens);45}46// /v1 streaming + trailing slash variants47{48  const r = await raw("/v1/chat/completions/", { method: "POST", body: JSON.stringify({ model: m, messages: [{ role: "user", content: "hi" }], max_tokens: 2, thinking: { type: "disabled" } }) });49  out.trailing_slash = { status: r.status, body: r.status === 200 ? "ok" : r.body };50  console.log("trailing slash →", r.status);51}52save("10-misc.json", out);53