Update agents/agents.py
Browse files- agents/agents.py +111 -140
agents/agents.py
CHANGED
@@ -14,7 +14,6 @@ ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
|
|
14 |
class TopicAgent:
|
15 |
def generate_outline(self, topic, duration, difficulty):
|
16 |
if not openai_client:
|
17 |
-
print("OpenAI API not set - using enhanced mock data for outline.")
|
18 |
return self._mock_outline(topic, duration, difficulty)
|
19 |
|
20 |
try:
|
@@ -46,7 +45,6 @@ class TopicAgent:
|
|
46 |
)
|
47 |
return json.loads(response.choices[0].message.content)
|
48 |
except Exception as e:
|
49 |
-
print(f"Error generating outline: {e}. Using mock data.")
|
50 |
return self._mock_outline(topic, duration, difficulty)
|
51 |
|
52 |
def _mock_outline(self, topic, duration, difficulty):
|
@@ -95,7 +93,6 @@ class TopicAgent:
|
|
95 |
class ContentAgent:
|
96 |
def generate_content(self, outline):
|
97 |
if not openai_client:
|
98 |
-
print("OpenAI API not set - using enhanced mock data for content.")
|
99 |
return self._mock_content(outline)
|
100 |
|
101 |
try:
|
@@ -130,7 +127,6 @@ class ContentAgent:
|
|
130 |
)
|
131 |
return json.loads(response.choices[0].message.content)
|
132 |
except Exception as e:
|
133 |
-
print(f"Error generating content: {e}. Using mock data.")
|
134 |
return self._mock_content(outline)
|
135 |
|
136 |
def _mock_content(self, outline):
|
@@ -177,7 +173,6 @@ class ContentAgent:
|
|
177 |
class SlideAgent:
|
178 |
def generate_slides(self, content):
|
179 |
if not openai_client:
|
180 |
-
print("OpenAI API not set - using enhanced mock data for slides.")
|
181 |
return self._professional_slides(content)
|
182 |
|
183 |
try:
|
@@ -207,7 +202,6 @@ class SlideAgent:
|
|
207 |
)
|
208 |
return response.choices[0].message.content
|
209 |
except Exception as e:
|
210 |
-
print(f"Error generating slides: {e}. Using mock data.")
|
211 |
return self._professional_slides(content)
|
212 |
|
213 |
def _professional_slides(self, content):
|
@@ -251,55 +245,54 @@ graph TD
|
|
251 |
A[Current Costs] --> B[Potential Savings]
|
252 |
C[Implementation Costs] --> D[Net ROI]
|
253 |
B --> D
|
254 |
-
Use code with caution.
|
255 |
-
Python
|
256 |
Document current process costs
|
|
|
257 |
Estimate efficiency gains
|
|
|
258 |
Calculate net ROI
|
259 |
-
|
|
|
|
|
260 |
"""
|
|
|
261 |
class CodeAgent:
|
262 |
-
def generate_code(self, content):
|
263 |
-
if not openai_client:
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
print(f"Error generating code: {e}. Using mock data.")
|
295 |
-
return self._professional_code(content)
|
296 |
|
297 |
-
def _professional_code(self, content):
|
298 |
-
|
299 |
-
Use code with caution.
|
300 |
-
Enterprise-Grade Prompt Engineering Lab
|
301 |
Business Solution Framework
|
302 |
-
|
303 |
class PromptOptimizer:
|
304 |
def __init__(self, model="gpt-4-turbo"):
|
305 |
self.model = model
|
@@ -318,113 +311,91 @@ class PromptOptimizer:
|
|
318 |
# Example usage
|
319 |
optimizer = PromptOptimizer()
|
320 |
print(optimizer.calculate_roi(500000, 0.35)) # $175,000 savings
|
321 |
-
|
322 |
-
Python
|
323 |
Security Best Practices
|
324 |
-
|
325 |
def secure_prompt_handling(user_input):
|
326 |
# Implement OWASP security standards
|
327 |
-
# This is a placeholder for actual sanitization logic
|
328 |
-
# e.g., using a library like bleach
|
329 |
-
def sanitize_input(text): return text
|
330 |
-
def validate_business_context(text): return text
|
331 |
-
def apply_enterprise_guardrails(text): return text
|
332 |
-
|
333 |
sanitized = sanitize_input(user_input)
|
334 |
validate_business_context(sanitized)
|
335 |
return apply_enterprise_guardrails(sanitized)
|
336 |
-
|
337 |
-
Python
|
338 |
Integration Pattern: CRM System
|
339 |
-
|
340 |
def integrate_with_salesforce(prompt, salesforce_data):
|
341 |
-
# This is a placeholder for actual API integration
|
342 |
-
def call_ai_api(p): return f"AI response for: {{p}}"
|
343 |
-
|
344 |
# Enterprise integration example
|
345 |
enriched_prompt = f"{{prompt}} using {{salesforce_data}}"
|
346 |
return call_ai_api(enriched_prompt)
|
347 |
-
Use code with caution.
|
348 |
-
Python
|
349 |
"""
|
|
|
350 |
class DesignAgent:
|
351 |
-
def generate_design(self, slide_content):
|
352 |
-
if not openai_client:
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
return None
|
371 |
-
Use code with caution.
|
372 |
class VoiceoverAgent:
|
373 |
-
def
|
374 |
-
self.api_key = ELEVENLABS_API_KEY
|
375 |
-
self.voice_id = "21m00Tcm4TlvDq8ikWAM"
|
376 |
-
self.model = "eleven_monolingual_v1"
|
377 |
-
Generated code
|
378 |
-
def generate_voiceover(self, text, voice_id=None):
|
379 |
-
if not self.api_key:
|
380 |
-
print("ElevenLabs API key not set - skipping voiceover generation.")
|
381 |
-
return None
|
382 |
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
"
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
"voice_settings": {
|
396 |
-
"stability": 0.7,
|
397 |
-
"similarity_boost": 0.8,
|
398 |
-
"style": 0.5,
|
399 |
-
"use_speaker_boost": True
|
400 |
}
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
return None
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
if response.status_code == 200:
|
424 |
-
return response.json().get("voices", [])
|
425 |
-
else:
|
426 |
-
print(f"Error from ElevenLabs API while fetching voices: {response.status_code} - {response.text}")
|
427 |
return []
|
428 |
-
|
429 |
-
|
430 |
-
return []
|
|
|
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:
|
|
|
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):
|
|
|
93 |
class ContentAgent:
|
94 |
def generate_content(self, outline):
|
95 |
if not openai_client:
|
|
|
96 |
return self._mock_content(outline)
|
97 |
|
98 |
try:
|
|
|
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):
|
|
|
173 |
class SlideAgent:
|
174 |
def generate_slides(self, content):
|
175 |
if not openai_client:
|
|
|
176 |
return self._professional_slides(content)
|
177 |
|
178 |
try:
|
|
|
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):
|
|
|
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
|
|
|
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 []
|
|