Spaces:
Sleeping
Sleeping
Update logger.py
Browse files
logger.py
CHANGED
@@ -16,39 +16,61 @@ def log_feedback(
|
|
16 |
):
|
17 |
"""
|
18 |
Logs Evo and GPT output along with user's preference for retraining.
|
|
|
19 |
"""
|
|
|
|
|
|
|
20 |
file_exists = os.path.isfile(LOG_FILE)
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
if not file_exists:
|
26 |
writer.writerow([
|
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 |
-
evo_reasoning,
|
52 |
-
user_preference or "",
|
53 |
-
evo_was_correct
|
54 |
-
])
|
|
|
16 |
):
|
17 |
"""
|
18 |
Logs Evo and GPT output along with user's preference for retraining.
|
19 |
+
Creates feedback_log.csv automatically if it doesn't exist.
|
20 |
"""
|
21 |
+
print("✅ log_feedback() triggered")
|
22 |
+
print("User voted:", user_preference)
|
23 |
+
|
24 |
file_exists = os.path.isfile(LOG_FILE)
|
25 |
|
26 |
+
try:
|
27 |
+
with open(LOG_FILE, mode='a', newline='', encoding='utf-8') as file:
|
28 |
+
writer = csv.writer(file)
|
29 |
+
|
30 |
+
if not file_exists:
|
31 |
+
writer.writerow([
|
32 |
+
"timestamp",
|
33 |
+
"question",
|
34 |
+
"option1",
|
35 |
+
"option2",
|
36 |
+
"context",
|
37 |
+
"evo_output",
|
38 |
+
"gpt_output",
|
39 |
+
"evo_reasoning",
|
40 |
+
"user_preference",
|
41 |
+
"evo_was_correct"
|
42 |
+
])
|
43 |
+
|
44 |
+
evo_was_correct = "yes" if user_preference == "Evo" else (
|
45 |
+
"no" if user_preference == "GPT" else ""
|
46 |
+
)
|
47 |
|
|
|
48 |
writer.writerow([
|
49 |
+
datetime.now().isoformat(),
|
50 |
+
question,
|
51 |
+
option1,
|
52 |
+
option2,
|
53 |
+
context,
|
54 |
+
evo_output,
|
55 |
+
gpt_output,
|
56 |
+
evo_reasoning,
|
57 |
+
user_preference or "",
|
58 |
+
evo_was_correct
|
59 |
])
|
60 |
+
print("✅ Feedback successfully logged.")
|
61 |
+
|
62 |
+
except Exception as e:
|
63 |
+
print("❌ Failed to log feedback:", e)
|
64 |
|
65 |
+
# ✅ Manual test trigger
|
66 |
+
if __name__ == "__main__":
|
67 |
+
log_feedback(
|
68 |
+
"What is 2 + 2?",
|
69 |
+
"4",
|
70 |
+
"5",
|
71 |
+
"Basic math context",
|
72 |
+
"4",
|
73 |
+
"4",
|
74 |
+
"Both answered correctly.",
|
75 |
+
"Evo"
|
76 |
+
)
|
|
|
|
|
|
|
|