HemanM commited on
Commit
e96f206
·
verified ·
1 Parent(s): ec179c9

Update logger.py

Browse files
Files changed (1) hide show
  1. logger.py +51 -29
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
- with open(LOG_FILE, mode='a', newline='', encoding='utf-8') as file:
23
- writer = csv.writer(file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- if not file_exists:
26
  writer.writerow([
27
- "timestamp",
28
- "question",
29
- "option1",
30
- "option2",
31
- "context",
32
- "evo_output",
33
- "gpt_output",
34
- "evo_reasoning",
35
- "user_preference",
36
- "evo_was_correct"
37
  ])
 
 
 
 
38
 
39
- evo_was_correct = "yes" if user_preference == "Evo" else (
40
- "no" if user_preference == "GPT" else ""
41
- )
42
-
43
- writer.writerow([
44
- datetime.now().isoformat(),
45
- question,
46
- option1,
47
- option2,
48
- context,
49
- evo_output,
50
- gpt_output,
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
+ )