From 75fcf820b596fd91ec4f91f98fe64da105bb3fa4 Mon Sep 17 00:00:00 2001
From: Atin Pothiraj <50777724+atinpothiraj@users.noreply.github.com>
Date: Tue, 30 May 2023 22:34:06 -0400
Subject: [PATCH] Created app.py

added supporting templates too.
---
 flask_testing/app.py               | 28 ++++++++++++++++++++++++++++
 flask_testing/templates/index.html | 15 +++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 flask_testing/app.py
 create mode 100644 flask_testing/templates/index.html

diff --git a/flask_testing/app.py b/flask_testing/app.py
new file mode 100644
index 0000000..2d9e821
--- /dev/null
+++ b/flask_testing/app.py
@@ -0,0 +1,28 @@
+import os
+
+import openai
+from flask import Flask, redirect, render_template, request, url_for
+
+app = Flask(__name__)
+openai.api_key = os.getenv("OPENAI_API_KEY")
+
+
+@app.route("/", methods=("GET", "POST"))
+def index():
+    if request.method == "POST":
+        task_form = request.form["task_form"]
+        response = openai.Completion.create(model="text-davinci-003", 
+                                            prompt = generate_prompt(task_form),
+                                            temperature=0, 
+                                            max_tokens=100)
+        return redirect(url_for("index", result=response.choices[0].text))
+
+    result = request.args.get("result")
+    return render_template("index.html", result=result)
+
+
+def generate_prompt(task_form):
+    base_text = "You are a software manager at the company Alphabet. Q: Format a message that specifically delegates the parts of the following task to your team of engineers."
+    
+    
+    return base_text + "TASK: " + task_form
diff --git a/flask_testing/templates/index.html b/flask_testing/templates/index.html
new file mode 100644
index 0000000..8bee883
--- /dev/null
+++ b/flask_testing/templates/index.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<head>
+  <title>Quickstart</title>
+</head>
+
+<body>
+  <h3>Name your task</h3>
+  <form action="/" method="post">
+    <input type="text" name="task_form" placeholder="Enter a task" required />
+    <input type="submit" value="Generate subtasks" />
+  </form>
+  {% if result %}
+  <div class="result">{{ result }}</div>
+  {% endif %}
+</body>
\ No newline at end of file