/*--- title: Stream a reply group: Services summary: llm.streamRequest delivers the reply in chunks; set their size in the LLM window. setup: {"mocks":{"llm":{"mode":"fixed","reply":"Streaming sends the answer piece by piece, so a WebApp can show it while it is written.","reasoning":"The user wants a demo of streaming.","chunkSize":10,"chunkDelayMs":60}}} ---*/ requirelib("llm"); var pieces = 0; var thinking = ""; var reply = llm.streamRequest( [{ role: "user", content: "Explain streaming in one sentence." }], {}, function (delta) { if (delta.reasoning) { thinking += delta.reasoning; } if (delta.content) { pieces++; console.log("chunk " + pieces + ": " + delta.content); } } ); sendJSONResp({ chunks: pieces, reasoning: thinking, result: reply });