Spaces:
Sleeping
Sleeping
Update groq_api.py
Browse files- groq_api.py +15 -26
groq_api.py
CHANGED
@@ -1,7 +1,7 @@
|
|
|
|
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,36 +9,29 @@ def summarize_match(job_description, cv_names, cv_snippets):
|
|
9 |
return "❌ GROQ_API_KEY not set."
|
10 |
|
11 |
try:
|
12 |
-
#
|
13 |
-
|
14 |
-
cv_names.append("[No CV]")
|
15 |
-
cv_snippets.append("[No content]")
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
cv_names = [name[:60] for name in cv_names
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
# Compose prompt
|
23 |
prompt = f"""
|
24 |
You are an AI recruitment assistant helping to evaluate candidates for an open job role.
|
25 |
|
26 |
-
Below is the job description, followed by
|
27 |
|
28 |
Your task is to assess how well each candidate aligns with the job. Be honest — if a candidate lacks the required skills or experience, clearly say they are not a good fit.
|
29 |
|
30 |
### Job Description:
|
31 |
{job_description}
|
32 |
|
33 |
-
### Candidate CVs:
|
34 |
-
1. {cv_names[0]}:
|
35 |
-
{cv_snippets[0]}
|
36 |
-
|
37 |
-
2. {cv_names[1]}:
|
38 |
-
{cv_snippets[1]}
|
39 |
-
|
40 |
-
3. {cv_names[2]}:
|
41 |
-
{cv_snippets[2]}
|
42 |
|
43 |
### Instructions:
|
44 |
- Focus on **specific skills**, **technical tools**, **relevant experience**, and **industry fit**.
|
@@ -46,17 +39,13 @@ Your task is to assess how well each candidate aligns with the job. Be honest
|
|
46 |
- Clearly explain **who is not a match**, and **why not**.
|
47 |
- Avoid general language like "strong background" unless it's backed by actual experience.
|
48 |
|
49 |
-
End with a short ranked list
|
50 |
-
1. Candidate 2 – Strong Python and ML background
|
51 |
-
2. Candidate 1 – Partial match, good general programming skills
|
52 |
-
3. Candidate 3 – Not relevant to the job
|
53 |
""".strip()
|
54 |
|
55 |
-
# Truncate if
|
56 |
if len(prompt) > 8000:
|
57 |
prompt = prompt[:8000]
|
58 |
|
59 |
-
# Send request to Groq API using LLaMA3
|
60 |
response = requests.post(
|
61 |
url="https://api.groq.com/openai/v1/chat/completions",
|
62 |
headers={
|
|
|
1 |
+
# groq_api.py
|
2 |
import os
|
3 |
import requests
|
4 |
|
|
|
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 |
+
# Truncate job description
|
13 |
+
job_description = job_description.strip()[:800] or "[No description provided]"
|
|
|
|
|
14 |
|
15 |
+
# Apply safe truncation (summary) to each CV
|
16 |
+
summarized_snippets = [(cv.strip()[:700] or "[No content]") for cv in cv_snippets]
|
17 |
+
cv_names = [name[:60] for name in cv_names]
|
18 |
+
|
19 |
+
# Build dynamic CV section
|
20 |
+
cv_section = ""
|
21 |
+
for i, (name, snippet) in enumerate(zip(cv_names, summarized_snippets), start=1):
|
22 |
+
cv_section += f"\n{i}. {name}:\n{snippet}\n"
|
23 |
|
|
|
24 |
prompt = f"""
|
25 |
You are an AI recruitment assistant helping to evaluate candidates for an open job role.
|
26 |
|
27 |
+
Below is the job description, followed by candidate CV summaries.
|
28 |
|
29 |
Your task is to assess how well each candidate aligns with the job. Be honest — if a candidate lacks the required skills or experience, clearly say they are not a good fit.
|
30 |
|
31 |
### Job Description:
|
32 |
{job_description}
|
33 |
|
34 |
+
### Candidate CVs:{cv_section}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
### Instructions:
|
37 |
- Focus on **specific skills**, **technical tools**, **relevant experience**, and **industry fit**.
|
|
|
39 |
- Clearly explain **who is not a match**, and **why not**.
|
40 |
- Avoid general language like "strong background" unless it's backed by actual experience.
|
41 |
|
42 |
+
End with a short ranked list of the candidates.
|
|
|
|
|
|
|
43 |
""".strip()
|
44 |
|
45 |
+
# Truncate if too long
|
46 |
if len(prompt) > 8000:
|
47 |
prompt = prompt[:8000]
|
48 |
|
|
|
49 |
response = requests.post(
|
50 |
url="https://api.groq.com/openai/v1/chat/completions",
|
51 |
headers={
|