From 24f376b63a797e9c9d9b47f210c98782a0bcb86d Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Fri, 20 Dec 2024 04:55:48 +0000 Subject: [PATCH] Add binary which converts JSON schemas to regex --- Cargo.toml | 5 +++++ src/bin/convert-json-schema.rs | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/bin/convert-json-schema.rs diff --git a/Cargo.toml b/Cargo.toml index 6c7f49d..9f3f31a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,3 +40,8 @@ build-python-extension-release = "python setup.py build_rust --inplace --release [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] } + +[[bin]] +name = "convert-json-schema" +test = false +bench = false diff --git a/src/bin/convert-json-schema.rs b/src/bin/convert-json-schema.rs new file mode 100644 index 0000000..459144f --- /dev/null +++ b/src/bin/convert-json-schema.rs @@ -0,0 +1,8 @@ +use outlines_core::json_schema::build_regex_from_schema; + +fn main() { + let schema = std::io::read_to_string(std::io::stdin()).unwrap(); + let regex = build_regex_from_schema(&schema, None).unwrap(); + println!("Regex: {}", regex); + println!("Regex len: {}", regex.len()); +}