Spaces:
Sleeping
Sleeping
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. | |
""" | |
file_exists = os.path.isfile(LOG_FILE) | |
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 | |
]) | |