File size: 7,944 Bytes
ff60dd7
 
 
 
b61ec6f
ff60dd7
 
 
 
 
 
74058dd
 
 
 
ff60dd7
 
b61ec6f
 
 
 
 
 
 
 
ff60dd7
b61ec6f
 
 
ff60dd7
 
 
b61ec6f
 
 
 
 
 
 
 
 
ff60dd7
 
b61ec6f
 
ff60dd7
 
 
b61ec6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff60dd7
 
b61ec6f
 
 
 
 
 
ff60dd7
 
 
 
 
 
b61ec6f
 
 
 
 
 
 
 
 
 
 
 
 
 
ff60dd7
 
b61ec6f
 
 
ff60dd7
b61ec6f
ff60dd7
 
 
 
 
b61ec6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff60dd7
 
39ac420
 
ff60dd7
 
 
39ac420
 
 
 
 
 
 
b61ec6f
 
 
 
 
79a8749
b61ec6f
39ac420
b61ec6f
 
79a8749
39ac420
ff60dd7
b61ec6f
 
 
39ac420
ff60dd7
b61ec6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff60dd7
b61ec6f
 
 
 
ff60dd7
b61ec6f
ff60dd7
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
# crewai_resume_optimization.py

import os
from crewai import Agent, Task, Crew
from crewai_tools import PDFSearchTool, ScrapeWebsiteTool
import openai

# Set the model; adjust as needed.
os.environ["OPENAI_MODEL_NAME"] = 'gpt-4o-mini'
openai.api_key = os.getenv("OPENAI_API_KEY")

# Initialize tools.
pdf_tool = PDFSearchTool()
scrape_tool = ScrapeWebsiteTool()  

# For this module, we do not need external scraping tools since job input is text.
# Define the Resume Strategist Agent.
# resume_strategist = Agent(
#     role="Resume Strategist for Engineers",
#     goal="Optimize the candidate's resume by integrating job keywords while preserving its original content.",
#     backstory="You are an expert resume strategist. You enhance resumes by incorporating provided keywords exactly where necessary, preserving the original content.",
#     verbose=True
# )

# Resume Strategist Agent: Optimize resume based on provided job description.
resume_strategist = Agent(
    role="Resume Strategist for ATS Optimization",
    goal="Optimize the candidate's resume to better match the job description for ATS screening. Do not create new roles or responsibilities; instead, tailor the existing content to highlight alignment with the job requirements.",
    backstory="You are an expert resume strategist who refines resumes by selectively integrating provided job keywords while preserving the candidate's original experience.",
    verbose=True
)

# # Define the Interview Preparer Agent.
# interview_preparer = Agent(
#     role="Interview Preparer",
#     goal="Generate interview questions and talking points based on the optimized resume and job keywords.",
#     backstory="You create insightful interview questions that help a candidate prepare for an interview, based on the resume content and job requirements.",
#     verbose=True
# )

# Interview Preparer Agent: Generate interview questions based on optimized resume.
interview_preparer = Agent(
    role="Interview Preparer",
    goal="Generate interview questions and talking points based on the optimized resume and job description.",
    backstory="You create insightful interview questions to help candidates prepare, using the optimized resume and job description as context.",
    verbose=True
)

# Job Description Extractor Agent: Used when the user provides a job URL.
job_desc_extractor = Agent(
    role="Job Description Extractor",
    goal="Extract the job description content from the provided job posting URL using scraping.",
    backstory="You specialize in scraping and extracting relevant job information from websites.",
    verbose=True,
    tools=[scrape_tool]
)


# # Task 1: Resume Optimization Task.
# resume_optimization_task = Task(
#     description=(
#         "Given the original resume text: {resume_text}\n\n"
#         "and the following job keywords: {job_keywords}, "
#         "optimize the resume to highlight the candidate's strengths by incorporating these keywords where appropriate. "
#         "Preserve the original content; do not invent new details. "
#         "Return the updated resume in markdown format."
#     ),
#     expected_output="A markdown formatted optimized resume.",
#     output_file="tailored_resume.md",
#     agent=resume_strategist
# )

# Task for Resume Optimization: Use the original resume text and job description.
resume_optimization_task = Task(
    description=(
        "Given the original resume text:\n\n{resume_text}\n\n"
        "and the job description:\n\n{job_description}\n\n"
        "Optimize the resume to better match the job requirements for ATS screening."
        "Make sure to identify keywords form the job description and inlcude all necessary keywords to make the resume standout"
        "Preserve the original roles and responsibilities, but tailor the content to emphasize alignment with the job requirements. "
        "Return the optimized resume in markdown format."
    ),
    expected_output="A markdown formatted optimized resume.",
    output_file="tailored_resume.md",
    agent=resume_strategist
)

# # Task 2: Interview Question Generation Task.
# interview_generation_task = Task(
#     description=(
#         "Using the optimized resume: {optimized_resume}\n\n"
#         "and the job keywords: {job_keywords}, generate a set of interview questions and talking points. "
#         "Return the result in markdown format."
#     ),
#     expected_output="A markdown formatted document containing interview questions and talking points.",
#     output_file="interview_materials.md",
#     agent=interview_preparer,
#     context=[resume_optimization_task]
# )

# Task for Interview Generation: Use the optimized resume and job description.
interview_generation_task = Task(
    description=(
        "Using the optimized resume:\n\n{optimized_resume}\n\n"
        "and the job description:\n\n{job_description}\n\n"
        "Generate a set of interview questions and talking points in markdown format."
    ),
    expected_output="A markdown formatted document with interview questions and talking points.",
    output_file="interview_materials.md",
    agent=interview_preparer,
    context=[resume_optimization_task]
)

# Task for Job Description Extraction (for URL mode).
job_desc_extraction_task = Task(
    description=(
        "Extract and return the job description content from the job posting URL {job_url}."
    ),
    expected_output="A string containing the job description.",
    agent=job_desc_extractor
)

# Crew for job description extraction (URL mode)
job_desc_crew = Crew(
    agents=[job_desc_extractor],
    tasks=[job_desc_extraction_task],
    verbose=True
)

# Assemble the Crew.
resume_optimization_crew = Crew(
    agents=[resume_strategist],
    tasks=[resume_optimization_task],
    verbose=True
)

# Assemble the Crew.
interview_prep_crew = Crew(
    agents=[ interview_preparer],
    tasks=[ interview_generation_task],
    verbose=True
)

# ---------------------------
# Functions to call the crews
# ---------------------------
def optimize_resume(resume_text: str, job_description: str) -> str:
    inputs = {"resume_text": resume_text, "job_description": job_description}
    results = resume_optimization_crew .kickoff(inputs=inputs)
    return results.raw

def generate_interview_questions(optimized_resume: str, job_description: str) -> str:
    inputs = {"optimized_resume": optimized_resume, "job_description": job_description}
    results = interview_prep_crew.kickoff(inputs=inputs)
    return results.raw

def extract_job_description(job_url: str) -> str:
    inputs = {"job_url": job_url}
    results = job_desc_crew.kickoff(inputs=inputs)
    return results.raw

# def optimize_resume(resume_text: str, job_keywords: str) -> str:
#     inputs = {"resume_text": resume_text, "job_keywords": job_keywords}
#     results = resume_optimization_crew.kickoff(inputs=inputs)
#     return results.raw

# def generate_interview_questions(optimized_resume: str, job_keywords: str) -> str:
#     inputs = {"optimized_resume": optimized_resume, "job_keywords": job_keywords}
#     results = interview_prep_crew.kickoff(inputs=inputs)
#     return results.raw

# if __name__ == "__main__":
#     sample_resume = "Sample resume text here..."
#     sample_keywords = "Python, Machine Learning, Leadership"
#     optimized = optimize_resume(sample_resume, sample_keywords)
#     print("Optimized Resume:\n", optimized)
#     interview = generate_interview_questions(optimized, sample_keywords)
#     print("Interview Questions:\n", interview)

if __name__ == "__main__":
    # Test usage
    sample_resume = "Sample resume text..."
    sample_job_desc = "This job requires Python, machine learning, and leadership."
    optimized = optimize_resume(sample_resume, sample_job_desc)
    print("Optimized Resume:\n", optimized)
    interview = generate_interview_questions(optimized, sample_job_desc)
    print("Interview Questions:\n", interview)