Spaces:
Runtime error
Runtime error
Update groq_api.py
Browse files- groq_api.py +18 -13
groq_api.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
GROQ_API_KEY = "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"
|
| 6 |
|
| 7 |
def summarize_match(job_description, cv_names, cv_snippets):
|
|
@@ -9,19 +9,19 @@ def summarize_match(job_description, cv_names, cv_snippets):
|
|
| 9 |
return "❌ GROQ_API_KEY not set."
|
| 10 |
|
| 11 |
try:
|
| 12 |
-
# Ensure
|
| 13 |
while len(cv_names) < 3:
|
| 14 |
cv_names.append("[No CV]")
|
| 15 |
cv_snippets.append("[No content]")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
job_description = job_description.strip()[:1000] or "[No description provided]"
|
| 19 |
cv_names = [name[:60] for name in cv_names[:3]]
|
| 20 |
cv_snippets = [(text.strip()[:1500] or "[No content]") for text in cv_snippets[:3]]
|
| 21 |
|
| 22 |
-
#
|
| 23 |
prompt = f"""
|
| 24 |
-
You are an AI recruitment assistant helping
|
| 25 |
|
| 26 |
### Job Description:
|
| 27 |
{job_description}
|
|
@@ -36,17 +36,19 @@ You are an AI recruitment assistant helping match CVs to job descriptions.
|
|
| 36 |
3. {cv_names[2]}:
|
| 37 |
{cv_snippets[2]}
|
| 38 |
|
| 39 |
-
|
| 40 |
-
- PHP experience
|
| 41 |
-
-
|
| 42 |
-
-
|
|
|
|
|
|
|
| 43 |
""".strip()
|
| 44 |
|
| 45 |
-
#
|
| 46 |
if len(prompt) > 8000:
|
| 47 |
prompt = prompt[:8000]
|
| 48 |
|
| 49 |
-
#
|
| 50 |
response = requests.post(
|
| 51 |
url="https://api.groq.com/openai/v1/chat/completions",
|
| 52 |
headers={
|
|
@@ -54,8 +56,11 @@ Based on the job requirements, analyze each candidate and explain which (if any)
|
|
| 54 |
"Content-Type": "application/json"
|
| 55 |
},
|
| 56 |
json={
|
| 57 |
-
"model": "
|
| 58 |
-
"messages": [
|
|
|
|
|
|
|
|
|
|
| 59 |
"temperature": 0.4
|
| 60 |
},
|
| 61 |
timeout=30
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# Load from environment variable or fallback
|
| 5 |
GROQ_API_KEY = "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"
|
| 6 |
|
| 7 |
def summarize_match(job_description, cv_names, cv_snippets):
|
|
|
|
| 9 |
return "❌ GROQ_API_KEY not set."
|
| 10 |
|
| 11 |
try:
|
| 12 |
+
# Ensure 3 CVs are present (pad if needed)
|
| 13 |
while len(cv_names) < 3:
|
| 14 |
cv_names.append("[No CV]")
|
| 15 |
cv_snippets.append("[No content]")
|
| 16 |
|
| 17 |
+
# Truncate content safely
|
| 18 |
job_description = job_description.strip()[:1000] or "[No description provided]"
|
| 19 |
cv_names = [name[:60] for name in cv_names[:3]]
|
| 20 |
cv_snippets = [(text.strip()[:1500] or "[No content]") for text in cv_snippets[:3]]
|
| 21 |
|
| 22 |
+
# Compose prompt
|
| 23 |
prompt = f"""
|
| 24 |
+
You are an AI recruitment assistant helping to evaluate candidates for a job.
|
| 25 |
|
| 26 |
### Job Description:
|
| 27 |
{job_description}
|
|
|
|
| 36 |
3. {cv_names[2]}:
|
| 37 |
{cv_snippets[2]}
|
| 38 |
|
| 39 |
+
Please analyze how well each candidate matches the job. Focus on:
|
| 40 |
+
- PHP/web development experience
|
| 41 |
+
- Programming and software skills
|
| 42 |
+
- Relevant technical background
|
| 43 |
+
|
| 44 |
+
List the best matches and briefly justify each recommendation.
|
| 45 |
""".strip()
|
| 46 |
|
| 47 |
+
# Truncate to fit Groq token window if needed
|
| 48 |
if len(prompt) > 8000:
|
| 49 |
prompt = prompt[:8000]
|
| 50 |
|
| 51 |
+
# Send request to Groq API using LLaMA3
|
| 52 |
response = requests.post(
|
| 53 |
url="https://api.groq.com/openai/v1/chat/completions",
|
| 54 |
headers={
|
|
|
|
| 56 |
"Content-Type": "application/json"
|
| 57 |
},
|
| 58 |
json={
|
| 59 |
+
"model": "llama3-8b-8192",
|
| 60 |
+
"messages": [
|
| 61 |
+
{"role": "system", "content": "You are a helpful recruitment assistant."},
|
| 62 |
+
{"role": "user", "content": prompt}
|
| 63 |
+
],
|
| 64 |
"temperature": 0.4
|
| 65 |
},
|
| 66 |
timeout=30
|