UNPKG

ai

Version:

AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.

21 lines (20 loc) • 461 B
export async function processTextStream({ stream, onTextPart, }: { stream: ReadableStream<Uint8Array>; onTextPart: (chunk: string) => Promise<void> | void; }): Promise<void> { const reader = stream .pipeThrough( new TextDecoderStream() as ReadableWritablePair<string, Uint8Array>, ) .getReader(); while (true) { const { done, value } = await reader.read(); if (done) { break; } await onTextPart(value); } }