From 10815100acaa283079dcb2c785bd1792a81a81f7 Mon Sep 17 00:00:00 2001 From: "grit-dev-app[bot]" <105042105+grit-dev-app[bot]@users.noreply.github.com> Date: Tue, 9 Apr 2024 05:23:32 +0000 Subject: [PATCH] [bot] migrate files --- app.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 7b2864137..fb43900ac 100644 --- a/app.py +++ b/app.py @@ -1,21 +1,20 @@ import os -import openai +from openai import OpenAI + +client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) 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": animal = request.form["animal"] - response = openai.Completion.create( - model="text-davinci-003", - prompt=generate_prompt(animal), - temperature=0.6, - ) + response = client.completions.create(model="text-davinci-003", + prompt=generate_prompt(animal), + temperature=0.6) return redirect(url_for("index", result=response.choices[0].text)) result = request.args.get("result")