1 Star 1 Fork 0

此刻/openai-quickstart-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.py 878 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhangyunan 提交于 2023-03-07 10:09 . init
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":
animal = request.form["animal"]
response = openai.Completion.create(
max_tokens=1024,
n=1,
stop=None,
model="text-davinci-001",
prompt=generate_prompt(animal),
temperature=0.8,
)
return redirect(url_for("index", result=response.choices[0].text.replace('/r/n', '<br>')))
result = request.args.get("result")
return render_template("index.html", result=result)
def generate_prompt(animal):
return animal
# animal.capitalize()
# )
if '__main__' == __name__:
app.run(port=10800, host='0.0.0.0')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/cike-projects/openai-quickstart-python.git
git@gitee.com:cike-projects/openai-quickstart-python.git
cike-projects
openai-quickstart-python
openai-quickstart-python
main

搜索帮助