saherPervaiz commited on
Commit
d31a363
·
verified ·
1 Parent(s): 2d589f0

Update groq_api.py

Browse files
Files changed (1) hide show
  1. groq_api.py +31 -19
groq_api.py CHANGED
@@ -1,30 +1,42 @@
1
  # groq_api.py
 
2
  import os
3
- import openai
4
 
5
- # Set your Groq API key
6
- openai.api_key = "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"
7
- openai.api_base = "https://api.groq.com/openai/v1"
8
 
9
- MODEL_NAME = "mixtral-8x7b-32768" # You can change to another Groq-supported model
 
 
10
 
11
- def get_summary(jd_text, matched_cvs):
12
- joined_cvs = "\n\n".join(matched_cvs)
13
  prompt = f"""
14
- Given the following job description:
15
-
16
- {jd_text}
17
 
18
- And these CVs:
 
19
 
20
- {joined_cvs}
 
21
 
22
- Summarize which candidates best match the job description and why:
23
  """
24
 
25
- response = openai.ChatCompletion.create(
26
- model=MODEL_NAME,
27
- messages=[{"role": "user", "content": prompt}]
28
- )
29
-
30
- return response.choices[0].message.content.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # groq_api.py
2
+
3
  import os
4
+ import requests
5
 
6
+ GROQ_API_KEY = "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"
 
 
7
 
8
+ def summarize_match(jd, top_cv_names):
9
+ if not GROQ_API_KEY:
10
+ return "❌ GROQ_API_KEY not set in environment."
11
 
 
 
12
  prompt = f"""
13
+ You are a helpful assistant. A recruiter wants to know which CVs best match the following job description:
 
 
14
 
15
+ Job Description:
16
+ {jd}
17
 
18
+ Top CVs:
19
+ {', '.join(top_cv_names)}
20
 
21
+ Please summarize which candidates seem most relevant and why.
22
  """
23
 
24
+ try:
25
+ response = requests.post(
26
+ url="https://api.groq.com/openai/v1/chat/completions",
27
+ headers={
28
+ "Authorization": f"Bearer {GROQ_API_KEY}",
29
+ "Content-Type": "application/json"
30
+ },
31
+ json={
32
+ "model": "mixtral-8x7b-32768",
33
+ "messages": [{"role": "user", "content": prompt}],
34
+ "temperature": 0.5,
35
+ },
36
+ timeout=30
37
+ )
38
+ response.raise_for_status()
39
+ return response.json()["choices"][0]["message"]["content"]
40
+
41
+ except Exception as e:
42
+ return f"❌ Groq API Error: {e}"