UNPKG

@llumiverse/core

Version:

Provide an universal API to LLMs. Support for existing LLMs can be added by writing a driver.

30 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readStreamAsBase64 = readStreamAsBase64; exports.readStreamAsString = readStreamAsString; exports.readStreamAsUint8Array = readStreamAsUint8Array; async function readStreamAsBase64(stream) { const uint8Array = await readStreamAsUint8Array(stream); return Buffer.from(uint8Array).toString('base64'); } async function readStreamAsString(stream) { const uint8Array = await readStreamAsUint8Array(stream); return Buffer.from(uint8Array).toString(); } 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