-
Notifications
You must be signed in to change notification settings - Fork 84
/
index.py
35 lines (31 loc) · 1.02 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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")