Spaces:
Sleeping
Sleeping
File size: 1,840 Bytes
84bc138 d31a363 84bc138 d31a363 84bc138 8421e19 84bc138 7e2083c d31a363 100dadd 84bc138 fb85604 8421e19 fb85604 8421e19 fb85604 8421e19 fb85604 100dadd 84bc138 100dadd 84bc138 fb85604 7e2083c 84bc138 8421e19 84bc138 8421e19 fb85604 8421e19 d31a363 100dadd d31a363 100dadd d31a363 8421e19 100dadd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# groq_api.py
import os
import requests
GROQ_API_KEY = "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"
def summarize_match(job_description, cv_names, cv_snippets):
if not GROQ_API_KEY:
return "β GROQ_API_KEY not set."
try:
# Safety checks
job_description = job_description.strip() or "[No description]"
cv_names = cv_names[:3]
cv_snippets = [s[:400] for s in cv_snippets[:3]] # shorten per snippet
if not cv_snippets or not any(cv_snippets):
return "β No valid CV content to summarize."
# Format prompt
cv_info = "\n\n".join([
f"{cv_names[i]}:\n{cv_snippets[i] or '[No content]'}"
for i in range(len(cv_names))
])
prompt = f"""
You are an AI recruiter assistant.
A company has the following job description:
---
{job_description}
---
Here are the top 3 candidate CVs (partial content):
{cv_info}
Please summarize why these candidates are a good fit for the job.
""".strip()
print("π¦ Prompt size (chars):", len(prompt))
print("π¦ Prompt preview:\n", prompt[:800]) # trim to preview
# Call Groq
response = requests.post(
url="https://api.groq.com/openai/v1/chat/completions",
headers={
"Authorization": f"Bearer {GROQ_API_KEY}",
"Content-Type": "application/json"
},
json={
"model": "mixtral-8x7b-32768",
"messages": [{"role": "user", "content": prompt}],
"temperature": 0.5
},
timeout=30
)
response.raise_for_status()
return response.json()["choices"][0]["message"]["content"]
except requests.exceptions.RequestException as e:
return f"β Groq API error: {e}"
|