"""User Feedback Handler""" import time from typing import Optional, Dict from enum import Enum class FeedbackType(Enum): """Types of user feedback""" POSITIVE = "positive" NEGATIVE = "negative" NEUTRAL = "neutral" class FeedbackHandler: """Handle user feedback""" def __init__(self): self.feedback_history: list[Dict] = [] def collect_feedback( self, response_id: str, helpful: bool, comment: Optional[str] = None ): """Collect user feedback""" feedback = { "response_id": response_id, "helpful": helpful, "comment": comment, "timestamp": time.time(), } self.feedback_history.append(feedback) return feedback def get_average_rating(self) -> float: """Calculate average feedback rating""" if not self.feedback_history: return 0.0 positive = sum(1 for f in self.feedback_history if f["helpful"]) return positive / len(self.feedback_history) def show_feedback_prompt(self): """Show feedback prompt""" print("\n[bold cyan]Was this response helpful?[/bold cyan]") print(" [green]1.[/green] Yes šŸ‘") print(" [red]2.[/red] No šŸ‘Ž") print(" [yellow]3.[/yellow] Skip ā­ļø") def process_quick_feedback(self, rating: int) -> Dict: """Process quick feedback""" feedback_map = { 1: (True, "positive"), 2: (False, "negative"), 3: (None, "neutral"), } helpful, ftype = feedback_map.get(rating, (None, "neutral")) if helpful is not None: return self.collect_feedback( f"response_{int(time.time())}", helpful=helpful ) return {"type": "skipped"} def quick_feedback_prompt(): """Quick feedback prompt""" print("\nšŸ“Š Quick Feedback:") print(" šŸ‘ This helped!") print(" šŸ‘Ž Needs improvement") print(" ā­ļø Skip")