mgbam commited on
Commit
ebde4a2
·
verified ·
1 Parent(s): 88bd42a

Update agents/agents.py

Browse files
Files changed (1) hide show
  1. agents/agents.py +140 -111
agents/agents.py CHANGED
@@ -14,6 +14,7 @@ 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
  return self._mock_outline(topic, duration, difficulty)
18
 
19
  try:
@@ -45,6 +46,7 @@ class TopicAgent:
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,6 +95,7 @@ class TopicAgent:
93
  class ContentAgent:
94
  def generate_content(self, outline):
95
  if not openai_client:
 
96
  return self._mock_content(outline)
97
 
98
  try:
@@ -127,6 +130,7 @@ class ContentAgent:
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,6 +177,7 @@ class ContentAgent:
173
  class SlideAgent:
174
  def generate_slides(self, content):
175
  if not openai_client:
 
176
  return self._professional_slides(content)
177
 
178
  try:
@@ -202,6 +207,7 @@ class SlideAgent:
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,54 +251,55 @@ 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
@@ -311,91 +318,113 @@ class PromptOptimizer:
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 []
 
 
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
  )
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
  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
  )
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
  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
  )
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
  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
+ Q&A: Let's discuss your specific challenges
 
 
260
  """
 
261
  class CodeAgent:
262
+ def generate_code(self, content):
263
+ if not openai_client:
264
+ print("OpenAI API not set - using enhanced mock data for code.")
265
+ return self._professional_code(content)
266
+ Generated code
267
+ try:
268
+ response = openai_client.chat.completions.create(
269
+ model="gpt-4-turbo",
270
+ messages=[
271
+ {
272
+ "role": "system",
273
+ "content": (
274
+ "You are an enterprise solutions architect. Create professional-grade code labs with: "
275
+ "1) Production-ready patterns 2) Comprehensive documentation "
276
+ "3) Enterprise security practices 4) Scalable architectures. "
277
+ "Use Python with the latest best practices."
278
+ )
279
+ },
280
+ {
281
+ "role": "user",
282
+ "content": (
283
+ f"Create a professional code lab for: {json.dumps(content)}. "
284
+ "Include: Setup instructions, business solution patterns, "
285
+ "enterprise integration examples, and security best practices."
286
+ )
287
+ }
288
+ ],
289
+ temperature=0.3,
290
+ max_tokens=2500
291
+ )
292
+ return response.choices[0].message.content
293
+ except Exception as e:
294
+ print(f"Error generating code: {e}. Using mock data.")
295
+ return self._professional_code(content)
296
 
297
+ def _professional_code(self, content):
298
+ return f"""
299
+ Use code with caution.
300
+ Enterprise-Grade Prompt Engineering Lab
301
  Business Solution Framework
302
+ Generated python
303
  class PromptOptimizer:
304
  def __init__(self, model="gpt-4-turbo"):
305
  self.model = model
 
318
  # Example usage
319
  optimizer = PromptOptimizer()
320
  print(optimizer.calculate_roi(500000, 0.35)) # $175,000 savings
321
+ Use code with caution.
322
+ Python
323
  Security Best Practices
324
+ Generated python
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
+ Use code with caution.
337
+ Python
338
  Integration Pattern: CRM System
339
+ Generated python
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
+ print("OpenAI API not set - skipping design generation.")
354
+ return None
355
+ Generated code
356
+ try:
357
+ response = openai_client.images.generate(
358
+ model="dall-e-3",
359
+ prompt=(
360
+ f"Professional corporate slide background for '{slide_content[:200]}' workshop. "
361
+ "Modern business style, clean lines, premium gradient, boardroom appropriate. "
362
+ "Include abstract technology elements in corporate colors."
363
+ ),
364
+ n=1,
365
+ size="1024x1024"
366
+ )
367
+ return response.data[0].url
368
+ except Exception as e:
369
+ print(f"Error generating design: {e}. Skipping design generation.")
370
+ return None
371
+ Use code with caution.
372
  class VoiceoverAgent:
373
+ def init(self):
374
+ self.api_key = ELEVENLABS_API_KEY
375
+ self.voice_id = "21m00Tcm4TlvDq8ikWAM" # Default voice ID (pre-selected voice "Rachel")
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
+ try:
384
+ voice = voice_id if voice_id else self.voice_id
385
+
386
+ url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice}"
387
+ headers = {
388
+ "Accept": "audio/mpeg",
389
+ "Content-Type": "application/json",
390
+ "xi-api-key": self.api_key
391
+ }
392
+ data = {
393
+ "text": text,
394
+ "model_id": self.model,
395
+ "voice_settings": {
396
+ "stability": 0.7,
397
+ "similarity_boost": 0.8,
398
+ "style": 0.5,
399
+ "use_speaker_boost": True
 
 
 
 
 
400
  }
401
+ }
402
+ response = requests.post(url, json=data, headers=headers)
403
+
404
+ if response.status_code == 200:
405
+ return response.content
406
+ else:
407
+ print(f"Error from ElevenLabs API: {response.status_code} - {response.text}")
408
  return None
409
+ except Exception as e:
410
+ print(f"Error generating voiceover: {e}. Skipping voiceover generation.")
411
+ return None
412
+
413
+ def get_voices(self):
414
+ if not self.api_key:
415
+ print("ElevenLabs API key not set - cannot fetch voices.")
416
+ return []
417
+
418
+ try:
419
+ url = "https://api.elevenlabs.io/v1/voices"
420
+ headers = {"xi-api-key": self.api_key}
421
+ response = requests.get(url, headers=headers)
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
+ except Exception as e:
429
+ print(f"Error fetching voices: {e}.")
430
+ return []