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.9 KB · 74 lines typescript
Raw Blame History
1// Probe 07: web search via :online suffix and via plugins web (max_results 3), streaming annotations; openrouter/auto tiny call.2import { raw, rawSSE, save, short } from "./lib.ts";3import { OPENAI, ANTHROPIC } from "./models.ts";45const results: any = {};6const q = "What is the current version number of Node.js LTS? One sentence with a source.";78// (1) :online suffix, non-streaming9{10  const r = await raw("/chat/completions", {11    method: "POST",12    body: JSON.stringify({ model: `${OPENAI}:online`, messages: [{ role: "user", content: q }], max_tokens: 200, usage: { include: true }, reasoning: { effort: "low" } }),13  });14  const b: any = r.body;15  const msg = b?.choices?.[0]?.message;16  results.online_suffix = { status: r.status, model: b?.model, provider: b?.provider, keys: Object.keys(msg ?? {}), annotations: msg?.annotations, content: msg?.content, usage: b?.usage, error: b?.error };17  console.log(`[online] ${r.status} model=${b?.model} provider=${b?.provider} msgKeys=${Object.keys(msg ?? {})} annotations=${msg?.annotations?.length} usage=${JSON.stringify(b?.usage)}`);18  console.log("  content:", short(msg?.content, 300));19  console.log("  annotation[0]:", short(msg?.annotations?.[0], 500));20  if (b?.error) console.log("  ERR", JSON.stringify(b.error));21}2223// (2) plugins web with max_results 3, streaming, on Anthropic24{25  const s = await rawSSE("/chat/completions", {26    model: ANTHROPIC,27    messages: [{ role: "user", content: q }],28    plugins: [{ id: "web", max_results: 3 }],29    max_tokens: 200,30    stream: true,31    usage: { include: true },32  });33  const annots: any[] = [];34  let text = "";35  const deltaKeys = new Set<string>();36  for (const e of s.events) {37    if (e.data === "[DONE]") continue;38    const d = e.data?.choices?.[0]?.delta ?? {};39    for (const k of Object.keys(d)) deltaKeys.add(k);40    if (d.content) text += d.content;41    if (d.annotations) annots.push(...d.annotations);42  }43  const usage = s.events.find((e) => e.data?.usage)?.data?.usage;44  results.plugin_stream = { status: s.status, events: s.events.length, comments: s.comments, deltaKeys: [...deltaKeys], annotations: annots, text, usage, error: (s as any).error, firstAnnotationChunk: s.events.find((e) => e.data?.choices?.[0]?.delta?.annotations)?.data };45  console.log(`\n[plugin stream ${ANTHROPIC}] ${s.status} events=${s.events.length} deltaKeys=${[...deltaKeys]} annotations=${annots.length} comments=${s.comments.length}`);46  console.log("  text:", short(text, 300));47  console.log("  annotation[0]:", short(annots[0], 500));48  console.log("  usage:", JSON.stringify(usage));49  if ((s as any).error) console.log("  ERR", short((s as any).error));50}5152// (3) openrouter/auto tiny53{54  const r = await raw("/chat/completions", {55    method: "POST",56    body: JSON.stringify({ model: "openrouter/auto", messages: [{ role: "user", content: "Say hi in 3 words." }], max_tokens: 20, usage: { include: true } }),57  });58  const b: any = r.body;59  results.auto = { status: r.status, model: b?.model, provider: b?.provider, usage: b?.usage, content: b?.choices?.[0]?.message?.content, error: b?.error };60  console.log(`\n[auto] ${r.status} model=${b?.model} provider=${b?.provider} usage=${JSON.stringify(b?.usage)} ${short(b?.choices?.[0]?.message?.content, 80)} ${b?.error ? JSON.stringify(b.error) : ""}`);61}6263// (4) tilde latest alias64{65  const r = await raw("/chat/completions", {66    method: "POST",67    body: JSON.stringify({ model: "~openai/gpt-mini-latest", messages: [{ role: "user", content: "Say hi in 3 words." }], max_tokens: 20, usage: { include: true }, reasoning: { effort: "low" } }),68  });69  const b: any = r.body;70  results.tilde = { status: r.status, model: b?.model, provider: b?.provider, usage: b?.usage, error: b?.error };71  console.log(`[tilde] ${r.status} model=${b?.model} provider=${b?.provider} usage=${JSON.stringify(b?.usage)} ${b?.error ? JSON.stringify(b.error) : ""}`);72}73save("07-websearch.json", results);74