|
2 | 2 | Flask Application |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import openai |
| 6 | + |
| 7 | +from dotenv import load_dotenv |
| 8 | +import os |
| 9 | + |
| 10 | +load_dotenv() |
| 11 | +openai.api_key = os.getenv("OPENAI_API_KEY") |
| 12 | + |
5 | 13 | from dataclasses import asdict |
6 | 14 |
|
7 | 15 | from flask import Flask, jsonify, request |
@@ -216,3 +224,36 @@ def get_skill(skill_id): |
216 | 224 | return jsonify({"error": "Skill not found"}), 404 |
217 | 225 | except TypeError as e: |
218 | 226 | return jsonify({"error": str(e)}), 400 |
| 227 | + |
| 228 | + |
| 229 | +@app.route("/resume/suggest-description", methods=["POST"]) |
| 230 | +def suggest_description(): |
| 231 | + """ |
| 232 | + Uses OpenAI API to suggest improvements for a description field. |
| 233 | + Expects JSON: { "type": "experience"|"education", "description": "..." } |
| 234 | + """ |
| 235 | + data_in = request.get_json() |
| 236 | + desc = data_in.get("description", "") |
| 237 | + section_type = data_in.get("type", "experience") |
| 238 | + |
| 239 | + if not desc: |
| 240 | + return jsonify({"error": "Description is required"}), 400 |
| 241 | + |
| 242 | + prompt = ( |
| 243 | + f"Suggest a more professional and concise version of this {section_type} description:\n{desc}" |
| 244 | + ) |
| 245 | + |
| 246 | + try: |
| 247 | + client = openai.OpenAI() |
| 248 | + response = client.chat.completions.create( |
| 249 | + model="gpt-3.5-turbo", |
| 250 | + messages=[ |
| 251 | + {"role": "system", "content": "You are a helpful assistant for resume writing"}, |
| 252 | + {"role": "user", "content": prompt}, |
| 253 | + ], |
| 254 | + max_tokens=100, |
| 255 | + ) |
| 256 | + suggestion = response.choices[0].message.content.strip() |
| 257 | + return jsonify({"suggestion": suggestion}), 200 |
| 258 | + except Exception as e: |
| 259 | + return jsonify({"error": str(e)}), 500 |
0 commit comments