File size: 916 Bytes
e0f0929
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

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
        ]