RSS Amplifier

Miguel Piedrafita · Jan 17, 2024

Working with streaming JSON in Rust

0
Sign in to vote or save

This page did not load. You can still read it on the original site — the toolbar below keeps your place in the directory.

LLMs have gotten pretty good at generating structured data recently, but unlike with text you can't use the results in real-time, since the returned JSON isn't valid until the end of the response. To solve this, I built a fast JSON syntax validator of sorts, which keeps track of the current context (are we inside a string, object, key, etc.) and can revert back to the latest valid state or…

GitHub - m1guelpf/repair-json: Repair incomplete JSON (e.g. from streaming APIs or AI models) so it can be parsed as it's received.

LLMs have gotten pretty good at generating structured data recently, but unlike with text you can't use the results in real-time, since the returned JSON isn't valid until the end of the response.

To solve this, I built a fast JSON syntax validator of sorts, which keeps track of the current context (are we inside a string, object, key, etc.) and can revert back to the latest valid state or complete the JSON to make it parseable.

Read on miguel.build

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.