hn.today

Nozzle: A streaming library that emits when possible and buffers where necessary

github.com5 points0 comments
Screenshot of Nozzle: A streaming library that emits when possible and buffers where necessary

Nozzle is a small TypeScript library for processing text as it arrives from language models or other streaming sources. It accepts synchronous or asynchronous iterables, including streams from common AI providers, and chains transformations without waiting for the full input. Its central design is to emit content as soon as it is safe while temporarily buffering only material whose meaning could change when more text arrives. For example, it can recognize a regular-expression match split across chunks, hold that possible match until confirmed or ruled out, and pass unrelated text downstream immediately. A parsing pipeline can therefore turn matched text into structured values while preserving the surrounding prose.

The library offers tools for regex scanning, matching, parsing and replacement, as well as splitting, filtering, mapping, buffering, timing, accumulation and stream conversion. Examples show extracting a code block for live preview and re-chunking bursty output into steadier word-sized pieces. Its behavior has explicit limits: lookarounds, anchors, word boundaries and other patterns dependent on unseen or arbitrary boundaries are unsupported, while open-ended quantifiers or ambiguous alternatives can delay output. Pipelines are lazy, generator sources can be consumed only once, and breaking iteration closes upstream iterators; errors surface at the awaiting call, though cancellation of provider-side I/O is not guaranteed. Nozzle is useful when applications need responsive, incremental handling of generated text without sacrificing correctness at chunk boundaries.

Read on github.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Aristotle Expands into Rust

Aristotle Expands into Rust

Aristotle has expanded its formal verification platform to Rust, allowing developers to prove code meets specifications and contains no undefined behavior, including in unsafe blocks. It can also verify that Rust rewrites behave like their original C code, targeting critical software such as smart contracts and infrastructure. (harmonic.fun)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.