@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
21 lines (16 loc) • 467 B
text/typescript
export const createReadableStream = <T>(chunks: T[]) =>
new ReadableStream({
start(controller) {
chunks.forEach((chunk) => controller.enqueue(chunk));
controller.close();
},
});
export const readStreamChunk = async (stream: ReadableStream) => {
const decoder = new TextDecoder();
const chunks = [];
// @ts-ignore
for await (const chunk of stream) {
chunks.push(decoder.decode(chunk, { stream: true }));
}
return chunks;
};