Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
slippersheepig authored Mar 6, 2023
1 parent 14b1ba2 commit 53a9f14
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import json
from revChatGPT.Unofficial import Chatbot
from revChatGPT.V1 import Chatbot
from flask import Flask, request, render_template, redirect

server = Flask(__name__)
Expand All @@ -11,25 +10,23 @@
# init chatbot
chatbot = Chatbot(config)

def send_gpt(message):
response = chatbot.ask(message)
return response["message"]
def generate_response(prompt):
try:
response = ""
for data in chatbot.ask(prompt):
response = data["message"]
return response
except Exception as e:
return e

@server.route('/', 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="问题不能为空")
question = request.form['question']
print("======================================")
print("接到请求:", question)
res = send_gpt(question)
print("问题:\n", question)
print("答案:\n", res)
@server.route("/")
def home():
return render_template("chat.html")

return render_template('chat.html', question=question, res=str(res))
return render_template('chat.html', question=0)
@server.route("/get")
def get_bot_response():
user_text = request.args.get('msg')
return str(generate_response(user_text))

if __name__ == '__main__':
server.run(debug=True, host='0.0.0.0', port=80)
server.run(debug=False, host='0.0.0.0', port=8088)

0 comments on commit 53a9f14

Please sign in to comment.