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

Update groq_api.py

Browse files
Files changed (1) hide show
  1. groq_api.py +16 -8
groq_api.py CHANGED
@@ -3,17 +3,24 @@
3
  import os
4
  import requests
5
 
6
- GROQ_API_KEY ="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"
7
 
8
  def summarize_match(job_description, cv_names, cv_snippets):
9
  if not GROQ_API_KEY:
10
  return "❌ GROQ_API_KEY not set."
11
 
12
  try:
13
- # Safeguard input
14
  job_description = job_description.strip() or "[No description]"
 
 
 
 
 
 
 
15
  cv_info = "\n\n".join([
16
- f"{cv_names[i]}:\n{cv_snippets[i].strip() or '[No content]'}"
17
  for i in range(len(cv_names))
18
  ])
19
 
@@ -28,12 +35,13 @@ A company has the following job description:
28
  Here are the top 3 candidate CVs (partial content):
29
  {cv_info}
30
 
31
- Please summarize why these candidates are relevant for the job.
32
- """
33
 
34
- print("=== Prompt Sent to Groq ===")
35
- print(prompt[:1500]) # show only first 1500 chars
36
 
 
37
  response = requests.post(
38
  url="https://api.groq.com/openai/v1/chat/completions",
39
  headers={
@@ -51,5 +59,5 @@ Please summarize why these candidates are relevant for the job.
51
  response.raise_for_status()
52
  return response.json()["choices"][0]["message"]["content"]
53
 
54
- except Exception as e:
55
  return f"❌ Groq API error: {e}"
 
3
  import os
4
  import requests
5
 
6
+ GROQ_API_KEY = "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"
7
 
8
  def summarize_match(job_description, cv_names, cv_snippets):
9
  if not GROQ_API_KEY:
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
 
 
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
  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}"