Spaces:
Sleeping
Sleeping
Update groq_api.py
Browse files- groq_api.py +14 -16
groq_api.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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):
|
@@ -12,40 +12,38 @@ def summarize_match(job_description, cv_names, cv_snippets):
|
|
12 |
# Truncate job description
|
13 |
job_description = job_description.strip()[:800] or "[No description provided]"
|
14 |
|
15 |
-
#
|
16 |
-
|
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,
|
22 |
cv_section += f"\n{i}. {name}:\n{snippet}\n"
|
23 |
|
|
|
24 |
prompt = f"""
|
25 |
-
You are an AI recruitment assistant helping to evaluate
|
26 |
|
27 |
-
Below is the job description, followed by candidate CV summaries.
|
28 |
|
29 |
-
Your
|
|
|
|
|
|
|
|
|
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**.
|
38 |
-
- Clearly identify **who is a good match**, and **why**.
|
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 |
-
#
|
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={
|
|
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
|
4 |
+
# Set your Groq API Key
|
5 |
GROQ_API_KEY = "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"
|
6 |
|
7 |
def summarize_match(job_description, cv_names, cv_snippets):
|
|
|
12 |
# Truncate job description
|
13 |
job_description = job_description.strip()[:800] or "[No description provided]"
|
14 |
|
15 |
+
# Truncate each CV snippet
|
16 |
+
cv_snippets = [(text.strip()[:700] or "[No content]") for text 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, cv_snippets), start=1):
|
22 |
cv_section += f"\n{i}. {name}:\n{snippet}\n"
|
23 |
|
24 |
+
# Build prompt
|
25 |
prompt = f"""
|
26 |
+
You are an AI recruitment assistant helping to evaluate candidate CVs for a job opening.
|
27 |
|
28 |
+
Below is the job description, followed by {len(cv_names)} candidate CV summaries.
|
29 |
|
30 |
+
Your job is to:
|
31 |
+
- Analyze each candidate's relevance based on their technical skills, tools, and experience
|
32 |
+
- Be honest: clearly state if a candidate is a good fit or not
|
33 |
+
- Avoid generic praise unless it's supported by actual content
|
34 |
+
{"- Rank the candidates based on fit if more than one is provided." if len(cv_names) > 1 else ""}
|
35 |
|
36 |
### Job Description:
|
37 |
{job_description}
|
38 |
|
39 |
### Candidate CVs:{cv_section}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
""".strip()
|
41 |
|
42 |
+
# Enforce character limit (approx 8000 tokens max for llama3-8b-8192)
|
43 |
if len(prompt) > 8000:
|
44 |
prompt = prompt[:8000]
|
45 |
|
46 |
+
# Call Groq API
|
47 |
response = requests.post(
|
48 |
url="https://api.groq.com/openai/v1/chat/completions",
|
49 |
headers={
|