EvoPlatformV3 / retrain_from_feedback.py
HemanM's picture
Update retrain_from_feedback.py
b0e670a verified
raw
history blame
1.6 kB
import csv
import os
from datetime import datetime
from retrain_from_feedback import train_evo
# πŸ” Main entry point for feedback-triggered retraining
def retrain_from_feedback(feedback_log):
# βœ… Check if feedback is present
if not feedback_log:
return "⚠️ No feedback data to retrain from."
# πŸ“ Write feedback to CSV
try:
os.makedirs("feedback", exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filepath = f"feedback/feedback_log.csv" # also usable for loading
with open(filepath, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow([
"question", "option1", "option2", "answer",
"confidence", "reasoning", "context",
"user_preference", "evo_was_correct", "evo_output"
])
for row in feedback_log:
question, option1, option2, answer, confidence, reasoning, context = row
# Simulate Evo being preferred (you can modify this logic later)
writer.writerow([
question, option1, option2, answer,
confidence, reasoning, context,
"evo", "yes", answer
])
except Exception as e:
return f"❌ Failed to save feedback: {str(e)}"
# πŸ” Trigger training
try:
train_evo() # This uses the latest feedback_log.csv
return "βœ… Evo retrained and weights saved."
except Exception as e:
return f"❌ Evo training failed: {str(e)}"