Spaces:
Sleeping
Sleeping
Download src/qa_langgraph/run_logger.py from helmfridsson/qa-agent-langgraph: direct link, hf CLI and curl.
- Browser
- Download file 894 Bytes
-
https://huggingface.co/spaces/helmfridsson/qa-agent-langgraph/resolve/main/src/qa_langgraph/run_logger.py
- Command line
-
hf download hf://spaces/helmfridsson/qa-agent-langgraph/src/qa_langgraph/run_logger.py
-
curl -L -o run_logger.py https://huggingface.co/spaces/helmfridsson/qa-agent-langgraph/resolve/main/src/qa_langgraph/run_logger.py
894 Bytes
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Any | |
| RUNS_DIR = Path(__file__).resolve().parents[2] / "runs" | |
| def run_dir(run_id: str) -> Path: | |
| path = RUNS_DIR / run_id | |
| path.mkdir(parents=True, exist_ok=True) | |
| return path | |
| def append_stage_trace(run_id: str, trace: dict[str, Any]) -> None: | |
| path = run_dir(run_id) / "stage_traces.jsonl" | |
| with path.open("a", encoding="utf-8") as handle: | |
| handle.write(json.dumps(trace, ensure_ascii=False) + "\n") | |
| def write_run_export(run_id: str, export: dict[str, Any]) -> None: | |
| path = run_dir(run_id) / "run_export.json" | |
| path.write_text(json.dumps(export, indent=2, ensure_ascii=False), encoding="utf-8") | |
| def read_stage_traces_jsonl(run_id: str) -> str: | |
| path = run_dir(run_id) / "stage_traces.jsonl" | |
| return path.read_text(encoding="utf-8") if path.exists() else "" | |