Spaces:
Sleeping
Sleeping
Update groq_api.py
Browse files- groq_api.py +15 -16
groq_api.py
CHANGED
|
@@ -10,38 +10,37 @@ def summarize_match(job_description, cv_names, cv_snippets):
|
|
| 10 |
return "β GROQ_API_KEY not set."
|
| 11 |
|
| 12 |
try:
|
| 13 |
-
#
|
| 14 |
-
job_description = job_description.strip() or "[No description]"
|
| 15 |
-
cv_names = cv_names[:3]
|
| 16 |
-
cv_snippets = [
|
| 17 |
|
| 18 |
-
|
| 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]
|
| 24 |
for i in range(len(cv_names))
|
| 25 |
])
|
| 26 |
|
| 27 |
prompt = f"""
|
| 28 |
You are an AI recruiter assistant.
|
| 29 |
|
| 30 |
-
|
| 31 |
---
|
| 32 |
{job_description}
|
| 33 |
---
|
| 34 |
|
| 35 |
-
|
| 36 |
{cv_info}
|
| 37 |
|
| 38 |
-
|
| 39 |
""".strip()
|
| 40 |
|
| 41 |
-
|
| 42 |
-
print("π¦ Prompt
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
#
|
| 45 |
response = requests.post(
|
| 46 |
url="https://api.groq.com/openai/v1/chat/completions",
|
| 47 |
headers={
|
|
@@ -59,5 +58,5 @@ Please summarize why these candidates are a good fit for the job.
|
|
| 59 |
response.raise_for_status()
|
| 60 |
return response.json()["choices"][0]["message"]["content"]
|
| 61 |
|
| 62 |
-
except
|
| 63 |
return f"β Groq API error: {e}"
|
|
|
|
| 10 |
return "β GROQ_API_KEY not set."
|
| 11 |
|
| 12 |
try:
|
| 13 |
+
# Clean + limit all text
|
| 14 |
+
job_description = job_description.strip()[:600] or "[No description]"
|
| 15 |
+
cv_names = [name[:60] for name in cv_names[:3]]
|
| 16 |
+
cv_snippets = [(text.strip()[:400] or "[No content]") for text in cv_snippets[:3]]
|
| 17 |
|
| 18 |
+
# Assemble cleaned prompt
|
|
|
|
|
|
|
|
|
|
| 19 |
cv_info = "\n\n".join([
|
| 20 |
+
f"{cv_names[i]}:\n{cv_snippets[i]}"
|
| 21 |
for i in range(len(cv_names))
|
| 22 |
])
|
| 23 |
|
| 24 |
prompt = f"""
|
| 25 |
You are an AI recruiter assistant.
|
| 26 |
|
| 27 |
+
Here is the job description:
|
| 28 |
---
|
| 29 |
{job_description}
|
| 30 |
---
|
| 31 |
|
| 32 |
+
Top 3 CV snippets:
|
| 33 |
{cv_info}
|
| 34 |
|
| 35 |
+
Summarize why these candidates may be a good fit.
|
| 36 |
""".strip()
|
| 37 |
|
| 38 |
+
# Show debugging info
|
| 39 |
+
print("π¦ Prompt length:", len(prompt))
|
| 40 |
+
if len(prompt) > 8000:
|
| 41 |
+
return "β Prompt too long for Groq (must be under 8K characters)."
|
| 42 |
|
| 43 |
+
# Send to Groq API
|
| 44 |
response = requests.post(
|
| 45 |
url="https://api.groq.com/openai/v1/chat/completions",
|
| 46 |
headers={
|
|
|
|
| 58 |
response.raise_for_status()
|
| 59 |
return response.json()["choices"][0]["message"]["content"]
|
| 60 |
|
| 61 |
+
except Exception as e:
|
| 62 |
return f"β Groq API error: {e}"
|