from flask import Flask, request, jsonify import pandas as pd import matplotlib.pyplot as plt import os import openai app = Flask(__name__) openai.api_key = os.getenv("OPENAI_API_KEY") # Sample data to store tasks and users tasks_data = {} users_data = {} def generate_prompt(task_form): base_text = "You are a software engineer at a software development company. Your job is to assign tags to tasks based on the software/tools used. Please generate one-word tags representing software/tools/libraries commonly used by developers to build or complete the following task." return base_text + "TASK: " + task_form def generate_technical_tags(task_form): prompt = generate_prompt(task_form) response = openai.Completion.create( model="text-davinci-003", prompt=prompt, temperature=0, max_tokens=100, stop=["TASK:"] ) tags = response.choices[0].text.strip().split("\n") return tags @app.route('/label_tasks', methods=['POST']) def get_task_tags(): # try: data = request.get_json() tasks = data[0]['tasks'] result = {} for task, task_description in tasks.items(): task_id = task_description["id"] task_content = task_description["content"] task_complexity = task_description["complexityScore"] tags = generate_technical_tags(task_content) # where the function that gets the tags is placed result[task_id] = tags return jsonify(result) # except Exception as e: # return jsonify({"error": str(e)}), 500 @app.route('/assign_tasks', methods=['POST']) def assign_tasks_to_users(): try: data = request.get_json() tasks = data[0]['tasks'] users = data[0]['users'] result = {} tasks_dict = {} users_dict = {} for task, task_description in tasks.items(): tasks_dict[task_description["id"]] = {"tags" : task_description["content"], "complexity" : task_description["complexityScore"]} # tasks_dict[task_description["id"]] = {"tags" : generate_technical_tags(task_description["content"]), "complexity" : task_description["complexityScore"]} for user, user_description in users.items(): users_dict[user_description["id"]] = {"strengths" : user_description["strengths"], "current_tasks" : user_description["currentTasks"]} # return jsonify(result) return result except Exception as e: return jsonify({"error": str(e)}), 500 if __name__ == '__main__': app.run(debug=True)