siddhartharya commited on
Commit
67c2abc
·
verified ·
1 Parent(s): 8d271f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -47,27 +47,32 @@ class AutonomousEmailAgent:
47
 
48
  return self.send_request_to_llm(reasoning_prompt)
49
 
50
- # Send request to Groq Cloud LLM
51
  def send_request_to_llm(self, prompt):
52
  print("Sending request to Groq Cloud LLM...")
53
  api_key = os.getenv("GROQ_API_KEY")
 
 
 
 
54
  headers = {
55
  "Authorization": f"Bearer {api_key}",
56
  "Content-Type": "application/json"
57
  }
58
  data = {
59
- "model": "llama-3.1-70b-versatile", # Updated model name
60
  "messages": [{"role": "user", "content": prompt}]
61
  }
62
  response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=data)
63
 
 
64
  if response.status_code == 200:
65
  result = response.json()
66
  content = "".join([chunk.get("choices", [{}])[0].get("delta", {}).get("content", "") for chunk in result])
67
  print(content)
68
  return self.act_on_llm_instructions(content)
69
  else:
70
- print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}")
71
  return "Error: Unable to generate response."
72
 
73
  # Function to act on the LLM's structured instructions
 
47
 
48
  return self.send_request_to_llm(reasoning_prompt)
49
 
50
+ # Send request to Groq Cloud LLM with enhanced debugging and error handling
51
  def send_request_to_llm(self, prompt):
52
  print("Sending request to Groq Cloud LLM...")
53
  api_key = os.getenv("GROQ_API_KEY")
54
+ if not api_key:
55
+ print("Error: API key not found. Please set the GROQ_API_KEY environment variable.")
56
+ return "Error: API key not found."
57
+
58
  headers = {
59
  "Authorization": f"Bearer {api_key}",
60
  "Content-Type": "application/json"
61
  }
62
  data = {
63
+ "model": "llama-3.1-70b-versatile", # Model name
64
  "messages": [{"role": "user", "content": prompt}]
65
  }
66
  response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=data)
67
 
68
+ print(f"Status Code: {response.status_code}")
69
  if response.status_code == 200:
70
  result = response.json()
71
  content = "".join([chunk.get("choices", [{}])[0].get("delta", {}).get("content", "") for chunk in result])
72
  print(content)
73
  return self.act_on_llm_instructions(content)
74
  else:
75
+ print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}, Response: {response.text}")
76
  return "Error: Unable to generate response."
77
 
78
  # Function to act on the LLM's structured instructions