candidate-recommender / parse_job_description.py
avimittal30's picture
using original function to get scores
ccb6a47
import openai
from dotenv import load_dotenv
import os
import re
import json
load_dotenv()
# ## For hugging face
# os.environ['OPENAI_API_KEY']=os.getenv('OPENAI_API_KEY')
## for local run
os.environ['OPENAI_API_KEY']=os.getenv('OPENAI_API_KEY')
job_description = """
Five or more years of experience as engineer of software and networking platforms.
Seven or more years of experience (professional and academic) with Java, Python, and C++
Proven ability to document design processes, including development, testing, analytics, and troubleshooting.
Experience with rapid development cycles in a web-based environment.
Strong ability in scripting and test automation.
Desire to continue professional growth through training and education.
Bachelor’s or Master's degree (or equivalent) in software engineering or information technology or computer science/engineering.
Working knowledge of relational databases as well as ORM and SQL technologies.
Proficiency with HTML5, CSS3, and content management systems.
Web application development experience with multiple frameworks, including Wicket, GWT, and Spring MVC
"""
def extract_job_details(job_description):
messages = [
{"role": "system", "content": "You are an AI assistant that extracts key information from job descriptions."},
{"role": "user", "content": f"""Extract the following details from the given job description and return them in JSON format:
- **Skills**: Extract only the skill names without surrounding words.
- **Experience**: If multiple values are mentioned, calculate the average number of years.
- **Personality Traits**: List concise personality attributes.
- **Education**: Extract all possible **degree and discipline combinations**, ensuring **all common variants** are included.
### **Education Extraction Rules**
1. Identify **all degrees and disciplines** mentioned in the job description.
2. For **each degree found**, generate **all possible common variants** it might appear as in resumes. Ensure to include:
- Variants like **B.E.**, **B.Tech**, **BTech**, **Bachelor of Technology**, **Bachelor of Engineering**, etc.
- For **disciplines**: Consider **Computer Science**, **Information Technology**, **Software Engineering**, **Mechanical Engineering**, and others. Ensure you capture abbreviations like **CS**, **CSE**, **IT**, **SE**, etc.
3. Combine the degrees and disciplines into a structured format, ensuring all variants are covered in order of their popularity.
**Example:**
**Job Description:**
"We are looking for a candidate with a Bachelor's in Computer Science or Information Technology."
**Expected Output:**
```json
{{
"Education": [
"B.E. Computer Science",
"BE Computer Science",
"Bachelors of Engineering Computer Science",
"B.Tech Computer Science",
"B.Tech. Computer Science",
"BTech Computer Science",
"Bachelor of Technology Computer Science",
"B.E. Information Technology",
"BE Information Technology",
"Bachelors of Engineering Information Technology",
"B.Tech Information Technology",
"B.Tech. Information Technology",
"BTech Information Technology"
]
}}
```
### **Task:**
- **Extract the degrees and disciplines from the given job description.**
- **Expand them into all real-world variations, as seen in resumes.**
- **Ensure a structured JSON response similar to the example above.**
**Job Description:** {job_description}"""}
]
response = openai.chat.completions.create(
model="gpt-4", # You can use "gpt-3.5-turbo" as well
messages=messages,
max_tokens=1000,
temperature=0
)
response_text = response.choices[0].message.content.strip()
pattern = r'^```json\s*(.*?)\s*```$'
cleaned_string = re.sub(pattern, r'\1', response_text, flags=re.DOTALL).strip()
return json.loads(cleaned_string)