Download evaluation/src/rag_preprocess/jsonl_io.py from EllaNAM/rag-assignment-processed-bm25: direct link, hf CLI and curl.
- Browser
- Download file 503 Bytes
-
https://huggingface.co/datasets/EllaNAM/rag-assignment-processed-bm25/resolve/main/evaluation/src/rag_preprocess/jsonl_io.py
- Command line
-
hf download hf://datasets/EllaNAM/rag-assignment-processed-bm25/evaluation/src/rag_preprocess/jsonl_io.py
-
curl -L -o jsonl_io.py https://huggingface.co/datasets/EllaNAM/rag-assignment-processed-bm25/resolve/main/evaluation/src/rag_preprocess/jsonl_io.py
503 Bytes
| import json | |
| from pathlib import Path | |
| from typing import Any, Iterable | |
| def _write_jsonl_atomic(rows: Iterable[dict[str, Any]], path: Path) -> int: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| temporary = path.with_suffix(path.suffix + ".tmp") | |
| count = 0 | |
| with temporary.open("w", encoding="utf-8") as stream: | |
| for row in rows: | |
| stream.write(json.dumps(row, ensure_ascii=False) + "\n") | |
| count += 1 | |
| temporary.replace(path) | |
| return count | |