🤖 AI Summary
LangDiff is a new Python library that makes streaming structured outputs from LLMs practical and safe for real-world frontends. Instead of waiting for a complete JSON blob, LangDiff provides intelligent partial parsing and emits granular, type-safe callbacks (on_append, on_update, on_complete) as structures build token-by-token. You define schemas with Pydantic-style models (ld.Object, ld.List, ld.String), can derive real Pydantic models for SDK interoperability (e.g., OpenAI), and parse LLM streaming deltas with ld.Parser to progressively update UI state. It also offers ld.track_change() to capture mutations and flush a buffer of JSON Patch diffs instead of retransmitting whole objects.
Technically, LangDiff solves streaming JSON’s two big problems: unparseable partial tokens and tight frontend/backend coupling. It tracks fine-grained mutations and emits RFC‑6902-style patches (plus an efficient append op for string building) so frontends receive minimal, incremental updates. This enables type safety during streaming, clean schema evolution (backend prompts can change without breaking UIs), and efficient synchronization for responsive apps. The project includes examples (multi-section article streaming with OpenAI) and is Apache‑2.0 licensed; installable via pip install langdiff.
Loading comments...
login to comment
loading comments...
no comments yet