Update app.py
Browse files
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.
|
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 |
-
"
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
response = requests.post(url, headers=headers, json=data)
|
37 |
|
38 |
if response.status_code == 200:
|
39 |
-
|
|
|
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}")
|