// Probe 07: web search via :online suffix and via plugins web (max_results 3), streaming annotations; openrouter/auto tiny call. import { raw, rawSSE, save, short } from "./lib.ts"; import { OPENAI, ANTHROPIC } from "./models.ts"; const results: any = {}; const q = "What is the current version number of Node.js LTS? One sentence with a source."; // (1) :online suffix, non-streaming { const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: `${OPENAI}:online`, messages: [{ role: "user", content: q }], max_tokens: 200, usage: { include: true }, reasoning: { effort: "low" } }), }); const b: any = r.body; const msg = b?.choices?.[0]?.message; 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 }; console.log(`[online] ${r.status} model=${b?.model} provider=${b?.provider} msgKeys=${Object.keys(msg ?? {})} annotations=${msg?.annotations?.length} usage=${JSON.stringify(b?.usage)}`); console.log(" content:", short(msg?.content, 300)); console.log(" annotation[0]:", short(msg?.annotations?.[0], 500)); if (b?.error) console.log(" ERR", JSON.stringify(b.error)); } // (2) plugins web with max_results 3, streaming, on Anthropic { const s = await rawSSE("/chat/completions", { model: ANTHROPIC, messages: [{ role: "user", content: q }], plugins: [{ id: "web", max_results: 3 }], max_tokens: 200, stream: true, usage: { include: true }, }); const annots: any[] = []; let text = ""; const deltaKeys = new Set(); for (const e of s.events) { if (e.data === "[DONE]") continue; const d = e.data?.choices?.[0]?.delta ?? {}; for (const k of Object.keys(d)) deltaKeys.add(k); if (d.content) text += d.content; if (d.annotations) annots.push(...d.annotations); } const usage = s.events.find((e) => e.data?.usage)?.data?.usage; 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 }; console.log(`\n[plugin stream ${ANTHROPIC}] ${s.status} events=${s.events.length} deltaKeys=${[...deltaKeys]} annotations=${annots.length} comments=${s.comments.length}`); console.log(" text:", short(text, 300)); console.log(" annotation[0]:", short(annots[0], 500)); console.log(" usage:", JSON.stringify(usage)); if ((s as any).error) console.log(" ERR", short((s as any).error)); } // (3) openrouter/auto tiny { const r = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "openrouter/auto", messages: [{ role: "user", content: "Say hi in 3 words." }], max_tokens: 20, usage: { include: true } }), }); const b: any = r.body; results.auto = { status: r.status, model: b?.model, provider: b?.provider, usage: b?.usage, content: b?.choices?.[0]?.message?.content, error: b?.error }; 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) : ""}`); } // (4) tilde latest alias { const r = await raw("/chat/completions", { method: "POST", 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" } }), }); const b: any = r.body; results.tilde = { status: r.status, model: b?.model, provider: b?.provider, usage: b?.usage, error: b?.error }; console.log(`[tilde] ${r.status} model=${b?.model} provider=${b?.provider} usage=${JSON.stringify(b?.usage)} ${b?.error ? JSON.stringify(b.error) : ""}`); } save("07-websearch.json", results);