-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_utils.py
More file actions
260 lines (204 loc) · 7.67 KB
/
agent_utils.py
File metadata and controls
260 lines (204 loc) · 7.67 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
"""
Agent utility functions and helpers for Job Application Assistant
"""
from typing import Dict, Any
def format_profile_summary(parsed_profile: dict) -> str:
"""
Generate a human-readable summary of the parsed profile.
Args:
parsed_profile (dict): Structured profile data
Returns:
str: Summary text
"""
personal = parsed_profile.get('personal_info', {})
education = parsed_profile.get('education', [])
experience = parsed_profile.get('experience', [])
summary = f"""
Profile Summary:
================
Name: {personal.get('full_name', 'N/A')}
Email: {personal.get('email', 'N/A')}
Phone: {personal.get('phone', 'N/A')}
Education: {len(education)} entries
Experience: {len(experience)} entries
Projects: {len(parsed_profile.get('projects', []))} entries
Certifications: {len(parsed_profile.get('certifications', []))} entries
"""
return summary
def format_job_summary(parsed_job: dict) -> str:
"""
Generate a human-readable summary of the parsed job posting.
Args:
parsed_job (dict): Structured job data
Returns:
str: Summary text
"""
company = parsed_job.get('company', {})
exp_req = parsed_job.get('experience_required', {})
req_skills = parsed_job.get('required_skills', {})
summary = f"""
Job Posting Summary:
====================
Title: {parsed_job.get('job_title', 'N/A')}
Company: {company.get('name', 'N/A')}
Location: {company.get('location', 'N/A')}
Sector: {parsed_job.get('sector', 'N/A')}
Experience: {exp_req.get('description', 'N/A')}
Required Technical Skills: {', '.join(req_skills.get('technical', [])[:5])}
Required Soft Skills: {', '.join(req_skills.get('soft_skills', [])[:5])}
Total Responsibilities: {len(parsed_job.get('responsibilities', []))}
"""
return summary
def get_sector_tone(sector: str) -> tuple[str, str]:
"""
Determine appropriate tone and salutation based on job sector.
Args:
sector (str): Job sector
Returns:
tuple[str, str]: Tone description and salutation guide
"""
sector_lower = sector.lower()
if sector_lower in ['government', 'govt', 'public sector']:
return (
"formal and respectful",
"Use 'Respected Sir/Madam' or similar formal salutation"
)
elif sector_lower in ['banking', 'finance']:
return (
"professional and formal",
"Use 'Dear Hiring Manager' or 'Dear Sir/Madam'"
)
else:
return (
"professional yet personable",
"Use 'Dear Hiring Manager' or 'Dear Hiring Team'"
)
def extract_matching_skills(
user_skills: list,
required_skills: list,
preferred_skills: list = None
) -> Dict[str, list]:
"""
Extract skills that match job requirements.
Args:
user_skills (list): User's skills
required_skills (list): Job's required skills
preferred_skills (list): Job's preferred skills
Returns:
Dict[str, list]: Matched required and preferred skills
"""
if preferred_skills is None:
preferred_skills = []
# Normalize skills for comparison
user_skills_lower = [skill.lower() for skill in user_skills]
required_lower = [skill.lower() for skill in required_skills]
preferred_lower = [skill.lower() for skill in preferred_skills]
matched_required = [
skill for skill in user_skills
if skill.lower() in required_lower
]
matched_preferred = [
skill for skill in user_skills
if skill.lower() in preferred_lower
]
return {
"matched_required": matched_required,
"matched_preferred": matched_preferred,
"match_percentage": (
len(matched_required) / len(required_skills) * 100
if required_skills else 0
)
}
def build_profile_context(user_profile: dict) -> str:
"""
Build formatted context string from user profile.
Args:
user_profile (dict): Parsed user profile data
Returns:
str: Formatted profile context
"""
personal = user_profile.get('personal_info', {})
education = user_profile.get('education', [])
experience = user_profile.get('experience', [])
tech_skills = user_profile.get('technical_skills', {})
soft_skills = user_profile.get('soft_skills', [])
projects = user_profile.get('projects', [])
certifications = user_profile.get('certifications', [])
achievements = user_profile.get('achievements', [])
additional = user_profile.get('additional_info', {})
context = f"""
Personal Information:
- Name: {personal.get('full_name', 'N/A')}
- Phone: {personal.get('phone', 'N/A')}
- Email: {personal.get('email', 'N/A')}
- LinkedIn: {personal.get('linkedin', 'N/A')}
- GitHub: {personal.get('github', 'N/A')}
- Location: {personal.get('location', 'N/A')}
Education:
{chr(10).join([f"- {edu.get('degree', '')} from {edu.get('institution', '')}, {edu.get('year', '')} (Result: {edu.get('result', '')})" for edu in education])}
Experience:
{chr(10).join([f"- {exp.get('title', '')} at {exp.get('company', '')} ({exp.get('duration', '')})" for exp in experience]) if experience else "- Fresh graduate with no professional experience"}
Technical Skills:
- Programming Languages: {', '.join(tech_skills.get('programming_languages', []))}
- Web Technologies: {', '.join(tech_skills.get('web_technologies', []))}
- Databases: {', '.join(tech_skills.get('databases', []))}
- Tools & Frameworks: {', '.join(tech_skills.get('tools_frameworks', []))}
Soft Skills: {', '.join(soft_skills)}
Projects:
{chr(10).join([f"- {proj.get('name', '')}: {proj.get('description', '')}" for proj in projects])}
Certifications:
{chr(10).join([f"- {cert.get('name', '')} by {cert.get('organization', '')}" for cert in certifications])}
Achievements:
{chr(10).join([f"- {achievement}" for achievement in achievements])}
Career Objective: {additional.get('career_objective', '')}
"""
return context
def build_job_context(job_posting: dict) -> str:
"""
Build formatted context string from job posting.
Args:
job_posting (dict): Parsed job posting data
Returns:
str: Formatted job context
"""
company = job_posting.get('company', {})
required_skills = job_posting.get('required_skills', {})
preferred_skills = job_posting.get('preferred_skills', {})
responsibilities = job_posting.get('responsibilities', [])
context = f"""
Position: {job_posting.get('job_title', '')}
Company: {company.get('name', 'N/A')}
Location: {company.get('location', 'N/A')}
Sector: {job_posting.get('sector', '')}
Required Technical Skills: {', '.join(required_skills.get('technical', []))}
Required Soft Skills: {', '.join(required_skills.get('soft_skills', []))}
Preferred Technical Skills: {', '.join(preferred_skills.get('technical', []))}
Preferred Soft Skills: {', '.join(preferred_skills.get('soft_skills', []))}
Key Responsibilities:
{chr(10).join([f"- {resp}" for resp in responsibilities[:5]])}
"""
return context
def print_step_header(step_number: int, step_title: str):
"""
Print a formatted step header.
Args:
step_number (int): Step number
step_title (str): Title of the step
"""
print("\n" + "="*70)
print(f"STEP {step_number}: {step_title}")
print("="*70)
def print_success_message(message: str):
"""
Print a formatted success message.
Args:
message (str): Success message
"""
print(f"\n[SUCCESS] {message}")
def print_error_message(message: str):
"""
Print a formatted error message.
Args:
message (str): Error message
"""
print(f"\n[ERROR] {message}")