File size: 3,084 Bytes
fe099da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
from groq import Groq
from dotenv import load_dotenv

load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), ".env"))

client = Groq(api_key=os.getenv("GROQ_API_KEY"))

def extract_jd_keywords(jd_text: str) -> str:
    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[
            {
                "role": "system",
                "content": "You are an ATS expert. Extract required skills, responsibilities, and seniority from job descriptions. Be concise and structured."
            },
            {
                "role": "user",
                "content": f"Extract key skills and requirements from this job description:\n\n{jd_text}"
            }
        ]
    )
    return response.choices[0].message.content


def rewrite_resume_bullets(resume_text: str, jd_keywords: str) -> str:
    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[
            {
                "role": "system",
                "content": """You are an expert resume writer. Rewrite the candidate's actual experience into strong resume bullets that naturally align with the job.

Rules:
- Only use skills and projects the candidate ACTUALLY has in their resume
- Mention their real projects by name where they are relevant
- Sound natural and human — not like a keyword list
- Start every bullet with a strong action verb
- Keep each bullet under 20 words
- Do NOT invent anything not in the resume
- Do NOT just copy job requirements as bullets"""
            },
            {
                "role": "user",
                "content": f"""Candidate resume:
{resume_text}

Job requirements:
{jd_keywords}

Rewrite the candidate's real experience as strong resume bullets that highlight relevant skills and mention actual projects by name."""
            }
        ]
    )
    return response.choices[0].message.content


def generate_cover_letter(resume_text: str, jd_text: str, tone: str) -> str:
    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[
            {
                "role": "system",
                "content": f"""You are an expert cover letter writer. Write in a {tone} tone.

Rules:
- Write exactly 3 paragraphs
- Reference the candidate's REAL projects from their resume by name
- Sound like a real human wrote this — confident and natural
- Never use cliches like 'I hope this finds you well' or 'I am writing to express my interest'
- Paragraph 1: who they are and why they are a strong fit for this specific role
- Paragraph 2: mention 2 specific real projects from their resume that match the job
- Paragraph 3: excitement about the role and a clear next step CTA"""
            },
            {
                "role": "user",
                "content": f"""Candidate resume:
{resume_text}

Job description:
{jd_text}

Write a natural, confident cover letter that references the candidate's real projects by name."""
            }
        ]
    )
    return response.choices[0].message.content