@axflow/models
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -24,2 +24,14 @@ declare class HttpError extends Error { | ||
/** | ||
* Converts an AsyncIterable<T> to a ReadableStream<T>. | ||
* | ||
* ReadableStreams implement this natively as `ReadableStream.from` but this is | ||
* hardly available in any environments as of the time this was written. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/from_static | ||
* | ||
* @param iterable Any async iterable object. | ||
* @returns A ReadableStream over the iterable contents. | ||
*/ | ||
declare function IterableToStream<T>(iterable: AsyncIterable<T>): ReadableStream<T>; | ||
/** | ||
* Convert a ReadableStream<T> to an AsyncIterable<T>. | ||
@@ -148,2 +160,2 @@ * | ||
export { HttpError, JSONValueType, MessageType, NdJsonStream, NdJsonValueType, POST, StreamToIterable, StreamingJsonResponse, isHttpError }; | ||
export { HttpError, IterableToStream, JSONValueType, MessageType, NdJsonStream, NdJsonValueType, POST, StreamToIterable, StreamingJsonResponse, isHttpError }; |
@@ -24,2 +24,3 @@ "use strict"; | ||
HttpError: () => HttpError, | ||
IterableToStream: () => IterableToStream, | ||
NdJsonStream: () => NdJsonStream, | ||
@@ -63,2 +64,18 @@ POST: () => POST, | ||
// src/shared/stream.ts | ||
function IterableToStream(iterable) { | ||
if (typeof ReadableStream.from === "function") { | ||
return ReadableStream.from(iterable); | ||
} | ||
const iterator = iterable[Symbol.asyncIterator](); | ||
return new ReadableStream({ | ||
async pull(controller) { | ||
const { done, value } = await iterator.next(); | ||
if (done) { | ||
controller.close(); | ||
} else { | ||
controller.enqueue(value); | ||
} | ||
} | ||
}); | ||
} | ||
function StreamToIterable(stream) { | ||
@@ -239,2 +256,3 @@ return stream[Symbol.asyncIterator] ? stream[Symbol.asyncIterator]() : createIterable(stream); | ||
HttpError, | ||
IterableToStream, | ||
NdJsonStream, | ||
@@ -241,0 +259,0 @@ POST, |
{ | ||
"name": "@axflow/models", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Zero-dependency, modular SDK for building robust natural language applications", | ||
@@ -46,5 +46,9 @@ "author": "Axilla (https://axilla.io)", | ||
"lint": "prettier --check 'src/**/*.ts' 'test/**/*.ts'", | ||
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'", | ||
"test": "jest --testMatch \"./**/test/**/*.test.ts\"", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"devDependencies": { | ||
@@ -147,3 +151,3 @@ "@types/jest": "^29.5.3", | ||
}, | ||
"gitHead": "00b92806e94b8baf3206897a6f9ec5eb3e653d32" | ||
"gitHead": "ed0841b5dd94e4f89b38505a7daacbf4d2c00899" | ||
} |
@@ -11,6 +11,6 @@ # @axflow/models | ||
* Zero-dependency, modular package to consume all the most popular LLMs, embedding models, and more | ||
* Comes with a set of React hooks for easily creating robust completion and chat components | ||
* First-class streaming support for both low-level byte streams and higher-level JavaScript object streams | ||
* First-class support for streaming arbitrary data in addition to the LLM response | ||
* Comes with a set of utilities and React hooks for easily creating robust client applications | ||
* Built exclusively on modern web standards such as `fetch` and the stream APIs | ||
* First-class streaming support with both low-level byte streams or higher-level JavaScript objects | ||
* Supports Node 18+, Next.js serverless or edge runtime, browsers, ESM, CJS, and more | ||
@@ -271,4 +271,11 @@ * Supports a custom `fetch` implementation for request middleware (e.g., custom headers, logging) | ||
```ts | ||
import {StreamToIterable, NdJsonStream, StreamingJsonResponse, HttpError, isHttpError} from '@axflow/models/shared'; | ||
import { | ||
IterableToStream, | ||
StreamToIterable, | ||
NdJsonStream, | ||
StreamingJsonResponse, | ||
HttpError, | ||
isHttpError | ||
} from '@axflow/models/shared'; | ||
import type {NdJsonValueType, JSONValueType, MessageType} from '@axflow/models/shared'; | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138240
2636
280