@axflow/models
Advanced tools
Comparing version 0.0.1-alpha.8 to 0.0.1-alpha.9
@@ -18,3 +18,3 @@ declare class HttpError extends Error { | ||
type: 'chunk' | 'data'; | ||
value: Record<string, JSONValueType>; | ||
value: JSONValueType; | ||
}; | ||
@@ -25,3 +25,4 @@ declare class NdJsonStream { | ||
}>; | ||
static encode<T extends Record<string, JSONValueType>>(stream: ReadableStream<T>, options?: { | ||
static encode<T = any>(stream: ReadableStream<T>, options?: { | ||
map?: (value: T) => JSONValueType; | ||
data?: Record<string, JSONValueType>[]; | ||
@@ -28,0 +29,0 @@ }): ReadableStream<Uint8Array>; |
@@ -78,2 +78,5 @@ "use strict"; | ||
} | ||
function identity(value) { | ||
return value; | ||
} | ||
var NdJsonStream = class { | ||
@@ -117,2 +120,3 @@ static headers = Object.freeze({ "content-type": "application/x-ndjson; charset=utf-8" }); | ||
* @param options | ||
* @param options.map A function to map stream chunks to desired, json-serializable outputs | ||
* @param options.data Additional data to prepend to the output stream | ||
@@ -122,2 +126,5 @@ * @returns A readable stream of newline-delimited JSON | ||
static encode(stream, options) { | ||
options = options || {}; | ||
const map = options.map || identity; | ||
const data = options.data || []; | ||
const encoder = new TextEncoder(); | ||
@@ -131,3 +138,2 @@ function serialize(obj) { | ||
start(controller) { | ||
const data = options?.data || []; | ||
for (const value of data) { | ||
@@ -138,3 +144,3 @@ controller.enqueue(serialize({ type: "data", value })); | ||
transform(value, controller) { | ||
controller.enqueue(serialize({ type: "chunk", value })); | ||
controller.enqueue(serialize({ type: "chunk", value: map(value) })); | ||
} | ||
@@ -141,0 +147,0 @@ }); |
{ | ||
"name": "@axflow/models", | ||
"version": "0.0.1-alpha.8", | ||
"version": "0.0.1-alpha.9", | ||
"description": "Zero-dependency module to run, stream, and render results across the most popular LLMs and embedding models", | ||
@@ -123,3 +123,3 @@ "author": "Axilla (https://axilla.io)", | ||
}, | ||
"gitHead": "7f0fb32893d6e83b5aca05f7daf5e0b4e4d0fec5" | ||
"gitHead": "cb659f43473fce49cd3283e3a95d3b947dd683a4" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
76801
1686