Download src/ui/feedback.py from amkyawdev/burme-coder-max: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/datasets/amkyawdev/burme-coder-max/resolve/main/src/ui/feedback.py
- Command line
-
hf download hf://datasets/amkyawdev/burme-coder-max/src/ui/feedback.py
-
curl -L -o feedback.py https://huggingface.co/datasets/amkyawdev/burme-coder-max/resolve/main/src/ui/feedback.py
2.01 kB
| """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") | |