cv / groq_api.py
saherPervaiz's picture
Update groq_api.py
fb85604 verified
raw
history blame
1.52 kB
# 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:
# Safeguard input
job_description = job_description.strip() or "[No description]"
cv_info = "\n\n".join([
f"{cv_names[i]}:\n{cv_snippets[i].strip() 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 relevant for the job.
"""
print("=== Prompt Sent to Groq ===")
print(prompt[:1500]) # show only first 1500 chars
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 Exception as e:
return f"❌ Groq API error: {e}"