siddhartharya commited on
Commit
3be9484
1 Parent(s): c0d54a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -20,23 +20,31 @@ def fetch_public_data(name, dob, city):
20
 
21
  # Helper function to call Groq Cloud LLM API to generate email
22
  def generate_email_from_groq(bio, company_name, role):
23
- url = "https://api.groq.cloud/generate" # Replace with the correct Groq Cloud API URL
24
  headers = {
25
  "Authorization": f"Bearer {groq_api_key}", # Use the API key securely from environment
26
  "Content-Type": "application/json",
27
  }
 
 
28
  prompt = f"Write a professional email applying for a {role} position at {company_name}. Use this bio: {bio}. The email should include an introduction, relevant experience, skills, and a closing."
29
 
 
30
  data = {
31
- "model": "groq-model", # Adjust model name based on Groq documentation
32
- "prompt": prompt,
33
- "max_tokens": 300
 
 
 
 
34
  }
35
 
36
  response = requests.post(url, headers=headers, json=data)
37
 
38
  if response.status_code == 200:
39
- return response.json().get("choices")[0].get("text").strip()
 
40
  else:
41
  # Print or log the error for debugging
42
  print(f"Error: {response.status_code}, {response.text}")
 
20
 
21
  # Helper function to call Groq Cloud LLM API to generate email
22
  def generate_email_from_groq(bio, company_name, role):
23
+ url = "https://api.groq.com/openai/v1/chat/completions" # Updated API URL for Groq Cloud
24
  headers = {
25
  "Authorization": f"Bearer {groq_api_key}", # Use the API key securely from environment
26
  "Content-Type": "application/json",
27
  }
28
+
29
+ # Updated prompt for Groq Cloud chat completion
30
  prompt = f"Write a professional email applying for a {role} position at {company_name}. Use this bio: {bio}. The email should include an introduction, relevant experience, skills, and a closing."
31
 
32
+ # Construct the data payload for the API request
33
  data = {
34
+ "messages": [
35
+ {
36
+ "role": "user",
37
+ "content": prompt
38
+ }
39
+ ],
40
+ "model": "llama3-8b-8192" # Use the appropriate model from Groq Cloud
41
  }
42
 
43
  response = requests.post(url, headers=headers, json=data)
44
 
45
  if response.status_code == 200:
46
+ # Extract the generated email content from the API response
47
+ return response.json()["choices"][0]["message"]["content"].strip()
48
  else:
49
  # Print or log the error for debugging
50
  print(f"Error: {response.status_code}, {response.text}")