@llumiverse/core
Version:
Provide an universal API to LLMs. Support for existing LLMs can be added by writing a driver.
25 lines • 878 B
JavaScript
export async function readStreamAsBase64(stream) {
const uint8Array = await readStreamAsUint8Array(stream);
return Buffer.from(uint8Array).toString('base64');
}
export async function readStreamAsString(stream) {
const uint8Array = await readStreamAsUint8Array(stream);
return Buffer.from(uint8Array).toString();
}
export async function readStreamAsUint8Array(stream) {
const chunks = [];
let totalLength = 0;
for await (const chunk of stream) {
const uint8Chunk = chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk);
chunks.push(uint8Chunk);
totalLength += uint8Chunk.length;
}
const combined = new Uint8Array(totalLength);
let offset = 0;
for (const chunk of chunks) {
combined.set(chunk, offset);
offset += chunk.length;
}
return combined;
}
//# sourceMappingURL=stream.js.map