Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03k
1import {createParser} from './parse.ts'2import type {EventSourceMessage, EventSourceParser} from './types.ts'3 4/**5 * Options for the EventSourceParserStream.6 *7 * @public8 */9export interface StreamOptions {10 /**11 * Behavior when a parsing error occurs.12 *13 * - A custom function can be provided to handle the error.14 * - `'terminate'` will error the stream and stop parsing.15 * - Any other value will ignore the error and continue parsing.16 *17 * @defaultValue `undefined`18 */19 onError?: ('terminate' | ((error: Error) => void)) | undefined20 21 /**22 * Callback for when a reconnection interval is sent from the server.23 *24 * @param retry - The number of milliseconds to wait before reconnecting.25 */26 onRetry?: ((retry: number) => void) | undefined27 28 /**29 * Callback for when a comment is encountered in the stream.30 *31 * @param comment - The comment encountered in the stream.32 */33 onComment?: ((comment: string) => void) | undefined34 35 /**36 * Maximum number of characters the parser is allowed to buffer across calls to `feed()`.37 * See {@link ParserConfig.maxBufferSize} for details.38 *39 * When the limit is exceeded, the stream is always errored (regardless of the `onError`40 * setting) since the underlying parser is unrecoverable without a `reset()`.41 *42 * @defaultValue `undefined` (unbounded)43 */44 maxBufferSize?: number | undefined45}46 47/**48 * A TransformStream that ingests a stream of strings and produces a stream of `EventSourceMessage`.49 *50 * @example Basic usage51 * ```52 * const eventStream =53 * response.body54 * .pipeThrough(new TextDecoderStream())55 * .pipeThrough(new EventSourceParserStream())56 * ```57 *58 * @example Terminate stream on parsing errors59 * ```60 * const eventStream =61 * response.body62 * .pipeThrough(new TextDecoderStream())63 * .pipeThrough(new EventSourceParserStream({onError: 'terminate'}))64 * ```65 *66 * @public67 */68export class EventSourceParserStream extends TransformStream<string, EventSourceMessage> {69 constructor({onError, onRetry, onComment, maxBufferSize}: StreamOptions = {}) {70 let parser!: EventSourceParser71 72 super({73 start(controller) {74 parser = createParser({75 onEvent: (event) => {76 controller.enqueue(event)77 },78 onError(error) {79 if (typeof onError === 'function') {80 onError(error)81 }82 83 // `max-buffer-size-exceeded` is fatal — the parser is unusable until84 // `reset()`, which the stream wrapper has no way to call. Always85 // terminate the stream in that case so consumers see the meaningful86 // `ParseError` instead of an opaque "cannot feed terminated parser"87 // throw from the next chunk.88 if (onError === 'terminate' || error.type === 'max-buffer-size-exceeded') {89 controller.error(error)90 }91 92 // Ignore by default93 },94 onRetry,95 onComment,96 maxBufferSize,97 })98 },99 transform(chunk) {100 parser.feed(chunk)101 },102 })103 }104}105 106export {type ErrorType, ParseError} from './errors.ts'107export type {EventSourceMessage} from './types.ts'108 