Spaces:
Runtime error
Runtime error
| import random | |
| class PromptOptimizer: | |
| def __init__(self): | |
| self.prompts = [ | |
| "What is your main objective today?", | |
| "How can I assist with your current task?", | |
| "What’s the next priority to focus on?", | |
| ] | |
| self.performance_data = {} | |
| def get_prompt(self): | |
| return random.choice(self.prompts) | |
| def record_feedback(self, prompt, success=True): | |
| if prompt not in self.performance_data: | |
| self.performance_data[prompt] = {"success": 0, "fail": 0} | |
| if success: | |
| self.performance_data[prompt]["success"] += 1 | |
| else: | |
| self.performance_data[prompt]["fail"] += 1 | |
| def optimize_prompts(self): | |
| # Basic strategy: remove consistently failing prompts | |
| self.prompts = [ | |
| p for p in self.prompts | |
| if self.performance_data.get(p, {}).get("fail", 0) < 3 | |
| ] | |