Spaces:
Sleeping
Sleeping
Update groq_api.py
Browse files- groq_api.py +16 -8
groq_api.py
CHANGED
@@ -3,17 +3,24 @@
|
|
3 |
import os
|
4 |
import requests
|
5 |
|
6 |
-
GROQ_API_KEY ="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"
|
7 |
|
8 |
def summarize_match(job_description, cv_names, cv_snippets):
|
9 |
if not GROQ_API_KEY:
|
10 |
return "β GROQ_API_KEY not set."
|
11 |
|
12 |
try:
|
13 |
-
#
|
14 |
job_description = job_description.strip() or "[No description]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
cv_info = "\n\n".join([
|
16 |
-
f"{cv_names[i]}:\n{cv_snippets[i]
|
17 |
for i in range(len(cv_names))
|
18 |
])
|
19 |
|
@@ -28,12 +35,13 @@ A company has the following job description:
|
|
28 |
Here are the top 3 candidate CVs (partial content):
|
29 |
{cv_info}
|
30 |
|
31 |
-
Please summarize why these candidates are
|
32 |
-
"""
|
33 |
|
34 |
-
print("
|
35 |
-
print(prompt[:
|
36 |
|
|
|
37 |
response = requests.post(
|
38 |
url="https://api.groq.com/openai/v1/chat/completions",
|
39 |
headers={
|
@@ -51,5 +59,5 @@ Please summarize why these candidates are relevant for the job.
|
|
51 |
response.raise_for_status()
|
52 |
return response.json()["choices"][0]["message"]["content"]
|
53 |
|
54 |
-
except
|
55 |
return f"β Groq API error: {e}"
|
|
|
3 |
import os
|
4 |
import requests
|
5 |
|
6 |
+
GROQ_API_KEY = "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"
|
7 |
|
8 |
def summarize_match(job_description, cv_names, cv_snippets):
|
9 |
if not GROQ_API_KEY:
|
10 |
return "β GROQ_API_KEY not set."
|
11 |
|
12 |
try:
|
13 |
+
# Safety checks
|
14 |
job_description = job_description.strip() or "[No description]"
|
15 |
+
cv_names = cv_names[:3]
|
16 |
+
cv_snippets = [s[:400] for s in cv_snippets[:3]] # shorten per snippet
|
17 |
+
|
18 |
+
if not cv_snippets or not any(cv_snippets):
|
19 |
+
return "β No valid CV content to summarize."
|
20 |
+
|
21 |
+
# Format prompt
|
22 |
cv_info = "\n\n".join([
|
23 |
+
f"{cv_names[i]}:\n{cv_snippets[i] or '[No content]'}"
|
24 |
for i in range(len(cv_names))
|
25 |
])
|
26 |
|
|
|
35 |
Here are the top 3 candidate CVs (partial content):
|
36 |
{cv_info}
|
37 |
|
38 |
+
Please summarize why these candidates are a good fit for the job.
|
39 |
+
""".strip()
|
40 |
|
41 |
+
print("π¦ Prompt size (chars):", len(prompt))
|
42 |
+
print("π¦ Prompt preview:\n", prompt[:800]) # trim to preview
|
43 |
|
44 |
+
# Call Groq
|
45 |
response = requests.post(
|
46 |
url="https://api.groq.com/openai/v1/chat/completions",
|
47 |
headers={
|
|
|
59 |
response.raise_for_status()
|
60 |
return response.json()["choices"][0]["message"]["content"]
|
61 |
|
62 |
+
except requests.exceptions.RequestException as e:
|
63 |
return f"β Groq API error: {e}"
|