Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add description improvements #33

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.venv
.pytest_cache/
__pycache__
.vscode
.vscode
.env
24 changes: 22 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''
from flask import Flask, jsonify, request
from models import Experience, Education, Skill

from gpt_connection import get_improvement
app = Flask(__name__)

data = {
Expand All @@ -21,7 +21,8 @@
"September 2019",
"July 2022",
"80%",
"example-logo.png")
"example-logo.png",
"I was head of the debate team at university")
],
"skill": [
Skill("Python",
Expand Down Expand Up @@ -65,6 +66,25 @@ def education():

return jsonify({})

@app.route('/resume/reword_description', methods=['GET'])
def reword_description():
'''
Rewords the description using GPT
'''
model = None
try:
model = Experience(**request.json)
except:
model = Education(**request.json)

if model is None:
return jsonify({"error": "Invalid request"}), 400

response = get_improvement(model)
if response is None:
return jsonify({"error": "Failed to get improvement"}), 500

return jsonify({"response": response})

@app.route('/resume/skill', methods=['GET', 'POST'])
def skill():
Expand Down
31 changes: 31 additions & 0 deletions gpt_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


from openai import OpenAI
import os
from dotenv import load_dotenv
from models import Experience, Education
load_dotenv()

client = OpenAI(
api_key=os.getenv("OPENAI_API_KEY")
)

def get_improvement(model : Experience | Education):
prompt = f"Improve the following description for the {model.__class__.__name__}: {model.description}"

response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant that improves descriptions for resumes."},
{"role": "assistant", "content": "Here is the improved description:"},
{"role": "system", "content": f"Consider the following information about the {model.__class__.__name__}: {model.model_dump_json()}"},
{"role": "user", "content": prompt},
]
)
try:
return response.choices[0].message.content
except:
return None



13 changes: 13 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''

from dataclasses import dataclass
import json


@dataclass
Expand All @@ -19,6 +20,11 @@ class Experience:
description: str
logo: str

def model_dump_json(self):
'''
Dumps the class into a JSON string
'''
return json.dumps(self, default=lambda o: o.__dict__)

@dataclass
class Education:
Expand All @@ -31,6 +37,13 @@ class Education:
end_date: str
grade: str
logo: str
description: str

def model_dump_json(self):
'''
Dumps the class into a JSON string
'''
return json.dumps(self, default=lambda o: o.__dict__)


@dataclass
Expand Down