File size: 9,041 Bytes
025b987
 
 
 
 
 
245ba2a
5a84835
025b987
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a84835
 
025b987
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a84835
025b987
 
 
 
 
 
 
 
 
 
5a84835
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
025b987
 
 
 
 
 
 
 
 
 
 
 
 
5a84835
025b987
 
 
 
 
245ba2a
025b987
 
 
 
 
 
 
5a84835
025b987
5a84835
025b987
 
 
 
 
5a84835
f3c9931
 
 
 
 
 
 
 
 
 
 
 
 
 
1f2286b
f3c9931
1f2286b
f3c9931
 
025b987
 
eaaa73b
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
import json
import os
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.chains import LLMChain, SequentialChain

# from validation import validate_dict_value, validate_string_value

# os.environ["OPENA"]


vacancy = """
DATA SCIENTIST - GENTIS
========================

Profile:

Min of 3 years experience as a Data Scientist
Experience in Python and SQL
Communicative very strong
Experience in coaching and supporting junior collegues
Experience in Google Cloud is a plus
Experience in Machine Learning is a plus

They offer:

An opportunity to be part of not only a fast-growing, innovative company, but one where you as a person can grow professionally as fast as the company
A close-knit and diverse team who are all ready to help, listen and give advice to each other
Training opportunities (because they don't stand still, so neither do you)
Trendy and young company where everyone can be their own
A very nice salary package and much more
Lots of remote work and flexibility, so bye bye traffic JAMS!
A renovated office with everything you could dream of full with surprises and extras

"""


resume = """
John Doe
=============================

Skills 
 -  Python 
 -  Tableau 
 -  Data Visualization 
 -  R Studio 
 -  Machine Learning 
 -  Statistics IABAC Certified Data Scientist with versatile experience over 1+ years in managing business, data science consulting and leading innovation projects, bringing business ideas to working real world solutions.
Being a strong advocator of augmented era, where human capabilities are enhanced by machines, Fahed is passionate about bringing business concepts in area of machine learning, AI, robotics etc., to real life solutions.Education Details  January 2017 B.
Tech Computer Science & Engineering Mohali, Punjab Indo Global College of Engineering Data Science Consultant   Data Science Consultant - Datamites Skill Details  MACHINE LEARNING- Exprience - 13 months PYTHON- Exprience - 24 months SOLUTIONS- Exprience - 24 months DATA SCIENCE- Exprience - 24 months DATA VISUALIZATION- Exprience - 24 months Tableau- Exprience - 24 monthsCompany Details  company - Datamites description - 
 -  Analyzed and processed complex data sets using advanced querying, visualization and analytics tools.

 -  Responsible for loading, extracting and validation of client data.

 -  Worked on manipulating, cleaning & processing data using python.

 -  Used Tableau for data visualization.
company - Heretic Solutions Pvt Ltd description - 
 -  Worked closely with business to identify issues and used data to propose solutions for effective decision making.

 -  Manipulating, cleansing & processing data using Python, Excel and R.

 -  Analyzed raw data, drawing conclusions & developing recommendations.

 -  Used machine learning tools and statistical techniques to produce solutions to problems.

"""

llm = ChatOpenAI(temperature=0.0, openai_api_key=os.environ["OPENAI"])


def create_intro(vacancy=vacancy, resume=resume):

    template_vacancy_get_skills = """
    Can you generate me a list of the skills that a candidate is supposed to have for the below vacancy delimited by three backticks. 
    If you do not know if skills are available mention that you do not know and do not make up an answer. 
    Mention the skills in 1 to maximum three words for each skill. Return the skills as a JSON list.

    ```
    {vacancy}
    ```
    """

    prompt_vacancy_get_skills = ChatPromptTemplate.from_template(template=template_vacancy_get_skills)
    vacancy_skills = LLMChain(llm=llm, prompt=prompt_vacancy_get_skills, output_key="vacancy_skills")

    template_resume_check_skills = """
    ```
    {vacancy_skills}
    ```

    Based on the above list of skills required by a vacancy delimited by backticks,
    Can you create a JSON object based on the below keys each starting with '-', with respect to the resume below delimited by three backticks?

    - "skills_present": <list the skills present. If no skills are present return an empty list, do not make up an answer. >
    - "skills_not_present": <list the skills not present. If all skills are present return an empty list, do not make up an answer.>
    - "score": <calculate a percentage of the number of skills present with respect to the total skills requested>

    ```
    {resume}
    ```
    """

    prompt_resume_check_skills = ChatPromptTemplate.from_template(template=template_resume_check_skills)
    resume_skills = LLMChain(llm=llm, prompt=prompt_resume_check_skills, output_key="resume_skills")

    template_resume_past_experiences = """
    Can you generate me a list of the past work experiences that the candidate has based on the resume below enclosed by three backticks.
    Mention the experiences in one sentence of medium length. Return the experiences as a JSON list.

    ```
    {resume}
    ```
    """

    prompt_resume_past_experiences = ChatPromptTemplate.from_template(template=template_resume_past_experiences)
    past_experiences = LLMChain(llm=llm, prompt=prompt_resume_past_experiences, output_key="past_experiences")

    template_vacancy_check_past_experiences = """
    ```
    {past_experiences}
    ```

    Based on the above list of past experiences by a vacancy delimited by backticks,
    Can you create a JSON object based on the below keys each starting with '-', with respect to the vacancy below delimited by three backticks?

    - "relevant_experiences": <list the relevant experiences. If no experiences are relevant return an empty list, do not make up an answer. >
    - "irrelevant_experiences": <list the irrelevant experiences. If all experiences are relevant return an empty list, do not make up an answer.>
    - "score": <calculate a percentage of the number of skills present with respect to the total skills requested>

    ```
    {resume}
    ```
    """

    prompt_vacancy_check_past_experiences = ChatPromptTemplate.from_template(template=template_vacancy_check_past_experiences)
    check_past_experiences = LLMChain(llm=llm, prompt=prompt_vacancy_check_past_experiences, output_key="check_past_experiences")

    template_introduction_email = """
       You are a recruitment specialist that tries to place the right profiles for the right job.
       I have a vacancy below the delimiter <VACANCY> and ends with </VACANCY> 
       and I have a candidate its resume below the delimiter <RESUME> and it ends with </RESUME>.

       <VACANCY>
       {vacancy}
       </VACANCY>

       <RESUME>
       {resume}
       </RESUME>

       Can you fill in the introduction below and only return as answer this introduction?

       Role: < the role of the vacancy >
       Candidate: < name of the candidate >
       Education: < name the education of the candidate >
       Responsibilities: < did the candidate worked as an individual contributor or did het take on leadership postitions? >
       Experience: < name the 2 most relevant experiences from the candidate for this vacancy. Get them from the "relevant_experiences" key of the JSON object {past_experiences}. If there us no relevant experience, leave this empty. Do not make up an answer or get them from the irrelevant experiences. >
       Skills: print here a comma seperated list of the "skills_present" key of the JSON object {resume_skills}
       """

    prompt_introduction_email = ChatPromptTemplate.from_template(template=template_introduction_email)
    introduction_email = LLMChain(llm=llm, prompt=prompt_introduction_email, output_key="introduction_email")

    match_resume_vacancy_skills_chain = SequentialChain(
        chains=[vacancy_skills, resume_skills, past_experiences, check_past_experiences, introduction_email],
        input_variables=["vacancy", "resume"],
        output_variables=["vacancy_skills", "resume_skills", "past_experiences", "check_past_experiences", "introduction_email"],
        verbose=False
    )

    result = match_resume_vacancy_skills_chain({"vacancy": vacancy, "resume": resume})
    print(result)

    resume_skills = json.loads(result['resume_skills'])
    relevant_skills = len(resume_skills["skills_present"])
    total_skills = len(resume_skills["skills_present"] + resume_skills["skills_not_present"])
    score_skills = round(100.0*(relevant_skills/total_skills),2)


    check_past_experiences = json.loads(result['check_past_experiences'])
    relevant_experiences = len(check_past_experiences["relevant_experiences"])
    total_experiences = len(check_past_experiences["relevant_experiences"] + check_past_experiences["irrelevant_experiences"])
    score_experiences = round(100.0*(relevant_experiences/total_experiences),2)

    new_line = '\n'

    score = f"""
    Skills (Score: {score_skills}%)
    Relevant Skills: {",".join(resume_skills["skills_present"])}
    Not Relevant Skills: {",".join(resume_skills["skills_not_present"])}    
    """
    return result["introduction_email"], score

if __name__ == '__main__':
    create_intro(vacancy=vacancy,resume=resume)