Spaces:
Sleeping
Sleeping
Update groq_api.py
Browse files- groq_api.py +31 -19
groq_api.py
CHANGED
@@ -1,30 +1,42 @@
|
|
1 |
# groq_api.py
|
|
|
2 |
import os
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
openai.api_key = "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"
|
7 |
-
openai.api_base = "https://api.groq.com/openai/v1"
|
8 |
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
def get_summary(jd_text, matched_cvs):
|
12 |
-
joined_cvs = "\n\n".join(matched_cvs)
|
13 |
prompt = f"""
|
14 |
-
|
15 |
-
|
16 |
-
{jd_text}
|
17 |
|
18 |
-
|
|
|
19 |
|
20 |
-
|
|
|
21 |
|
22 |
-
|
23 |
"""
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# groq_api.py
|
2 |
+
|
3 |
import os
|
4 |
+
import requests
|
5 |
|
6 |
+
GROQ_API_KEY = "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"
|
|
|
|
|
7 |
|
8 |
+
def summarize_match(jd, top_cv_names):
|
9 |
+
if not GROQ_API_KEY:
|
10 |
+
return "❌ GROQ_API_KEY not set in environment."
|
11 |
|
|
|
|
|
12 |
prompt = f"""
|
13 |
+
You are a helpful assistant. A recruiter wants to know which CVs best match the following job description:
|
|
|
|
|
14 |
|
15 |
+
Job Description:
|
16 |
+
{jd}
|
17 |
|
18 |
+
Top CVs:
|
19 |
+
{', '.join(top_cv_names)}
|
20 |
|
21 |
+
Please summarize which candidates seem most relevant and why.
|
22 |
"""
|
23 |
|
24 |
+
try:
|
25 |
+
response = requests.post(
|
26 |
+
url="https://api.groq.com/openai/v1/chat/completions",
|
27 |
+
headers={
|
28 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
29 |
+
"Content-Type": "application/json"
|
30 |
+
},
|
31 |
+
json={
|
32 |
+
"model": "mixtral-8x7b-32768",
|
33 |
+
"messages": [{"role": "user", "content": prompt}],
|
34 |
+
"temperature": 0.5,
|
35 |
+
},
|
36 |
+
timeout=30
|
37 |
+
)
|
38 |
+
response.raise_for_status()
|
39 |
+
return response.json()["choices"][0]["message"]["content"]
|
40 |
+
|
41 |
+
except Exception as e:
|
42 |
+
return f"❌ Groq API Error: {e}"
|