-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_training_example.py
More file actions
225 lines (186 loc) · 6.96 KB
/
agent_training_example.py
File metadata and controls
225 lines (186 loc) · 6.96 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
"""
Agent Training Example
======================
This script demonstrates how to use another AI agent (or human reviewer)
to analyze feedback and suggest improvements to the chatbot.
Usage:
python agent_training_example.py
"""
from feedback_system import FeedbackSystem
import json
def analyze_feedback_for_training():
"""
Example of how to prepare feedback for another agent to analyze.
"""
print("=" * 80)
print("AGENT TRAINING EXAMPLE")
print("=" * 80)
print()
# Initialize feedback system
fs = FeedbackSystem()
# Check if we have feedback
stats = fs.get_feedback_stats()
if stats["total_count"] == 0:
print("⚠️ No feedback data available yet.")
print()
print("To use this feature:")
print("1. Run the chatbot: streamlit run app.py")
print("2. Have some conversations and rate the responses")
print("3. Run this script again")
return
print(f"📊 Found {stats['total_count']} feedback entries")
print(f" 👍 Positive: {stats['positive_count']}")
print(f" 👎 Negative: {stats['negative_count']}")
print(f" 💬 With text: {stats['with_text']}")
print()
# Export for training
print("📤 Exporting feedback for training...")
fs.export_for_training("training_data.json")
print(" ✅ Exported to training_data.json")
print()
# Show examples that need improvement
print("=" * 80)
print("NEGATIVE FEEDBACK (Needs Improvement)")
print("=" * 80)
print()
negative = fs.get_negative_feedback()
if len(negative) > 0:
for i, entry in enumerate(negative[:5], 1):
print(f"Example {i}:")
print(f" Question: {entry['question']}")
print(f" Response: {entry['response'][:150]}...")
print(f" Rating: {entry.get('rating', 'N/A')}")
if entry.get('text_feedback'):
print(f" Feedback: {entry['text_feedback']}")
print()
else:
print("✅ No negative feedback - great job!")
print()
print("=" * 80)
print("POSITIVE FEEDBACK (Working Well)")
print("=" * 80)
print()
positive = fs.get_positive_feedback()
if len(positive) > 0:
for i, entry in enumerate(positive[:3], 1):
print(f"Example {i}:")
print(f" Question: {entry['question']}")
print(f" Response: {entry['response'][:150]}...")
print(f" Rating: {entry.get('rating', 'N/A')}")
if entry.get('text_feedback'):
print(f" Feedback: {entry['text_feedback']}")
print()
else:
print("⚠️ No positive feedback yet")
print()
print("=" * 80)
print("INSTRUCTIONS FOR TRAINING AGENT")
print("=" * 80)
print()
print("You can now use another AI agent to improve the chatbot:")
print()
print("1. Share the training_data.json file with the agent")
print("2. Ask the agent to:")
print(" - Analyze patterns in negative feedback")
print(" - Suggest improvements to responses")
print(" - Identify edge cases not handled well")
print(" - Recommend changes to system prompts")
print()
print("3. Example prompt for the agent:")
print(" \"Analyze this chatbot feedback data and suggest 3-5 specific")
print(" improvements to make the chatbot more helpful. Focus on the")
print(" negative feedback and identify patterns.\"")
print()
print("4. Implement suggested improvements in app.py")
print("5. Test and collect more feedback")
print("6. Repeat!")
print()
print("=" * 80)
def show_learning_examples():
"""
Show high-quality examples for training.
"""
print("\n" + "=" * 80)
print("TOP LEARNING EXAMPLES")
print("=" * 80)
print()
fs = FeedbackSystem()
examples = fs.get_learning_examples(limit=5)
if len(examples) == 0:
print("No learning examples available yet.")
return
for i, entry in enumerate(examples, 1):
print(f"Example {i}:")
print(f" Question: {entry['question']}")
print(f" Response: {entry['response'][:200]}...")
print(f" Rating: {entry.get('rating', 'N/A')}")
if entry.get('text_feedback'):
print(f" Feedback: {entry['text_feedback']}")
if entry.get('disc_names'):
print(f" Discs: {', '.join(entry['disc_names'])}")
print()
print("These examples can be used to:")
print("- Fine-tune language models")
print("- Add to RAG knowledge base")
print("- Create test cases")
print("- Benchmark response quality")
def generate_training_prompt():
"""
Generate a prompt for another agent to analyze feedback.
"""
fs = FeedbackSystem()
negative = fs.get_negative_feedback()
positive = fs.get_positive_feedback()
if len(negative) == 0 and len(positive) == 0:
print("\nNo feedback available to generate prompt.")
return
print("\n" + "=" * 80)
print("GENERATED TRAINING PROMPT")
print("=" * 80)
print()
print("Copy this prompt and share it with another AI agent along with training_data.json:")
print()
print("-" * 80)
print()
prompt = f"""I need help improving a disc golf recommendation chatbot. I've collected user feedback and want you to analyze it and suggest improvements.
The chatbot helps users find the right disc golf discs based on their skill level, throwing distance, and preferences.
Feedback Summary:
- Total feedback: {fs.get_feedback_stats()['total_count']}
- Positive (👍): {fs.get_feedback_stats()['positive_count']}
- Negative (👎): {fs.get_feedback_stats()['negative_count']}
- With detailed comments: {fs.get_feedback_stats()['with_text']}
I've attached training_data.json with the full feedback data.
Please analyze the feedback and provide:
1. Top 3 patterns in negative feedback
2. What the chatbot is doing well (based on positive feedback)
3. 5 specific, actionable improvements I can implement
4. Suggestions for system prompt changes
5. Edge cases the chatbot should handle better
Focus on making the chatbot more accurate, helpful, and user-friendly."""
print(prompt)
print()
print("-" * 80)
print()
print("After getting suggestions from the agent:")
print("1. Review the suggestions carefully")
print("2. Implement changes in app.py")
print("3. Test the changes")
print("4. Collect more feedback")
print("5. Iterate!")
def main():
analyze_feedback_for_training()
show_learning_examples()
generate_training_prompt()
print("\n" + "=" * 80)
print("NEXT STEPS")
print("=" * 80)
print()
print("✓ Review the feedback examples above")
print("✓ Use training_data.json to train another agent")
print("✓ Implement suggested improvements")
print("✓ Test and iterate!")
print()
print("Happy training! 🎉")
print()
if __name__ == "__main__":
main()