Spaces:
Sleeping
Sleeping
| import json | |
| import os | |
| from datetime import datetime | |
| from typing import Dict, Any | |
| class TraceService: | |
| TRACE_DIR = "important/reasoning_traces" | |
| def __init__(self): | |
| if not os.path.exists(self.TRACE_DIR): | |
| os.makedirs(self.TRACE_DIR, exist_ok=True) | |
| def save_trace(self, trace_data: Dict[str, Any]): | |
| """ | |
| Appends a reasoning trace to a daily .jsonl file. | |
| """ | |
| today = datetime.now().strftime("%Y-%m-%d") | |
| file_path = os.path.join(self.TRACE_DIR, f"ora_traces_{today}.jsonl") | |
| # Add timestamp if missing | |
| if "timestamp" not in trace_data: | |
| trace_data["timestamp"] = datetime.now().isoformat() | |
| try: | |
| with open(file_path, "a", encoding="utf-8") as f: | |
| f.write(json.dumps(trace_data) + "\n") | |
| # print(f"TraceService: Trace saved to {file_path}") | |
| except Exception as e: | |
| print(f"TraceService Error: Failed to save trace: {str(e)}") | |
| trace_service = TraceService() | |