-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpt-dummy-test-1-file.py
78 lines (66 loc) · 2.84 KB
/
gpt-dummy-test-1-file.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
import openai
openai.api_key = ""
def get_completion(prompt, model="gpt-3.5-turbo", temperature=0):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature,
)
return response.choices[0].message["content"]
def save_details_to_json(details, output_file, output_directory):
output_file_path = os.path.join(output_directory, output_file)
with open(output_file_path, 'w', encoding='utf-8') as f:
json.dump(details, f, indent=4)
file_path = '#give the file path to a txt file'
with open(file_path, 'r') as file:
text = file.read()
print(text)
prompt = f"""Extract details from the text of resume delimited by angle brackets into a JSON. For any details that are blank or not found, use the word 'Unknown'.
The JSON should have the following keys.
{
"personal_info": {
"name": "",
"email": "",
"phone": "",
"address": ""
},
"education": [
{
"degree": "",
"university": "",
"graduation_year": ""
},
{
"degree": "",
"university": "",
"graduation_year": ""
}
],
"work_experience": [
{
"title": "",
"company": "",
"start_date": "",
"end_date": "",
"description": ""
},
{
"title": "",
"company": "",
"start_date": "",
"end_date": "",
"description": ""
}
],
"skills": [],
"certifications": [],
"projects": [],
"extracurricular_activities": [],
}
<{text}>"""
response = get_completion(prompt)
save_details_to_json(response,'Resume2.json', '#file path to where JSON must be stored')
prompt = f"""Extract details from the text of resume delimited by angle brackets into a JSON. The details that need to be extracted are:
Name, Phone number, email address, linkedin URL, github URL, work experience, education, skills, projects, extracurricular activities, certifications.
For any details that are blank or not found, use the word 'Unknown' <{text}>"""