Skip to Content

asResponse

A wrapper of asStream to automatically generate a Web API compatible Response object. See asStream for reference.

Parameters

  • processor: ({ pushText }: ProcessorCallbacks) => void - The processor function that you will use to send data back to the client.

Returns

  • Response - A Web API compatible response object.

Example

import { LlamaWorkspace } from "llamaworkspace"; // app is an instance of express, koa, hono or any other web framework app.post("/", async (req) => { // ...instantiation code... return await llamaWorkspace.asResponse(async ({ pushText }) => { // Your internal logic that eventually generates streaming data. const myInternalStream = await myAIAgentProcess(); for await (const chunk of myInternalStream) { // Every chunk of text generated by your code is sent back to Llama Workspace pushText(chunk); } }); });
Last updated on