{"id":"chatcmpl-9172c0d9dbbb0c39","object":"chat.completion","created":1774197192,"model":"NousResearch\/Hermes-3-Llama-3.2-3B","choices":[{"index":0,"message":{"role":"assistant","content":"First, install the required dependencies:\n\n```\npip install Flask-JWT-Extended Flask-SQLAlchemy\n```\n\nHere is the updated Flask app with authentication:\n\n```python\nfrom flask import Flask, request, jsonify\nfrom task_manager import TaskManager\nfrom flask_jwt_extended import JWTManager, create_access_token, jwt_required, get_jwt_identity\n\napp = Flask(__name__)\ntask_manager = TaskManager()\napp.config['JWT_SECRET_KEY'] = 'your-secret-key' # Change this to your own secret key\njwt = JWTManager(app)\n\n@app.route('\/')\ndef index():\n return \"Task Manager API\"\n\n@app.route('\/login', methods=['POST'])\ndef login():\n user = request.json.get('user')\n password = request.json.get('password')\n if user == 'admin' and password == 'admin':\n access_token = create_access_token(identity=user)\n return jsonify({'access_token': access_token})\n return jsonify({'message': 'Invalid username or password'})\n\n@app.route('\/tasks', methods=['GET'])\n@jwt_required()\ndef get_tasks():\n user_id = get_jwt_identity()\n tasks = [task for task in task_manager.tasks if task.assigned_to == user_id]\n output = []\n for task in tasks:\n task_data = {}\n task_data['id'] = task.id\n task_data['title'] = task.title\n task_data['description'] = task.description\n task_data['completed'] = task.completed\n task_data['priority'] = task.priority\n task_data['due_date'] = task.due_date\n task_data['tags'] = ', '.join(task.tags)\n task_data['depends_on'] = ', '.join([self.tasks_by_id[dep_id][0]['title'] for dep_id in task.depends_on])\n task_data['time_spent'] = task.time_spent\n task_data['progress'] = task.progress\n task_data['assigned_to'] = task.assigned_to\n task_data['estimated_minutes'] = task.estimated_minutes\n output.append(task_data)\n return jsonify({'tasks': output})\n\n@app.route('\/tasks', methods=['POST'])\n@jwt_required()\ndef create_task():\n data = request.get_json()\n title = data['title']\n description = data['description']\n due_date = data.get('due_date')\n tags = data.get('tags')\n depends_on = data.get('depends_on')\n recurrence = data.get('recur')\n next_occurrence = data.get('next_occurrence')\n time_spent = data.get('time_spent')\n progress = data.get('progress')\n assigned_to = data.get('assigned_to')\n estimated_minutes = data.get('estimated_minutes')\n user_id = get_jwt_identity()\n task_manager.add_task(title, description, due_date, tags, depends_on, recurrence, next_occurrence, time_spent, progress, assigned_to, estimated_minutes)\n return jsonify({'message': 'New task created'})\n\n@app.route('\/tasks\/', methods=['GET'])\n@jwt_required()\ndef get_task(id):\n task = next((task for task in task_manager.tasks if task.id == id and task.assigned_to == get_jwt_identity()), None)\n if task:\n task_data = {}\n task_data['id'] = task.id\n task_data['title'] = task.title\n task_data['description'] = task.description\n task_data['completed'] = task.completed\n task_data['priority'] = task.priority\n task_data['due_date'] = task.due_date\n task_data['tags'] = ', '.join(task.tags)\n task_data['depends_on'] = ', '.join([self.tasks_by_id[dep_id][0]['title'] for dep_id in task.depends_on])\n task_data['time_spent'] = task.time_spent\n task_data['progress'] = task.progress\n task_data['assigned_to'] = task.assigned_to\n task_data['estimated_minutes'] = task.estimated_minutes\n return jsonify({'task': task_data})\n return jsonify({'message': 'Task not found'})\n\n@app.route('\/tasks\/', methods=['PUT'])\n@jwt_required()\ndef update_task(id):\n data = request.get_json()\n task = next((task for task in task_manager.tasks if task.id == id and task.assigned_to == get_jwt_identity()), None)\n if task:\n task.title = data['title']\n task.description = data['description']\n task.due_date = data.get('due_date')\n task.tags = data.get('tags')\n task.depends_on = data.get('depends_on')\n task.recurrence = data.get('recur')\n task.next_occurrence = data.get('next_occurrence')\n task.time_spent = data.get('time_spent')\n task.progress = data.get('progress')\n task.assigned_to = data.get('assigned_to')\n task.estimated_minutes = data.get('estimated_minutes')\n return jsonify({'message': 'Task updated'})\n return jsonify({'message': 'Task not found'})\n\n@app.route('\/tasks\/', methods=['DELETE'])\n@jwt_required()\ndef delete_task(id):\n task = next((task for task in task_manager.tasks if task.id == id and task.assigned_to == get_jwt_identity()), None)\n if task:\n task_manager.delete_task(id)\n return jsonify({'message': 'Task deleted'})\n return jsonify({'message': 'Task not found'})\n\n@app.route('\/rate_limit', methods=['GET'])\n@jwt_required()\ndef rate_limit():\n user_id = get_jwt_identity()\n rate_limit = 100 # Change this to your own rate limit\n requests = request.args.get('requests', 0, type=int)\n remaining = rate_limit - requests\n return jsonify({'remaining': remaining})\n\nif __name__ == '__main__':\n app.run(debug=True)\n```\n\nThis Flask app has the following endpoints with authentication:\n- GET \/tasks: List all tasks (requires valid token)\n- POST \/tasks: Create a new task (requires valid token)\n- GET \/tasks\/: Get a specific task (requires valid token)\n- PUT \/tasks\/: Update a task (requires valid token)\n- DELETE \/tasks\/: Delete a task (requires valid token)\n- \/login: Login endpoint to get a token (requires admin user)\n- \/rate_limit: Get the remaining requests for the current user (requires valid token)\n\nTo use these endpoints, you can send HTTP requests to the corresponding URLs using tools like cURL or Postman. Make sure to include the access token in the Authorization header of the requests.","refusal":null,"annotations":null,"audio":null,"function_call":null,"tool_calls":[],"reasoning":null},"logprobs":null,"finish_reason":"stop","token_ids":null}],"service_tier":null,"system_fingerprint":null,"usage":{"prompt_tokens":28053,"total_tokens":29426,"completion_tokens":1373,"prompt_tokens_details":null},"prompt_token_ids":null,"kv_transfer_params":null}