-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
65 lines (48 loc) · 1.78 KB
/
application.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import datetime
import uuid
from flask import Flask, request, make_response, render_template, Response
import logging
from flask_cors import CORS
from gevent import pywsgi
from chain.gen_answer import GenAnswerOfRole
global vectordb
print("第一步")
app = Flask(__name__)
# 设置日志级别
app.logger.setLevel(logging.INFO)
# 创建日志处理器
handler = logging.FileHandler('app.log', encoding='utf-8')
handler.setLevel(logging.INFO)
# 创建日志格式
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# 添加日志处理器到应用程序记录器
app.logger.addHandler(handler)
# from flask_cors import CORS
app = Flask(__name__)
# 允许跨域
CORS(app)
@app.route('/')
def index():
# return render_template('index.html')
return "<h1>人类这不是你该来的地方</h1>"
# @app.route('/auto-ppt/gen-uuid', methods=['GET'])
# def get_uuid():
# random_uuid = str(uuid.uuid4())
# # todo 将ip地址和uuid 在redis缓存 对话历史记录
return "<h1>人类这不是你该来的地方</h1>"
@app.route('/generate_answer', methods=("GET", "POST"))
def stream1():
if request.method == "POST":
role = request.json["role"]
uuid = request.json["uuid"]
query = request.json["query"]
ip_address = request.remote_addr
title = GenAnswerOfRole(uuid, role)
answer = title.query_to_role(query)
app.logger.info(f'ip地址为 {ip_address}\tuuid为 {uuid}\t作为 {role}\t回答了 {query} 回答是:{answer} ')
return Response(answer, mimetype='application/octet-stream')
if __name__ == '__main__':
# app.run(host='0.0.0.0', port=16000, debug=False, threaded=True)
server = pywsgi.WSGIServer(('0.0.0.0', 16000), app)
server.serve_forever()