mgbam commited on
Commit
c846383
·
verified ·
1 Parent(s): a0b52d1

Update agents/agents.py

Browse files
Files changed (1) hide show
  1. agents/agents.py +146 -133
agents/agents.py CHANGED
@@ -11,11 +11,12 @@ load_dotenv()
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",
@@ -44,9 +45,9 @@ class TopicAgent:
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",
@@ -90,11 +91,12 @@ class TopicAgent:
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",
@@ -126,9 +128,9 @@ class ContentAgent:
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"),
@@ -170,11 +172,12 @@ class ContentAgent:
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",
@@ -201,9 +204,9 @@ class SlideAgent:
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
@@ -256,146 +259,156 @@ 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 []
 
 
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
+
15
  class TopicAgent:
16
  def generate_outline(self, topic, duration, difficulty):
17
  if not openai_client:
18
  return self._mock_outline(topic, duration, difficulty)
19
+
20
  try:
21
  response = openai_client.chat.completions.create(
22
  model="gpt-4-turbo",
 
45
  response_format={"type": "json_object"}
46
  )
47
  return json.loads(response.choices[0].message.content)
48
+ except Exception:
49
  return self._mock_outline(topic, duration, difficulty)
50
+
51
  def _mock_outline(self, topic, duration, difficulty):
52
  return {
53
  "title": f"Mastering {topic} for Business Impact",
 
91
  ]
92
  }
93
 
94
+
95
  class ContentAgent:
96
  def generate_content(self, outline):
97
  if not openai_client:
98
  return self._mock_content(outline)
99
+
100
  try:
101
  response = openai_client.chat.completions.create(
102
  model="gpt-4-turbo",
 
128
  response_format={"type": "json_object"}
129
  )
130
  return json.loads(response.choices[0].message.content)
131
+ except Exception:
132
  return self._mock_content(outline)
133
+
134
  def _mock_content(self, outline):
135
  return {
136
  "workshop_title": outline.get("title", "Premium AI Workshop"),
 
172
  ]
173
  }
174
 
175
+
176
  class SlideAgent:
177
  def generate_slides(self, content):
178
  if not openai_client:
179
  return self._professional_slides(content)
180
+
181
  try:
182
  response = openai_client.chat.completions.create(
183
  model="gpt-4-turbo",
 
204
  max_tokens=2500
205
  )
206
  return response.choices[0].message.content
207
+ except Exception:
208
  return self._professional_slides(content)
209
+
210
  def _professional_slides(self, content):
211
  return f"""---
212
  marp: true
 
259
  """
260
 
261
  class CodeAgent:
262
+ def generate_code(self, content):
263
+ if not openai_client:
264
+ return self._professional_code(content)
265
+
266
+ python
267
+ Copy
268
+ Edit
269
+ try:
270
+ response = openai_client.chat.completions.create(
271
+ model="gpt-4-turbo",
272
+ messages=[
273
+ {
274
+ "role": "system",
275
+ "content": (
276
+ "You are an enterprise solutions architect. Create professional-grade code labs with: "
277
+ "1) Production-ready patterns 2) Comprehensive documentation "
278
+ "3) Enterprise security practices 4) Scalable architectures. "
279
+ "Use Python with the latest best practices."
280
+ )
281
+ },
282
+ {
283
+ "role": "user",
284
+ "content": (
285
+ f"Create a professional code lab for: {json.dumps(content)}. "
286
+ "Include: Setup instructions, business solution patterns, "
287
+ "enterprise integration examples, and security best practices."
288
+ )
289
+ }
290
+ ],
291
+ temperature=0.3,
292
+ max_tokens=2500
293
+ )
294
+ return response.choices[0].message.content
295
+ except Exception:
296
+ return self._professional_code(content)
297
 
298
+ def _professional_code(self, content):
299
+ return f"""# Enterprise-Grade Prompt Engineering Lab
300
  Business Solution Framework
301
  python
302
  class PromptOptimizer:
303
+ def init(self, model="gpt-4-turbo"):
304
+ self.model = model
305
+ self.pattern_library = {{
306
+ "financial_analysis": "Extract key metrics from financial reports",
307
+ "customer_service": "Resolve tier-2 support tickets"
308
+ }}
309
+
310
+ ruby
311
+ Copy
312
+ Edit
313
+ def optimize_prompt(self, business_case):
314
+ # Implement enterprise optimization logic
315
+ return f"Business-optimized prompt for {{business_case}}"
316
+
317
+ def calculate_roi(self, current_cost, expected_efficiency):
318
+ return current_cost * expected_efficiency
319
+ Example usage
320
  optimizer = PromptOptimizer()
321
+ print(optimizer.calculate_roi(500000, 0.35)) # $175,000 savings
322
 
323
  Security Best Practices
324
  python
325
  def secure_prompt_handling(user_input):
326
+ # Implement OWASP security standards
327
+ sanitized = sanitize_input(user_input)
328
+ validate_business_context(sanitized)
329
+ return apply_enterprise_guardrails(sanitized)
330
 
331
  Integration Pattern: CRM System
332
  python
333
  def integrate_with_salesforce(prompt, salesforce_data):
334
+ # Enterprise integration example
335
+ enriched_prompt = f"{{prompt}} using {{salesforce_data}}"
336
+ return call_ai_api(enriched_prompt)
337
  """
338
 
339
  class DesignAgent:
340
+ def generate_design(self, slide_content):
341
+ if not openai_client:
342
+ return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
 
344
+ kotlin
345
+ Copy
346
+ Edit
347
+ try:
348
+ response = openai_client.images.generate(
349
+ model="dall-e-3",
350
+ prompt=(
351
+ f"Professional corporate slide background for '{slide_content[:200]}' workshop. "
352
+ "Modern business style, clean lines, premium gradient, boardroom appropriate. "
353
+ "Include abstract technology elements in corporate colors."
354
+ ),
355
+ n=1,
356
+ size="1024x1024"
357
+ )
358
+ return response.data[0].url
359
+ except Exception:
360
+ return None
361
  class VoiceoverAgent:
362
+ def init(self):
363
+ self.api_key = ELEVENLABS_API_KEY
364
+ self.voice_id = "21m00Tcm4TlvDq8ikWAM" # Default voice ID
365
+ self.model = "eleven_monolingual_v1"
366
+
367
+ python
368
+ Copy
369
+ Edit
370
+ def generate_voiceover(self, text, voice_id=None):
371
+ if not self.api_key:
372
+ return None
373
+
374
+ try:
375
+ voice = voice_id if voice_id else self.voice_id
376
+
377
+ url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice}"
378
+ headers = {
379
+ "Accept": "audio/mpeg",
380
+ "Content-Type": "application/json",
381
+ "xi-api-key": self.api_key
382
+ }
383
+ data = {
384
+ "text": text,
385
+ "model_id": self.model,
386
+ "voice_settings": {
387
+ "stability": 0.7,
388
+ "similarity_boost": 0.8,
389
+ "style": 0.5,
390
+ "use_speaker_boost": True
391
  }
392
+ }
393
+ response = requests.post(url, json=data, headers=headers)
394
+
395
+ if response.status_code == 200:
396
+ return response.content
397
+ return None
398
+ except Exception:
399
+ return None
400
+
401
+ def get_voices(self):
402
+ if not self.api_key:
403
+ return []
404
+
405
+ try:
406
+ url = "https://api.elevenlabs.io/v1/voices"
407
+ headers = {"xi-api-key": self.api_key}
408
+ response = requests.get(url, headers=headers)
409
+
410
+ if response.status_code == 200:
411
+ return response.json().get("voices", [])
412
+ return []
413
+ except Exception:
414
+ return []