Skip to content

Commit 019780c

Browse files
authored
Merge pull request #33 from jpgtzg/feature/add-description-improvements
Feature/add description improvements
2 parents 63a18b3 + 563cc0e commit 019780c

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
.pytest_cache/
44
__pycache__
55
.vscode
6-
.env
6+
.env

app.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from flask import Flask, jsonify, request
66
from models import Experience, Education, Skill
7+
from gpt_connection import get_improvement
78
from validation import validate_experience, validate_education, validate_skill
89
from spell_check import spell_check
910

@@ -21,14 +22,13 @@
2122
)
2223
],
2324
"education": [
24-
Education(
25-
"Computer Science",
26-
"University of Tech",
27-
"September 2019",
28-
"July 2022",
29-
"80%",
30-
"example-logo.png",
31-
)
25+
Education("Computer Science",
26+
"University of Tech",
27+
"September 2019",
28+
"July 2022",
29+
"80%",
30+
"example-logo.png",
31+
"I was head of the debate team at university")
3232
],
3333
"skill": [Skill("Python", "1-2 Years", "example-logo.png")],
3434
}
@@ -102,6 +102,25 @@ def education():
102102
except ValueError as e:
103103
return jsonify({"error": str(e)}), 400
104104

105+
@app.route('/resume/reword_description', methods=['GET'])
106+
def reword_description():
107+
'''
108+
Rewords the description using GPT
109+
'''
110+
model = None
111+
try:
112+
model = Experience(**request.json)
113+
except:
114+
model = Education(**request.json)
115+
116+
if model is None:
117+
return jsonify({"error": "Invalid request"}), 400
118+
119+
response = get_improvement(model)
120+
if response is None:
121+
return jsonify({"error": "Failed to get improvement"}), 500
122+
123+
return jsonify({"response": response})
105124

106125
@app.route("/resume/skill", methods=["GET", "POST"])
107126
def skill():

gpt_connection.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
3+
from openai import OpenAI
4+
import os
5+
from dotenv import load_dotenv
6+
from models import Experience, Education
7+
load_dotenv()
8+
9+
client = OpenAI(
10+
api_key=os.getenv("OPENAI_API_KEY")
11+
)
12+
13+
def get_improvement(model : Experience | Education):
14+
prompt = f"Improve the following description for the {model.__class__.__name__}: {model.description}"
15+
16+
response = client.chat.completions.create(
17+
model="gpt-4o-mini",
18+
messages=[
19+
{"role": "system", "content": "You are a helpful assistant that improves descriptions for resumes."},
20+
{"role": "assistant", "content": "Here is the improved description:"},
21+
{"role": "system", "content": f"Consider the following information about the {model.__class__.__name__}: {model.model_dump_json()}"},
22+
{"role": "user", "content": prompt},
23+
]
24+
)
25+
try:
26+
return response.choices[0].message.content
27+
except:
28+
return None
29+
30+
31+

models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'''
66

77
from dataclasses import dataclass
8+
import json
89

910

1011
@dataclass
@@ -19,6 +20,11 @@ class Experience:
1920
description: str
2021
logo: str
2122

23+
def model_dump_json(self):
24+
'''
25+
Dumps the class into a JSON string
26+
'''
27+
return json.dumps(self, default=lambda o: o.__dict__)
2228

2329
@dataclass
2430
class Education:
@@ -31,6 +37,13 @@ class Education:
3137
end_date: str
3238
grade: str
3339
logo: str
40+
description: str
41+
42+
def model_dump_json(self):
43+
'''
44+
Dumps the class into a JSON string
45+
'''
46+
return json.dumps(self, default=lambda o: o.__dict__)
3447

3548

3649
@dataclass

0 commit comments

Comments
 (0)