#!/usr/bin/env python3 """Run JSONLite offline with the bundled native MLX implementation. Defaults to model.safetensors beside this script. The verified source bundle includes the exact model architecture, tokenizer, native JSON prompt/decoder and examples. """ from pathlib import Path import hashlib import runpy import sys import tempfile import zipfile ROOT = Path(__file__).resolve().parent BUNDLE_SHA256 = "8f5a075f63e1ff8857af3ddd916afc57742e614b1da5cbbe15452e9c84e94d2a" def main(): archive = ROOT / "native_bundle.zip" if not archive.is_file(): raise SystemExit("Missing native_bundle.zip; download the complete repository.") if hashlib.sha256(archive.read_bytes()).hexdigest() != BUNDLE_SHA256: raise SystemExit("Native source bundle failed its integrity check.") if not any(arg == "--weights" or arg.startswith("--weights=") for arg in sys.argv[1:]): sys.argv.extend(["--weights", str(ROOT / "model.safetensors")]) with tempfile.TemporaryDirectory(prefix="jsonlite-runtime-") as directory: runtime = Path(directory) with zipfile.ZipFile(archive) as bundle: for member in bundle.infolist(): path = Path(member.filename) if path.is_absolute() or ".." in path.parts or (member.external_attr >> 16) & 0o170000 == 0o120000: raise SystemExit("Unsafe source-bundle entry.") bundle.extractall(runtime) runpy.run_path(str(runtime / "inference.py"), run_name="__main__") if __name__ == "__main__": main()