siddhartharya commited on
Commit
b682b3b
·
verified ·
1 Parent(s): 0d0ea47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -67,10 +67,15 @@ class AutonomousEmailAgent:
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."
 
67
 
68
  print(f"Status Code: {response.status_code}")
69
  if response.status_code == 200:
70
+ try:
71
+ result = response.json() # Parse the response as JSON
72
+ # Check if 'choices' and the content are correctly structured in the response
73
+ content = "".join([chunk.get("choices", [{}])[0].get("message", {}).get("content", "") for chunk in result.get("choices", [])])
74
+ print(content)
75
+ return self.act_on_llm_instructions(content)
76
+ except json.JSONDecodeError:
77
+ print("Error: Response from Groq Cloud LLM is not valid JSON.")
78
+ return "Error: Response is not in JSON format."
79
  else:
80
  print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}, Response: {response.text}")
81
  return "Error: Unable to generate response."