Alpha108 commited on
Commit
9317e1a
·
verified ·
1 Parent(s): e941444

Create resume_gen.py

Browse files
Files changed (1) hide show
  1. backend/agents/resume_gen.py +113 -0
backend/agents/resume_gen.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from groq import Groq
2
+
3
+ def generate_custom_resume(resume_text: str, job_description: str, api_key: str) -> str:
4
+ """
5
+ Generates a tailored resume using a Groq LLM.
6
+
7
+ Args:
8
+ resume_text (str): The user's original resume text.
9
+ job_description (str): The job description to tailor the resume for.
10
+ api_key (str): The Groq API key.
11
+
12
+ Returns:
13
+ str: The content of the tailored resume.
14
+ """
15
+ if not api_key:
16
+ raise ValueError("Groq API key is required.")
17
+
18
+ client = Groq(api_key=api_key)
19
+
20
+ prompt = f"""
21
+ You are an expert resume writer. Your task is to rewrite the following resume to be perfectly tailored for the provided job description.
22
+ Focus on highlighting the most relevant skills and experiences from the original resume that match the job requirements.
23
+ Structure the output cleanly and professionally. Do not invent new experiences.
24
+
25
+ **Original Resume:**
26
+ ---
27
+ {resume_text}
28
+ ---
29
+
30
+ **Job Description:**
31
+ ---
32
+ {job_description}
33
+ ---
34
+
35
+ **Your Task:**
36
+ Rewrite the resume, emphasizing the skills and experiences that align with the job description.
37
+ The output should be the full text of the new, tailored resume.
38
+ """
39
+
40
+ try:
41
+ chat_completion = client.chat.completions.create(
42
+ messages=[
43
+ {
44
+ "role": "system",
45
+ "content": "You are a professional resume writing assistant.",
46
+ },
47
+ {
48
+ "role": "user",
49
+ "content": prompt,
50
+ }
51
+ ],
52
+ model="llama3-8b-8192",
53
+ )
54
+ return chat_completion.choices[0].message.content
55
+ except Exception as e:
56
+ print(f"Error generating custom resume: {e}")
57
+ return "Error: Could not generate tailored resume."
58
+
59
+ def generate_cover_letter(resume_text: str, job_description: str, api_key: str) -> str:
60
+ """
61
+ Generates a compelling cover letter using a Groq LLM.
62
+
63
+ Args:
64
+ resume_text (str): The user's resume text to extract context from.
65
+ job_description (str): The job description for the target role.
66
+ api_key (str): The Groq API key.
67
+
68
+ Returns:
69
+ str: The generated cover letter.
70
+ """
71
+ if not api_key:
72
+ raise ValueError("Groq API key is required.")
73
+
74
+ client = Groq(api_key=api_key)
75
+
76
+ prompt = f"""
77
+ You are an expert career coach. Your task is to write a concise and compelling cover letter for the given job description, based on the provided resume.
78
+ The cover letter should be professional, enthusiastic, and highlight 2-3 key qualifications from the resume that directly match the job's requirements.
79
+ Start with a strong opening, explain the value the candidate brings in the body, and end with a clear call to action.
80
+
81
+ **Candidate's Resume:**
82
+ ---
83
+ {resume_text}
84
+ ---
85
+
86
+ **Target Job Description:**
87
+ ---
88
+ {job_description}
89
+ ---
90
+
91
+ **Your Task:**
92
+ Write a cover letter that is tailored to this specific job. Keep it to about 3-4 paragraphs.
93
+ Address it to "Hiring Manager" if no specific name is available.
94
+ """
95
+
96
+ try:
97
+ chat_completion = client.chat.completions.create(
98
+ messages=[
99
+ {
100
+ "role": "system",
101
+ "content": "You are a professional career coaching assistant.",
102
+ },
103
+ {
104
+ "role": "user",
105
+ "content": prompt,
106
+ }
107
+ ],
108
+ model="llama3-8b-8192",
109
+ )
110
+ return chat_completion.choices[0].message.content
111
+ except Exception as e:
112
+ print(f"Error generating cover letter: {e}")
113
+ return "Error: Could not generate cover letter."