siddhartharya commited on
Commit
2be8ad6
·
verified ·
1 Parent(s): 37e6cfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -83,9 +83,15 @@ def generate_email_content(api_key, prompt):
83
  max_tokens=1024,
84
  stream=False # Disable streaming for simplicity
85
  )
86
- email_content = response['choices'][0]['message']['content']
87
- logging.info("Email content generated successfully.")
88
- return email_content
 
 
 
 
 
 
89
  except Exception as e:
90
  logging.error(f"Error generating email content: {e}")
91
  return "Error generating email content."
 
83
  max_tokens=1024,
84
  stream=False # Disable streaming for simplicity
85
  )
86
+
87
+ # Access the response content correctly based on the Nvidia API structure
88
+ if hasattr(response, 'choices') and len(response.choices) > 0:
89
+ email_content = response.choices[0].message.content
90
+ logging.info("Email content generated successfully.")
91
+ return email_content
92
+ else:
93
+ logging.error("Error: No choices found in the response.")
94
+ return "Error generating email content: No valid choices."
95
  except Exception as e:
96
  logging.error(f"Error generating email content: {e}")
97
  return "Error generating email content."