forked from slippersheepig/chatgpt-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
41 lines (35 loc) · 1.21 KB
/
app.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
36
37
38
39
40
41
import openai
from flask import Flask, request, render_template, redirect
server = Flask(__name__)
def get_completion(question):
try:
response = openai.Completion.create(
model="text-davinci-003",
prompt=f"{question}\n",
temperature=0.9,
max_tokens=2048,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=None
)
except Exception as e:
print(e)
return e
return response["choices"][0].text
@server.route('/chat', methods=['GET', 'POST'])
def get_request_json():
if request.method == 'POST':
if len(request.form['question']) < 1:
return render_template(
'chat.html', question="null", res="Can't be empty")
question = request.form['question']
print("======================================")
print("Recieved:", question)
res = get_completion(question)
print("Q:\n", question)
print("A:\n", res)
return render_template('chat.html', question=question, res=str(res))
return render_template('chat.html', question=0)
if __name__ == '__main__':
server.run(debug=True, host='0.0.0.0', port=80)