-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_logger.py
More file actions
48 lines (43 loc) · 1.33 KB
/
Copy pathbenchmark_logger.py
File metadata and controls
48 lines (43 loc) · 1.33 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
import csv
import os
from datetime import datetime
BENCHMARK_FILE = "benchmarks.csv"
HEADERS = [
"timestamp",
"query",
"intent",
"category",
"tool_generation_time_sec",
"parameter_extraction_success",
"tool_execution_success",
"end_to_end_latency_sec",
"error_message"
]
def log_benchmark(
query: str,
intent: str,
category: str = "N/A",
tool_generation_time: float = None,
parameter_extraction_success: str = "N/A",
tool_execution_success: str = "N/A",
end_to_end_latency: float = 0.0,
error_message: str = ""
):
"""Logs dynamic chatbot execution metrics to a CSV file."""
file_exists = os.path.exists(BENCHMARK_FILE)
# Using 'utf-8' encoding and thread-safe write model
with open(BENCHMARK_FILE, mode="a", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
if not file_exists:
writer.writerow(HEADERS)
writer.writerow([
datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
query,
intent,
category,
f"{tool_generation_time:.4f}" if tool_generation_time is not None else "N/A",
parameter_extraction_success,
tool_execution_success,
f"{end_to_end_latency:.4f}",
str(error_message) if error_message else ""
])