代码拉取完成,页面将自动刷新
from flask import Flask,request
import requests
import json
import random
import openai
import os
app = Flask(__name__)
@app.route('/')
def hello_world():
return '在此输入apikey 样式:sk-s5S5BoV...'
@app.route('/message',methods = ['POST'])
def mess(): # put application's code here
message = request.json.get('msg')
openai.api_key = "key" #修改这里为自己申请的api_key
messages = [
{"role": "system", "content": "You are a coding tutor bot to help user write and optimize python code."},
]
messages.append({"role": "user", "content": message})
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": message}]
)
print(completion)
#messages.append({"role": "assistant", "content": response["choices"][0]["message"].content})
res = {
"resmsg":completion,
"code":200
}
return res
if __name__ == '__main__':
app.run(threaded = False,processes=5,host="0.0.0.0",port="5000")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。