Delete agents.py
Browse files
agents.py
DELETED
@@ -1,401 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
import os
|
3 |
-
import requests
|
4 |
-
from dotenv import load_dotenv
|
5 |
-
from openai import OpenAI
|
6 |
-
|
7 |
-
# Load environment variables
|
8 |
-
load_dotenv()
|
9 |
-
|
10 |
-
# Initialize API clients
|
11 |
-
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) if os.getenv("OPENAI_API_KEY") else None
|
12 |
-
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
|
13 |
-
|
14 |
-
class TopicAgent:
|
15 |
-
def generate_outline(self, topic, duration, difficulty):
|
16 |
-
if not openai_client:
|
17 |
-
return self._mock_outline(topic, duration, difficulty)
|
18 |
-
|
19 |
-
try:
|
20 |
-
response = openai_client.chat.completions.create(
|
21 |
-
model="gpt-4-turbo",
|
22 |
-
messages=[
|
23 |
-
{
|
24 |
-
"role": "system",
|
25 |
-
"content": (
|
26 |
-
"You are an expert corporate trainer with 20+ years of experience creating "
|
27 |
-
"high-value workshops for Fortune 500 companies. Create a professional workshop outline that "
|
28 |
-
"includes: 1) Clear learning objectives, 2) Practical real-world exercises, "
|
29 |
-
"3) Industry case studies, 4) Measurable outcomes. Format as JSON."
|
30 |
-
)
|
31 |
-
},
|
32 |
-
{
|
33 |
-
"role": "user",
|
34 |
-
"content": (
|
35 |
-
f"Create a comprehensive {duration}-hour {difficulty} workshop outline on '{topic}' for corporate executives. "
|
36 |
-
"Structure: title, duration, difficulty, learning_goals (3-5 bullet points), "
|
37 |
-
"modules (5-7 modules). Each module should have: title, duration, learning_points (3 bullet points), "
|
38 |
-
"case_study (real company example), exercises (2 practical exercises)."
|
39 |
-
)
|
40 |
-
}
|
41 |
-
],
|
42 |
-
temperature=0.3,
|
43 |
-
max_tokens=1500,
|
44 |
-
response_format={"type": "json_object"}
|
45 |
-
)
|
46 |
-
return json.loads(response.choices[0].message.content)
|
47 |
-
except Exception as e:
|
48 |
-
return self._mock_outline(topic, duration, difficulty)
|
49 |
-
|
50 |
-
def _mock_outline(self, topic, duration, difficulty):
|
51 |
-
return {
|
52 |
-
"title": f"Mastering {topic} for Business Impact",
|
53 |
-
"duration": f"{duration} hours",
|
54 |
-
"difficulty": difficulty,
|
55 |
-
"learning_goals": [
|
56 |
-
"Apply advanced techniques to real business challenges",
|
57 |
-
"Measure ROI of prompt engineering initiatives",
|
58 |
-
"Develop organizational prompt engineering standards",
|
59 |
-
"Implement ethical AI governance frameworks"
|
60 |
-
],
|
61 |
-
"modules": [
|
62 |
-
{
|
63 |
-
"title": "Strategic Foundations",
|
64 |
-
"duration": "45 min",
|
65 |
-
"learning_points": [
|
66 |
-
"Business value assessment framework",
|
67 |
-
"ROI calculation models",
|
68 |
-
"Stakeholder alignment strategies"
|
69 |
-
],
|
70 |
-
"case_study": "How JPMorgan reduced operational costs by 37% with prompt optimization",
|
71 |
-
"exercises": [
|
72 |
-
"Calculate potential ROI for your organization",
|
73 |
-
"Develop stakeholder communication plan"
|
74 |
-
]
|
75 |
-
},
|
76 |
-
{
|
77 |
-
"title": "Advanced Pattern Engineering",
|
78 |
-
"duration": "60 min",
|
79 |
-
"learning_points": [
|
80 |
-
"Chain-of-thought implementations",
|
81 |
-
"Self-correcting prompt architectures",
|
82 |
-
"Domain-specific pattern libraries"
|
83 |
-
],
|
84 |
-
"case_study": "McKinsey's knowledge management transformation",
|
85 |
-
"exercises": [
|
86 |
-
"Design pattern library for your industry",
|
87 |
-
"Implement self-correction workflow"
|
88 |
-
]
|
89 |
-
}
|
90 |
-
]
|
91 |
-
}
|
92 |
-
|
93 |
-
class ContentAgent:
|
94 |
-
def generate_content(self, outline):
|
95 |
-
if not openai_client:
|
96 |
-
return self._mock_content(outline)
|
97 |
-
|
98 |
-
try:
|
99 |
-
response = openai_client.chat.completions.create(
|
100 |
-
model="gpt-4-turbo",
|
101 |
-
messages=[
|
102 |
-
{
|
103 |
-
"role": "system",
|
104 |
-
"content": (
|
105 |
-
"You are a senior instructional designer creating premium corporate training materials. "
|
106 |
-
"Develop comprehensive workshop content with: 1) Practitioner-level insights, "
|
107 |
-
"2) Actionable frameworks, 3) Real-world examples, 4) Practical exercises. "
|
108 |
-
"Avoid generic AI content - focus on business impact."
|
109 |
-
)
|
110 |
-
},
|
111 |
-
{
|
112 |
-
"role": "user",
|
113 |
-
"content": (
|
114 |
-
f"Create premium workshop content for this outline: {json.dumps(outline)}. "
|
115 |
-
"For each module: "
|
116 |
-
"1) Detailed script (executive summary, 3 key concepts, business applications) "
|
117 |
-
"2) Speaker notes (presentation guidance) "
|
118 |
-
"3) 3 discussion questions with executive-level responses "
|
119 |
-
"4) 2 practical exercises with solution blueprints "
|
120 |
-
"Format as JSON."
|
121 |
-
)
|
122 |
-
}
|
123 |
-
],
|
124 |
-
temperature=0.4,
|
125 |
-
max_tokens=3000,
|
126 |
-
response_format={"type": "json_object"}
|
127 |
-
)
|
128 |
-
return json.loads(response.choices[0].message.content)
|
129 |
-
except Exception as e:
|
130 |
-
return self._mock_content(outline)
|
131 |
-
|
132 |
-
def _mock_content(self, outline):
|
133 |
-
return {
|
134 |
-
"workshop_title": outline.get("title", "Premium AI Workshop"),
|
135 |
-
"modules": [
|
136 |
-
{
|
137 |
-
"title": "Strategic Foundations",
|
138 |
-
"script": (
|
139 |
-
"## Executive Summary\n"
|
140 |
-
"This module establishes the business case for advanced prompt engineering, "
|
141 |
-
"focusing on measurable ROI and stakeholder alignment.\n\n"
|
142 |
-
"### Key Concepts:\n"
|
143 |
-
"1. **Value Assessment Framework**: Quantify potential savings and revenue opportunities\n"
|
144 |
-
"2. **ROI Calculation Models**: Custom models for different industries\n"
|
145 |
-
"3. **Stakeholder Alignment**: Executive communication strategies\n\n"
|
146 |
-
"### Business Applications:\n"
|
147 |
-
"- Cost reduction in customer service operations\n"
|
148 |
-
"- Acceleration of R&D processes\n"
|
149 |
-
"- Enhanced competitive intelligence"
|
150 |
-
),
|
151 |
-
"speaker_notes": [
|
152 |
-
"Emphasize real dollar impact - use JPMorgan case study numbers",
|
153 |
-
"Show ROI calculator template",
|
154 |
-
"Highlight C-suite communication strategies"
|
155 |
-
],
|
156 |
-
"discussion_questions": [
|
157 |
-
{
|
158 |
-
"question": "How could prompt engineering impact your bottom line?",
|
159 |
-
"response": "Typical results: 30-40% operational efficiency gains, 15-25% innovation acceleration"
|
160 |
-
}
|
161 |
-
],
|
162 |
-
"exercises": [
|
163 |
-
{
|
164 |
-
"title": "ROI Calculation Workshop",
|
165 |
-
"instructions": "Calculate potential savings using our enterprise ROI model",
|
166 |
-
"solution": "Template: (Current Cost × Efficiency Gain) - Implementation Cost"
|
167 |
-
}
|
168 |
-
]
|
169 |
-
}
|
170 |
-
]
|
171 |
-
}
|
172 |
-
|
173 |
-
class SlideAgent:
|
174 |
-
def generate_slides(self, content):
|
175 |
-
if not openai_client:
|
176 |
-
return self._professional_slides(content)
|
177 |
-
|
178 |
-
try:
|
179 |
-
response = openai_client.chat.completions.create(
|
180 |
-
model="gpt-4-turbo",
|
181 |
-
messages=[
|
182 |
-
{
|
183 |
-
"role": "system",
|
184 |
-
"content": (
|
185 |
-
"You are a McKinsey-level presentation specialist. Create professional slides with: "
|
186 |
-
"1) Clean, executive-friendly design 2) Data visualization frameworks "
|
187 |
-
"3) Action-oriented content 4) Brand-compliant styling. "
|
188 |
-
"Use Marp Markdown format with the 'gaia' theme."
|
189 |
-
)
|
190 |
-
},
|
191 |
-
{
|
192 |
-
"role": "user",
|
193 |
-
"content": (
|
194 |
-
f"Create a boardroom-quality slide deck for: {json.dumps(content)}. "
|
195 |
-
"Structure: Title slide, module slides (objective, 3 key points, case study, exercise), "
|
196 |
-
"summary slide. Include placeholders for data visualization."
|
197 |
-
)
|
198 |
-
}
|
199 |
-
],
|
200 |
-
temperature=0.2,
|
201 |
-
max_tokens=2500
|
202 |
-
)
|
203 |
-
return response.choices[0].message.content
|
204 |
-
except Exception as e:
|
205 |
-
return self._professional_slides(content)
|
206 |
-
|
207 |
-
def _professional_slides(self, content):
|
208 |
-
return f"""---
|
209 |
-
marp: true
|
210 |
-
theme: gaia
|
211 |
-
class: lead
|
212 |
-
paginate: true
|
213 |
-
backgroundColor: #fff
|
214 |
-
backgroundImage: url('https://marp.app/assets/hero-background.svg')
|
215 |
-
---
|
216 |
-
|
217 |
-
# {content.get('workshop_title', 'Executive AI Workshop')}
|
218 |
-
## Transforming Business Through Advanced AI
|
219 |
-
|
220 |
-
---
|
221 |
-
<!-- _class: invert -->
|
222 |
-
## Module 1: Strategic Foundations
|
223 |
-
### Driving Measurable Business Value
|
224 |
-
|
225 |
-

|
226 |
-
|
227 |
-
- **ROI Framework**: Quantifying impact
|
228 |
-
- **Stakeholder Alignment**: Executive buy-in strategies
|
229 |
-
- **Implementation Roadmap**: Phased adoption plan
|
230 |
-
|
231 |
-
---
|
232 |
-
## Case Study: Financial Services Transformation
|
233 |
-
### JPMorgan Chase
|
234 |
-
|
235 |
-
| Metric | Before | After | Improvement |
|
236 |
-
|--------|--------|-------|-------------|
|
237 |
-
| Operation Costs | $4.2M | $2.6M | 38% reduction |
|
238 |
-
| Process Time | 14 days | 3 days | 79% faster |
|
239 |
-
| Error Rate | 8.2% | 0.4% | 95% reduction |
|
240 |
-
|
241 |
-
---
|
242 |
-
## Practical Exercise: ROI Calculation
|
243 |
-
```mermaid
|
244 |
-
graph TD
|
245 |
-
A[Current Costs] --> B[Potential Savings]
|
246 |
-
C[Implementation Costs] --> D[Net ROI]
|
247 |
-
B --> D
|
248 |
-
Document current process costs
|
249 |
-
|
250 |
-
Estimate efficiency gains
|
251 |
-
|
252 |
-
Calculate net ROI
|
253 |
-
|
254 |
-
Q&A
|
255 |
-
Let's discuss your specific challenges
|
256 |
-
"""
|
257 |
-
|
258 |
-
class CodeAgent:
|
259 |
-
def generate_code(self, content):
|
260 |
-
if not openai_client:
|
261 |
-
return self._professional_code(content)
|
262 |
-
|
263 |
-
try:
|
264 |
-
response = openai_client.chat.completions.create(
|
265 |
-
model="gpt-4-turbo",
|
266 |
-
messages=[
|
267 |
-
{
|
268 |
-
"role": "system",
|
269 |
-
"content": (
|
270 |
-
"You are an enterprise solutions architect. Create professional-grade code labs with: "
|
271 |
-
"1) Production-ready patterns 2) Comprehensive documentation "
|
272 |
-
"3) Enterprise security practices 4) Scalable architectures. "
|
273 |
-
"Use Python with the latest best practices."
|
274 |
-
)
|
275 |
-
},
|
276 |
-
{
|
277 |
-
"role": "user",
|
278 |
-
"content": (
|
279 |
-
f"Create a professional code lab for: {json.dumps(content)}. "
|
280 |
-
"Include: Setup instructions, business solution patterns, "
|
281 |
-
"enterprise integration examples, and security best practices."
|
282 |
-
)
|
283 |
-
}
|
284 |
-
],
|
285 |
-
temperature=0.3,
|
286 |
-
max_tokens=2500
|
287 |
-
)
|
288 |
-
return response.choices[0].message.content
|
289 |
-
except Exception as e:
|
290 |
-
return self._professional_code(content)
|
291 |
-
|
292 |
-
def _professional_code(self, content):
|
293 |
-
return f"""# Enterprise-Grade Prompt Engineering Lab
|
294 |
-
Business Solution Framework
|
295 |
-
python
|
296 |
-
class PromptOptimizer:
|
297 |
-
def __init__(self, model="gpt-4-turbo"):
|
298 |
-
self.model = model
|
299 |
-
self.pattern_library = {{
|
300 |
-
"financial_analysis": "Extract key metrics from financial reports",
|
301 |
-
"customer_service": "Resolve tier-2 support tickets"
|
302 |
-
}}
|
303 |
-
|
304 |
-
def optimize_prompt(self, business_case):
|
305 |
-
# Implement enterprise optimization logic
|
306 |
-
return f"Business-optimized prompt for {{business_case}}"
|
307 |
-
|
308 |
-
def calculate_roi(self, current_cost, expected_efficiency):
|
309 |
-
return current_cost * expected_efficiency
|
310 |
-
|
311 |
-
# Example usage
|
312 |
-
optimizer = PromptOptimizer()
|
313 |
-
print(optimizer.calculate_roi(500000, 0.35)) # $175,000 savings
|
314 |
-
|
315 |
-
Security Best Practices
|
316 |
-
python
|
317 |
-
def secure_prompt_handling(user_input):
|
318 |
-
# Implement OWASP security standards
|
319 |
-
sanitized = sanitize_input(user_input)
|
320 |
-
validate_business_context(sanitized)
|
321 |
-
return apply_enterprise_guardrails(sanitized)
|
322 |
-
|
323 |
-
Integration Pattern: CRM System
|
324 |
-
python
|
325 |
-
def integrate_with_salesforce(prompt, salesforce_data):
|
326 |
-
# Enterprise integration example
|
327 |
-
enriched_prompt = f"{{prompt}} using {{salesforce_data}}"
|
328 |
-
return call_ai_api(enriched_prompt)
|
329 |
-
"""
|
330 |
-
|
331 |
-
class DesignAgent:
|
332 |
-
def generate_design(self, slide_content):
|
333 |
-
if not openai_client:
|
334 |
-
return None
|
335 |
-
|
336 |
-
try:
|
337 |
-
response = openai_client.images.generate(
|
338 |
-
model="dall-e-3",
|
339 |
-
prompt=(
|
340 |
-
f"Professional corporate slide background for '{slide_content[:200]}' workshop. "
|
341 |
-
"Modern business style, clean lines, premium gradient, boardroom appropriate. "
|
342 |
-
"Include abstract technology elements in corporate colors."
|
343 |
-
),
|
344 |
-
n=1,
|
345 |
-
size="1024x1024"
|
346 |
-
)
|
347 |
-
return response.data[0].url
|
348 |
-
except Exception as e:
|
349 |
-
return None
|
350 |
-
|
351 |
-
class VoiceoverAgent:
|
352 |
-
def __init__(self):
|
353 |
-
self.api_key = ELEVENLABS_API_KEY
|
354 |
-
self.voice_id = "21m00Tcm4TlvDq8ikWAM" # Default voice ID
|
355 |
-
self.model = "eleven_monolingual_v1"
|
356 |
-
|
357 |
-
def generate_voiceover(self, text, voice_id=None):
|
358 |
-
if not self.api_key:
|
359 |
-
return None
|
360 |
-
|
361 |
-
try:
|
362 |
-
voice = voice_id if voice_id else self.voice_id
|
363 |
-
|
364 |
-
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice}"
|
365 |
-
headers = {
|
366 |
-
"Accept": "audio/mpeg",
|
367 |
-
"Content-Type": "application/json",
|
368 |
-
"xi-api-key": self.api_key
|
369 |
-
}
|
370 |
-
data = {
|
371 |
-
"text": text,
|
372 |
-
"model_id": self.model,
|
373 |
-
"voice_settings": {
|
374 |
-
"stability": 0.7,
|
375 |
-
"similarity_boost": 0.8,
|
376 |
-
"style": 0.5,
|
377 |
-
"use_speaker_boost": True
|
378 |
-
}
|
379 |
-
}
|
380 |
-
response = requests.post(url, json=data, headers=headers)
|
381 |
-
|
382 |
-
if response.status_code == 200:
|
383 |
-
return response.content
|
384 |
-
return None
|
385 |
-
except Exception as e:
|
386 |
-
return None
|
387 |
-
|
388 |
-
def get_voices(self):
|
389 |
-
if not self.api_key:
|
390 |
-
return []
|
391 |
-
|
392 |
-
try:
|
393 |
-
url = "https://api.elevenlabs.io/v1/voices"
|
394 |
-
headers = {"xi-api-key": self.api_key}
|
395 |
-
response = requests.get(url, headers=headers)
|
396 |
-
|
397 |
-
if response.status_code == 200:
|
398 |
-
return response.json().get("voices", [])
|
399 |
-
return []
|
400 |
-
except Exception as e:
|
401 |
-
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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