File size: 2,559 Bytes
9089c56
84bc138
d31a363
84bc138
bf1ae63
84bc138
7e2083c
d31a363
5c62f99
84bc138
fb85604
9089c56
 
e791f2f
9089c56
 
 
 
 
 
 
 
fb85604
 
8fa1c54
 
9089c56
8fa1c54
 
84bc138
5c62f99
100dadd
84bc138
9089c56
84bc138
8fa1c54
 
 
 
 
0ac4fb8
9089c56
8421e19
84bc138
9089c56
57374a9
e791f2f
fb85604
d31a363
 
 
 
 
 
 
0ac4fb8
 
 
 
 
5c62f99
d31a363
 
 
100dadd
d31a363
 
 
e791f2f
5c62f99
e791f2f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# groq_api.py
import os
import requests

GROQ_API_KEY = "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"

def summarize_match(job_description, cv_names, cv_snippets):
    if not GROQ_API_KEY:
        return "❌ GROQ_API_KEY not set."

    try:
        # Truncate job description
        job_description = job_description.strip()[:800] or "[No description provided]"

        # Apply safe truncation (summary) to each CV
        summarized_snippets = [(cv.strip()[:700] or "[No content]") for cv in cv_snippets]
        cv_names = [name[:60] for name in cv_names]

        # Build dynamic CV section
        cv_section = ""
        for i, (name, snippet) in enumerate(zip(cv_names, summarized_snippets), start=1):
            cv_section += f"\n{i}. {name}:\n{snippet}\n"

        prompt = f"""
You are an AI recruitment assistant helping to evaluate candidates for an open job role.

Below is the job description, followed by candidate CV summaries.

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.

### Job Description:
{job_description}

### Candidate CVs:{cv_section}

### Instructions:
- Focus on **specific skills**, **technical tools**, **relevant experience**, and **industry fit**.
- Clearly identify **who is a good match**, and **why**.
- Clearly explain **who is not a match**, and **why not**.
- Avoid general language like "strong background" unless it's backed by actual experience.

End with a short ranked list of the candidates.
""".strip()

        # Truncate if too long
        if len(prompt) > 8000:
            prompt = prompt[:8000]

        response = requests.post(
            url="https://api.groq.com/openai/v1/chat/completions",
            headers={
                "Authorization": f"Bearer {GROQ_API_KEY}",
                "Content-Type": "application/json"
            },
            json={
                "model": "llama3-8b-8192",
                "messages": [
                    {"role": "system", "content": "You are a helpful recruitment assistant."},
                    {"role": "user", "content": prompt}
                ],
                "temperature": 0.4
            },
            timeout=30
        )

        response.raise_for_status()
        return response.json()["choices"][0]["message"]["content"]

    except requests.exceptions.RequestException as e:
        return f"❌ Groq API error: {e}"
    except Exception as e:
        return f"❌ Unexpected error: {e}"