setiyanikhil3 commited on
Commit
a274967
·
verified ·
1 Parent(s): 58ac83f

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +11 -1
agent.py CHANGED
@@ -4,6 +4,9 @@ import requests
4
  GROQ_API_URL = "https://api.groqcloud.com/v1/chat/completions"
5
  GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Secure key from Hugging Face Secrets
6
 
 
 
 
7
  # Helper function to load system prompt from txt files
8
  def load_prompt(filename):
9
  with open(f'config/system_prompts/{filename}', 'r') as file:
@@ -20,7 +23,14 @@ def call_groq(system_prompt, user_input):
20
  ]
21
  }
22
  response = requests.post(GROQ_API_URL, json=payload, headers=headers)
23
- return response.json()['choices'][0]['message']['content']
 
 
 
 
 
 
 
24
 
25
  def ad_copy_agent(product, description, audience, tone):
26
  system_prompt = load_prompt("ad_copy_prompt.txt")
 
4
  GROQ_API_URL = "https://api.groqcloud.com/v1/chat/completions"
5
  GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Secure key from Hugging Face Secrets
6
 
7
+ if not GROQ_API_KEY:
8
+ raise ValueError("GROQ_API_KEY is missing! Set it in Hugging Face Secrets.")
9
+
10
  # Helper function to load system prompt from txt files
11
  def load_prompt(filename):
12
  with open(f'config/system_prompts/{filename}', 'r') as file:
 
23
  ]
24
  }
25
  response = requests.post(GROQ_API_URL, json=payload, headers=headers)
26
+ if response.status_code != 200:
27
+ raise Exception(f"Groq API error: {response.status_code} - {response.text}")
28
+
29
+ data = response.json()
30
+ if 'choices' not in data or not data['choices']:
31
+ raise Exception("Groq API returned no choices.")
32
+
33
+ return data['choices'][0]['message']['content']
34
 
35
  def ad_copy_agent(product, description, audience, tone):
36
  system_prompt = load_prompt("ad_copy_prompt.txt")