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.
17 lines (16 loc) • 394 B
text/typescript
export async function processTextStream({
stream,
onTextPart,
}: {
stream: ReadableStream<Uint8Array>;
onTextPart: (chunk: string) => Promise<void> | void;
}): Promise<void> {
const reader = stream.pipeThrough(new TextDecoderStream()).getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
await onTextPart(value);
}
}