-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitResume.py
172 lines (143 loc) · 6 KB
/
splitResume.py
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
import os
from supabase import create_client , Client
import supabase
from groq import Groq
from hyde import generate_job_description
from openai import OpenAI
import os
def setup():
client = create_client(
os.environ.get("SUPABASE_URL"),
os.environ.get("SUPABASE_KEY")
)
return client
def retrieve_response(col_name: str , table_name: str , client , col_value):
"""
Retrieve response from supabase database using the id and table_name
"""
data, count = client.table(table_name).select('*').eq(col_name , col_value).execute()
return data
def update_response(col_name , col_value , table_name: str , client):
"""
Update response in the supabase database using the id and table_name
"""
data, count = client.table(table_name).update({col_name : col_value}).eq('id', 1).execute()
return data
def get_response(resume , file_name):
"""
resume : text of resume
file_name : will be the key
"""
#get supanase client for pushing data into the database
supabase_client = setup()
#get the response from the groq api for LLMs
client = Groq(
api_key=os.environ.get("GROQ_KEY"),
)
table_name = os.environ.get("SUPA_BASE_TABLE")
schema = {
"type":"object",
"properties": {
"name": {"type": "string",
"description": "The name of the candidate"
},
"contact_information": {"type": "string" ,
"description": "The contact information of the candidate. This should include the email address and phone number of the candidate. If the information is not present in the resume, just mention that the information is not present."
},
"summary": {"type": "string",
"description": "The summary of the candidate. This should include a brief overview of the candidate's background and experience. If the information is not present in the resume, just mention that the information is not present."
},
"work_experience": {"type": "string" ,
"description": "The work experience of the candidate"
},
"education": {"type": "string",
"description": "The education of the candidate"
},
"skills": {"type": "string",
"skills": "The skills of the candidate"
},
"certifications": {"type": "string",
"description": "The certifications of the candidate"
},
},
}
chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": f"""You are a recruiter and you have received a resume from a candidate. You need to split the resume into the following sections:\n
1. Name\n
2. Contact Information\n
3. Summary\n
4. Work Experience\n
5. Education\n
6. Skills\n
7. Certifications\n
If the information is not present in the resume, just mention that the information is not present.
Return a JSON object with the following schema:
{schema}
.
""",
},
{
"role": "user",
"content": f"The Resume is: \n\n{resume} ",
}
],
model="llama3-70b-8192",
response_format={"type": "json_object"}
)
output = chat_completion.choices[0].message.content
#process output as dict
output_dict = eval(output)
name = output_dict['name']
contact_information = output_dict['contact_information']
summary = output_dict['summary']
work_experience = output_dict['work_experience']
education = output_dict['education']
skills = output_dict['skills']
certifications = output_dict['certifications']
st = ""
st = st + "Name: " + name + "\n\n"
st = st + "Contact Information: " + contact_information + "\n\n"
st = st + "Summary: " + summary + "\n\n"
st = st + "Work Experience: " + work_experience + "\n\n"
st = st + "Education: " + education + "\n\n"
st = st + "Skills: " + skills + "\n\n"
st = st + "Certifications: " + certifications + "\n\n"
#replace space in file name with underscore
file_name = file_name.replace(" ", "_")
file_name = file_name.split(".pdf")[0]
new_name = name.replace(" ", "_")
#push the response to the database
response = {
"id": 1 ,
"resume_key": file_name + "_" + new_name,
"name": name,
"resume_content": st,
}
#delete the previous record with the same id
# data, count = supabase_client.table(table_name).delete().eq('id', 1).execute()
# #insert the new record
# data, count = supabase_client.table(table_name).insert(response).execute()
#retrieve the response from the database
# print("retrieve response")
# data_retrieved = retrieve_response(col_name='id' , table_name=table_name , client=supabase_client , col_value=1)
#get conversation from the response
# conversation = data_retrieved[1][0]['conversation']
job_description = generate_job_description(st)
api_key = os.environ.get("OPENAI_API_KEY")
OpenAIclient = OpenAI(api_key=api_key)
response = OpenAIclient.embeddings.create(
input= job_description,
model="text-embedding-3-small"
)
embedding = response.data[0].embedding
output = supabase_client.rpc('match_documents' ,{ "query_embedding" : embedding,
"match_threshold" : 0.3,
"match_count" : 5,
}).select('*').execute()
reco = ""
for i in output.data:
reco = reco + i['content'] + "\n\n****************************************************************\n\n"
return reco