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": - "skills_not_present": - "score": ``` {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": - "irrelevant_experiences": - "score": ``` {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 and ends with and I have a candidate its resume below the delimiter and it ends with . {vacancy} {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 > - 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)