saherPervaiz commited on
Commit
57374a9
Β·
verified Β·
1 Parent(s): 8421e19

Update groq_api.py

Browse files
Files changed (1) hide show
  1. groq_api.py +15 -16
groq_api.py CHANGED
@@ -10,38 +10,37 @@ def summarize_match(job_description, cv_names, cv_snippets):
10
  return "❌ GROQ_API_KEY not set."
11
 
12
  try:
13
- # Safety checks
14
- job_description = job_description.strip() or "[No description]"
15
- cv_names = cv_names[:3]
16
- cv_snippets = [s[:400] for s in cv_snippets[:3]] # shorten per snippet
17
 
18
- if not cv_snippets or not any(cv_snippets):
19
- return "❌ No valid CV content to summarize."
20
-
21
- # Format prompt
22
  cv_info = "\n\n".join([
23
- f"{cv_names[i]}:\n{cv_snippets[i] or '[No content]'}"
24
  for i in range(len(cv_names))
25
  ])
26
 
27
  prompt = f"""
28
  You are an AI recruiter assistant.
29
 
30
- A company has the following job description:
31
  ---
32
  {job_description}
33
  ---
34
 
35
- Here are the top 3 candidate CVs (partial content):
36
  {cv_info}
37
 
38
- Please summarize why these candidates are a good fit for the job.
39
  """.strip()
40
 
41
- print("πŸ“¦ Prompt size (chars):", len(prompt))
42
- print("πŸ“¦ Prompt preview:\n", prompt[:800]) # trim to preview
 
 
43
 
44
- # Call Groq
45
  response = requests.post(
46
  url="https://api.groq.com/openai/v1/chat/completions",
47
  headers={
@@ -59,5 +58,5 @@ Please summarize why these candidates are a good fit for the job.
59
  response.raise_for_status()
60
  return response.json()["choices"][0]["message"]["content"]
61
 
62
- except requests.exceptions.RequestException as e:
63
  return f"❌ Groq API error: {e}"
 
10
  return "❌ GROQ_API_KEY not set."
11
 
12
  try:
13
+ # Clean + limit all text
14
+ job_description = job_description.strip()[:600] or "[No description]"
15
+ cv_names = [name[:60] for name in cv_names[:3]]
16
+ cv_snippets = [(text.strip()[:400] or "[No content]") for text in cv_snippets[:3]]
17
 
18
+ # Assemble cleaned prompt
 
 
 
19
  cv_info = "\n\n".join([
20
+ f"{cv_names[i]}:\n{cv_snippets[i]}"
21
  for i in range(len(cv_names))
22
  ])
23
 
24
  prompt = f"""
25
  You are an AI recruiter assistant.
26
 
27
+ Here is the job description:
28
  ---
29
  {job_description}
30
  ---
31
 
32
+ Top 3 CV snippets:
33
  {cv_info}
34
 
35
+ Summarize why these candidates may be a good fit.
36
  """.strip()
37
 
38
+ # Show debugging info
39
+ print("πŸ“¦ Prompt length:", len(prompt))
40
+ if len(prompt) > 8000:
41
+ return "❌ Prompt too long for Groq (must be under 8K characters)."
42
 
43
+ # Send to Groq API
44
  response = requests.post(
45
  url="https://api.groq.com/openai/v1/chat/completions",
46
  headers={
 
58
  response.raise_for_status()
59
  return response.json()["choices"][0]["message"]["content"]
60
 
61
+ except Exception as e:
62
  return f"❌ Groq API error: {e}"