File size: 1,024 Bytes
5e0532d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()