From a7db571513123c4787463f5d2536df4f3040e24c Mon Sep 17 00:00:00 2001 From: Daniel Samson Date: Mon, 16 Nov 2026 12:19:27 +0000 Subject: [PATCH] add script to convert training snippets into a jsonl file --- .gitignore | 2 ++ README.md | 53 ++++++++++++++++++++++++++++++++++++++++- scripts/dir-to-jsonl.py | 43 +++++++++++++++++++++++++++++++++ testing.jsonl | 1 - training.jsonl | 1 - validation.jsonl | 1 - 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100755 scripts/dir-to-jsonl.py delete mode 100644 testing.jsonl delete mode 100644 training.jsonl delete mode 100644 validation.jsonl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8942924 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv/ +*.jsonl diff --git a/README.md b/README.md index be5bfd9..9e9cd02 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,54 @@ # kuberdata -Large Language Model training dataset \ No newline at end of file +Large Language Model training dataset + +## Setup + +### Prerequisites + +- [uv](https://docs.astral.sh/uv/) — a fast Python package and project manager. Install it with: + + ```sh + curl -LsSf https://astral.sh/uv/install.sh | sh + ``` + + (or `brew install uv` on macOS) + +- A Python interpreter (e.g. 3.10+). If none is installed, `uv` can fetch one automatically: + + ```sh + uv python install 3.12 + ``` + +### Create a virtual environment + +From the repository root, create and activate a virtual environment with uv: + +```sh +# Create .venv (a Python interpreter is selected or fetched automatically) +uv venv + +# Activate it +source .venv/bin/activate +``` + +## Usage + +### dir-to-jsonl script + +`scripts/dir-to-jsonl.py` reads all `.json` files in a directory, minifies each one, and appends them as lines to an output JSONL file. It uses only the Python standard library, so no extra packages are required. + +```sh +python scripts/dir-to-jsonl.py +``` + +Example: + +```sh +python scripts/dir-to-jsonl.py data/kubernetes-documentation-website/training training.jsonl +``` + +Notes: + +- The output file is **appended to**, so delete it first if you want a fresh build. +- Files that fail to parse are skipped with a warning on stderr. diff --git a/scripts/dir-to-jsonl.py b/scripts/dir-to-jsonl.py new file mode 100755 index 0000000..4005ef5 --- /dev/null +++ b/scripts/dir-to-jsonl.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""Read all JSON files in a directory, minify each, and append to an output JSONL file.""" + +import argparse +import json +import sys +from pathlib import Path + + +def main() -> int: + parser = argparse.ArgumentParser( + description="Minify each JSON file in a directory and append to a JSONL file." + ) + parser.add_argument("directory", help="Directory containing .json files") + parser.add_argument("output", help="Output JSONL file to append to") + args = parser.parse_args() + + dir_path = Path(args.directory) + if not dir_path.is_dir(): + print(f"Error: '{args.directory}' is not a directory", file=sys.stderr) + return 1 + + json_files = sorted(dir_path.glob("*.json")) + if not json_files: + print(f"No .json files found in '{args.directory}'", file=sys.stderr) + return 1 + + written = 0 + with open(args.output, "a", encoding="utf-8") as out: + for f in json_files: + try: + data = json.loads(f.read_text(encoding="utf-8")) + out.write(json.dumps(data, separators=(",", ":"), ensure_ascii=False) + "\n") + written += 1 + except (json.JSONDecodeError, OSError) as e: + print(f"Warning: skipping {f}: {e}", file=sys.stderr) + + print(f"Wrote {written} record(s) to {args.output}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/testing.jsonl b/testing.jsonl deleted file mode 100644 index f60ff5c..0000000 --- a/testing.jsonl +++ /dev/null @@ -1 +0,0 @@ -{"id":"testing-list-pods-all-namespaces-001","messages":[]} \ No newline at end of file diff --git a/training.jsonl b/training.jsonl deleted file mode 100644 index 409b7df..0000000 --- a/training.jsonl +++ /dev/null @@ -1 +0,0 @@ -{"id":"training-list-pods-all-namespaces-001","messages":[]} \ No newline at end of file diff --git a/validation.jsonl b/validation.jsonl deleted file mode 100644 index ff45f10..0000000 --- a/validation.jsonl +++ /dev/null @@ -1 +0,0 @@ -{"id":"validation-list-pods-all-namespaces-001","messages":[]} \ No newline at end of file