File size: 1,920 Bytes
80cdad4
 
c1de334
80cdad4
 
 
c1de334
 
 
 
 
 
 
 
 
 
 
d45f9ca
e96f206
c1de334
e96f206
 
 
80cdad4
d45f9ca
e96f206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1de334
bcf74f5
e96f206
 
 
 
 
 
 
 
 
 
bcf74f5
e96f206
 
 
 
d45f9ca
e96f206
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
import csv
import os
from datetime import datetime

LOG_FILE = "feedback_log.csv"

def log_feedback(
    question,
    option1,
    option2,
    context,
    evo_output,
    gpt_output,
    evo_reasoning,
    user_preference=None
):
    """
    Logs Evo and GPT output along with user's preference for retraining.
    Creates feedback_log.csv automatically if it doesn't exist.
    """
    print("✅ log_feedback() triggered")
    print("User voted:", user_preference)

    file_exists = os.path.isfile(LOG_FILE)

    try:
        with open(LOG_FILE, mode='a', newline='', encoding='utf-8') as file:
            writer = csv.writer(file)

            if not file_exists:
                writer.writerow([
                    "timestamp",
                    "question",
                    "option1",
                    "option2",
                    "context",
                    "evo_output",
                    "gpt_output",
                    "evo_reasoning",
                    "user_preference",
                    "evo_was_correct"
                ])

            evo_was_correct = "yes" if user_preference == "Evo" else (
                "no" if user_preference == "GPT" else ""
            )

            writer.writerow([
                datetime.now().isoformat(),
                question,
                option1,
                option2,
                context,
                evo_output,
                gpt_output,
                evo_reasoning,
                user_preference or "",
                evo_was_correct
            ])
        print("✅ Feedback successfully logged.")

    except Exception as e:
        print("❌ Failed to log feedback:", e)

# ✅ Manual test trigger
if __name__ == "__main__":
    log_feedback(
        "What is 2 + 2?",
        "4",
        "5",
        "Basic math context",
        "4",
        "4",
        "Both answered correctly.",
        "Evo"
    )