-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
66 lines (55 loc) · 1.93 KB
/
logger.py
File metadata and controls
66 lines (55 loc) · 1.93 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
from dataclasses import dataclass, asdict
from datetime import datetime
from typing import Optional, Dict, Any
from pathlib import Path
@dataclass
class StepLog:
timestamp: str
step: int
state_before: Dict[str, Any]
model_output: str
parse_success: bool
parse_error: Optional[str]
decision: Optional[str]
stop_reason: Optional[str]
state_after: Dict[str, Any]
true_confidence: Optional[float] = None
measured_confidence: Optional[float] = None
uncertainty_detail: Optional[Dict[str, Any]] = None
class ReasoningLogger:
def __init__(self, log_path: str = "reasoning.jsonl"):
self.log_path = Path(log_path)
self.step_logs: list = []
self.log_path.write_text("")
def log_step(self, step_log: StepLog) -> None:
self.step_logs.append(step_log)
with open(self.log_path, "a") as f:
log_dict = asdict(step_log)
f.write(json.dumps(log_dict) + "\n")
def log_summary(
self,
final_state: Dict[str, Any],
total_steps: int,
stop_reason: str,
elapsed_time: float
) -> None:
final_solution_entry = {
"type": "final_solution",
"solution": final_state.get("current_solution", ""),
"confidence": final_state.get("confidence", 0.0)
}
summary = {
"type": "summary",
"timestamp": datetime.now().isoformat(),
"total_steps": total_steps,
"stop_reason": stop_reason,
"elapsed_time_seconds": round(elapsed_time, 2),
"open_questions": final_state.get("open_questions", ""),
"final_state": final_state
}
with open(self.log_path, "a") as f:
f.write(json.dumps(final_solution_entry) + "\n")
f.write(json.dumps(summary) + "\n")
def get_logs(self) -> list:
return self.step_logs