llm decided to add additional safety layer to rag evaluation file save
This commit is contained in:
@@ -549,6 +549,14 @@ def update_batch_stats(store: dict[str, Any], batch_meta: dict[str, Any]) -> Non
|
|||||||
store.setdefault("meta", {})["updated_at"] = now_iso()
|
store.setdefault("meta", {})["updated_at"] = now_iso()
|
||||||
|
|
||||||
|
|
||||||
|
def atomic_write_json(path: Path, payload: dict[str, Any]) -> None:
|
||||||
|
"""Atomically write JSON to avoid partial/corrupted files on interruption."""
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
tmp_path = path.with_suffix(path.suffix + ".tmp")
|
||||||
|
tmp_path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||||
|
tmp_path.replace(path)
|
||||||
|
|
||||||
|
|
||||||
def compute_batch_summary(results: list[DocumentEvaluation]) -> dict[str, Any]:
|
def compute_batch_summary(results: list[DocumentEvaluation]) -> dict[str, Any]:
|
||||||
wins = {"LangChain": 0, "LlamaIndex": 0, "Tie": 0}
|
wins = {"LangChain": 0, "LlamaIndex": 0, "Tie": 0}
|
||||||
scores_lc: list[float] = []
|
scores_lc: list[float] = []
|
||||||
@@ -660,9 +668,7 @@ def run_evaluation(doc_from: int, doc_to: int, mode: str) -> None:
|
|||||||
batch_results.append(doc_result)
|
batch_results.append(doc_result)
|
||||||
|
|
||||||
# Save incremental progress after each file/step
|
# Save incremental progress after each file/step
|
||||||
OUTPUT_JSON.write_text(
|
atomic_write_json(OUTPUT_JSON, store)
|
||||||
json.dumps(store, ensure_ascii=False, indent=2), encoding="utf-8"
|
|
||||||
)
|
|
||||||
print(" -> step saved")
|
print(" -> step saved")
|
||||||
|
|
||||||
summary = compute_batch_summary(batch_results)
|
summary = compute_batch_summary(batch_results)
|
||||||
@@ -674,9 +680,7 @@ def run_evaluation(doc_from: int, doc_to: int, mode: str) -> None:
|
|||||||
"mode": mode,
|
"mode": mode,
|
||||||
}
|
}
|
||||||
update_batch_stats(store, batch_meta)
|
update_batch_stats(store, batch_meta)
|
||||||
OUTPUT_JSON.write_text(
|
atomic_write_json(OUTPUT_JSON, store)
|
||||||
json.dumps(store, ensure_ascii=False, indent=2), encoding="utf-8"
|
|
||||||
)
|
|
||||||
|
|
||||||
print("\nBatch complete.")
|
print("\nBatch complete.")
|
||||||
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
||||||
|
|||||||
Reference in New Issue
Block a user