SuperAPI AI Directory

litechain

Lightweight alternative to LangChain for composing LLMs

Open website

About this tool

LiteChain has been renamed to LangStream, see issue #4 for details. LangStream is a lightweight alternative for building LLM applications. Unlike LangChain, it does not provide a large number of features and classes; instead, it focuses on a small core that is easy to learn, adapt, well documented, fully typed, and truly composable, using Stream rather than Chain as the building block.

Purpose

LangStream is used to build LLM applications by composing Streams to connect different parts, such as LLMs, output parsers, and more. It is designed to simplify pipelines and connections in LLM applications, letting developers focus on core parts such as prompt engineering.

Main capabilities

  • Stream building block: An LLM is a Stream, an output parser is a Stream, and a group of Streams can be composed into another Stream.
  • Composition functions: Provides and_then、map、collect、join、gather and other functions for composing Streams.
  • Type signatures: Streams accept type signatures, such as EmojiStream has the type [str, OpenAIChatDelta], representing input and output types. Type signatures help prevent errors and aid debugging.
  • Async streams: All Streams are async streams using Python's AsyncGenerator class.
  • Debugging friendly: In the final stream, everything that passed through the entire stream can always be accessed, providing the debug function and the output.final attribute.
  • Prompt externalization: Prompts are not hidden inside agents; developers are encouraged to build their own agents to customize prompts.
  • Bring your own integrations: Provides integrations such as OpenAI and GPT4All, but keeps them thin and as close to the original API as possible.

Usage

Build applications by composing Streams. For example, create a GPT4 Stream, append ". Reply in emojis" to the user message to build the prompt, use the OpenAI chat structure and zero temperature. Then iterate over each token output using an async loop. Use functions such as and_then to connect two Streams.

Applicable scenarios

Suitable for developers who need to build LLM applications and want a lightweight, composable, type-safe framework. Especially suitable for scenarios where developers want to customize prompts and agents without having details hidden by the framework.

Limitations

  • The project is very new and in a rapidly developing field; documentation and guide content need contributions.
  • It does not provide a large number of features and classes, so it may not be suitable for users who need rich built-in functionality.
  • There are few integrations; currently OpenAI and GPT4All and others are provided, but users are encouraged to add their own integrations.
  • Requires knowledge of Python async programming.

For more information, please refer to the documentation: Getting started, Detailed guides, How-to examples. Join the Discord community for support.