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%
2.6 KB · 37 lines typescript
Raw Blame History
1import { rawPost, save, short } from "./lib.ts";23const model = process.argv[2] ?? "kimi-k3";4const tools = [{ type: "builtin_function", function: { name: "$web_search" } }];5const messages: any[] = [{ role: "user", content: "What was the closing value of the S&P 500 yesterday? Search the web and cite the source URL." }];6const extra = model === "kimi-k3" ? { reasoning_effort: "low" } : {};78// canonical: non-streamed step 1, append message verbatim9const r1 = await rawPost("/chat/completions", { model, messages, tools, max_tokens: 6000, ...extra });10const m = (r1.body as any)?.choices?.[0]?.message;11console.log(`[${model}] step1 non-stream ${r1.status} finish=${(r1.body as any)?.choices?.[0]?.finish_reason} keys=${Object.keys(m ?? {})} usage=${JSON.stringify((r1.body as any)?.usage)}`);12console.log("  message:", short(m, 900));13const out: any = { step1: r1 };14if (m?.tool_calls?.length) {15  const toolMsgs = m.tool_calls.map((tc: any) => ({ role: "tool", tool_call_id: tc.id, name: tc.function.name, content: tc.function.arguments }));16  const variants: Array<[string, any]> = [17    ["verbatim message", m],18    ["no reasoning_content", { role: "assistant", content: m.content, tool_calls: m.tool_calls }],19    ["reasoning_content empty string", { role: "assistant", content: m.content, reasoning_content: "", tool_calls: m.tool_calls }],20    ["tool_calls type=function instead of builtin_function", { ...m, tool_calls: m.tool_calls.map((tc: any) => ({ ...tc, type: "function" })) }],21  ];22  for (const [label, asst] of variants) {23    const r2 = await rawPost("/chat/completions", { model, messages: [...messages, asst, ...toolMsgs], tools, max_tokens: 6000, ...extra });24    const mm = (r2.body as any)?.choices?.[0]?.message;25    console.log(`  step2 [${label}] ${r2.status} finish=${(r2.body as any)?.choices?.[0]?.finish_reason} usage=${JSON.stringify((r2.body as any)?.usage)}`);26    console.log("    ->", short(mm?.content ?? mm?.tool_calls ?? r2.body, 700));27    if (mm) console.log("    message keys:", Object.keys(mm), "choice keys:", Object.keys((r2.body as any).choices[0]));28    out[`step2:${label}`] = r2;29    if (r2.status === 200 && !out.firstOk) out.firstOk = label;30  }31  // tool message without name field32  const noName = await rawPost("/chat/completions", { model, messages: [...messages, m, ...m.tool_calls.map((tc: any) => ({ role: "tool", tool_call_id: tc.id, content: tc.function.arguments }))], tools, max_tokens: 6000, ...extra });33  console.log(`  step2 [tool msg without name] ${noName.status}`, short((noName.body as any)?.choices?.[0]?.message?.content ?? noName.body, 200));34  out["step2:noName"] = noName;35}36save(`06b-websearch-variants-${model}`, out);37