shiki-stream  by antfu

Streaming code highlighting for LLM output

created 5 months ago
538 stars

Top 59.8% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This library provides a streaming syntax highlighter for Shiki, designed to efficiently highlight text streams, particularly useful for real-time outputs from Large Language Models (LLMs). It enables developers to integrate syntax highlighting into dynamic content without blocking the main thread.

How It Works

The core of the library is the CodeToTokenTransformStream, a Web Stream API transform stream. It takes raw text input and pipes it through Shiki's highlighter, converting code into an array of ThemedToken objects. This approach allows for incremental processing of text data as it arrives, making it ideal for asynchronous operations. The allowRecalls option enables more granular token output by handling context-dependent highlighting changes via special "recall" tokens.

Quick Start & Requirements

  • Install via npm: npm install shiki-stream
  • Requires Node.js or a modern browser environment supporting Web Streams.
  • Initialize Shiki highlighter with desired languages and themes.
  • Pipe your text stream through CodeToTokenTransformStream.

Highlighted Details

  • Streaming tokenization for efficient LLM output highlighting.
  • Supports allowRecalls for fine-grained, context-aware highlighting.
  • Provides renderers for Vue and React for easy integration.

Maintenance & Community

  • Developed by Anthony Fu.
  • MIT License.

Licensing & Compatibility

  • MIT License.
  • Compatible with commercial and closed-source applications.

Limitations & Caveats

The allowRecalls feature requires custom handling by the stream consumer to correctly manage context-dependent highlighting updates.

Health Check
Last commit

4 months ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
24 stars in the last 90 days

Explore Similar Projects

Starred by Simon Willison Simon Willison(Author of Django), Jared Palmer Jared Palmer(Ex-VP of AI at Vercel; Founder of Turborepo; Author of Formik, TSDX), and
1 more.

GPT-3-Encoder by latitudegames

0%
719
JS library for GPT-2/GPT-3 text tokenization
created 4 years ago
updated 2 years ago
Feedback? Help us improve.