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.6 KB · 96 lines typescript
Raw Blame History
1// Probe (i): Responses API — non-stream, streaming event names, function call, structured output, reasoning summary, store:false.2import { raw, rawSSE, save, short } from "./lib.ts";34const results: Record<string, any> = {};5// 1. non-stream basic with reasoning summary + encrypted content6results.basic = await raw("/responses", {7  method: "POST",8  body: JSON.stringify({9    model: "grok-4.3",10    instructions: "Answer in one short sentence.",11    input: [{ role: "user", content: "What is the capital of Canada?" }],12    max_output_tokens: 300,13    store: false,14    reasoning: { effort: "low", summary: "auto" },15    include: ["reasoning.encrypted_content"],16  }),17});18console.log("basic", results.basic.status, short(results.basic.body, 1500));1920// 2. streaming -> event names21const s = await rawSSE("/responses", {22  model: "grok-4.3",23  input: "Say hello in French, 5 words max.",24  stream: true,25  store: false,26  max_output_tokens: 200,27});28results.stream = {29  status: s.status,30  error: (s as any).error,31  eventTypes: [...new Set(s.events.map((e) => e.data?.type ?? e.event))],32  sseEventNames: [...new Set(s.events.map((e) => e.event).filter(Boolean))],33  samples: s.events.slice(0, 6).map((e) => e.data),34  last: s.events.slice(-2).map((e) => e.data),35};36console.log("stream", s.status, results.stream.eventTypes);3738// 3. function call (flat tool) non-stream + streaming39const tools = [{ type: "function", name: "get_weather", description: "Get weather", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] } }];40const fc = await rawSSE("/responses", { model: "grok-4.3", input: [{ role: "user", content: "Weather in Montreal? Use the tool." }], tools, stream: true, store: false, max_output_tokens: 300 });41results.functionCallStream = {42  status: fc.status,43  error: (fc as any).error,44  eventTypes: [...new Set(fc.events.map((e) => e.data?.type))],45  fcEvents: fc.events.filter((e) => /function_call|output_item/.test(e.data?.type ?? "")).map((e) => e.data),46};47console.log("fc stream", fc.status, results.functionCallStream.eventTypes);48const completed = fc.events.find((e) => e.data?.type === "response.completed")?.data?.response;49const call = completed?.output?.find((o: any) => o.type === "function_call");50if (call) {51  results.functionCallRound2 = await raw("/responses", {52    method: "POST",53    body: JSON.stringify({54      model: "grok-4.3",55      input: [{ role: "user", content: "Weather in Montreal? Use the tool." }, ...completed.output, { type: "function_call_output", call_id: call.call_id, output: JSON.stringify({ temp_c: 21 }) }],56      tools,57      store: false,58      max_output_tokens: 200,59    }),60  });61  console.log("fc round2", results.functionCallRound2.status, short(results.functionCallRound2.body?.output?.at(-1), 300));62}6364// 4. structured output via text.format65results.structured = await raw("/responses", {66  method: "POST",67  body: JSON.stringify({68    model: "grok-4.3",69    input: "Give info about Paris.",70    text: { format: { type: "json_schema", name: "city", strict: true, schema: { type: "object", properties: { city: { type: "string" }, country: { type: "string" } }, required: ["city", "country"], additionalProperties: false } } },71    store: false,72    max_output_tokens: 200,73  }),74});75console.log("structured", results.structured.status, short(results.structured.body?.output?.at(-1)?.content, 300));7677// 5. image input via Responses78results.imageFormat = await raw("/responses", {79  method: "POST",80  body: JSON.stringify({81    model: "grok-4.3",82    input: [{ role: "user", content: [{ type: "input_text", text: "One word: what color?" }, { type: "input_image", image_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVR4nGP4z8DwHwj+MzD8Z2D4DwAdyQX7Q7dWpAAAAABJRU5ErkJggg==", detail: "high" }] }],83    store: false,84    max_output_tokens: 100,85  }),86});87console.log("image", results.imageFormat.status, short(results.imageFormat.body?.output?.at(-1)?.content ?? results.imageFormat.body, 300));8889// 6. rejected params on Responses: presence_penalty etc.90results.rejectedParams = await raw("/responses", { method: "POST", body: JSON.stringify({ model: "grok-4.3", input: "ok", presence_penalty: 0.5, store: false, max_output_tokens: 20 }) });91console.log("rejected", results.rejectedParams.status, short(results.rejectedParams.body, 300));92results.multiAgentChat = await raw("/chat/completions", { method: "POST", body: JSON.stringify({ model: "grok-4.20-multi-agent-0309", messages: [{ role: "user", content: "Reply: ok" }], max_completion_tokens: 20 }) });93console.log("multi-agent on chat/completions", results.multiAgentChat.status, short(results.multiAgentChat.body, 300));9495save("07-responses.json", results);96