File size: 2,007 Bytes
a7d7463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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")