Crates.io | jawohl |
lib.rs | jawohl |
version | 0.1.0 |
source | src |
created_at | 2023-05-05 14:45:19.875928 |
updated_at | 2023-05-05 14:52:42.248165 |
description | Complete JSON documents from a stream of JSON tokens |
homepage | https://github.com/genauai/jawohl |
repository | https://github.com/genauai/jawohl |
max_upload_size | |
id | 857794 |
size | 62,345 |
jawohl
is a Rust library that helps you deal with JSON produced by Large Language Models (LLM's).
jawohl
can complete an partial JSON string by automatically adding the missing closing characters (quotes, braces, and brackets). This is particularly useful when you're dealing with streaming JSON strings from LLM's and want to display information without waiting for the inference process to finish.
Add the following line to your Cargo.toml file under the [dependencies] section:
jawohl = "0.1.0"
Here's a basic example showing how to use the JSON Completer library:
use jawohl::complete_json;
fn main() {
let input = r#"{"key": "value", "arr": [1, 2, {"nested_key": "nested_value""#;
assert!(complete_json(input), Ok(r#"{"key": "value", "arr": [1, 2, {"nested_key": "nested_value"}]}"#));
}
For more examples and advanced usage, refer to the examples directory. In particular, the OpenAI Streaming Parse example shows how to use jawohl to parse a stream of JSON data from OpenAI's API (using 64bit's async-openai library).
To run the test suite, run the following command from the root of the repository:
cargo test
This will execute a series of tests covering various scenarios, including nested objects and arrays, escaped quotes, and malformed JSON strings.
We welcome contributions! If you'd like to contribute, please follow these steps:
Please ensure that your code follows Rust's best practices and includes tests for any new functionality or bugfixes.
jawohl
was inspired by the untruncate-json library. We wanted to create a simpler version of untruncate-json
that was specifically designed for JSON produced by LLM's. jawohl
will not fix all partial json strings like how untruncate-json
will, but it will fix the most common cases. jawohl
is meant to be useful for displaying partial JSON strings from LLM's in a web browser, terminal, or other UI, where you want to display the JSON as it's being generated, without waiting for the inference process to finish and it's not that important that you have to be able to parse the JSON for each token, just for some of them. Additionally, we wanted to write it in Rust so that it could be used in other languages like Python and Javascript.
This project is licensed under the MIT License.