forked from DeepInsight-AI/DeepBI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp2.py
125 lines (98 loc) · 4.05 KB
/
app2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import tornado.ioloop
import tornado.web
import json
from ai.backend.chat_task import ChatClass
from ai.backend.aidb.autopilot.autopilot_mysql_api import AutopilotMysql
from ai.backend.aidb.autopilot.autopilot_starrocks_api import AutopilotStarrocks
from ai.backend.aidb.autopilot.autopilot_mongodb_api import AutopilotMongoDB
from ai.backend.aidb.autopilot.autopilot_csv_api import AutopilotCSV
from ai.backend.base_config import CONFIG
from ai.backend.aidb.dashboard.prettify_dashboard import PrettifyDashboard
class MainHandler(tornado.web.RequestHandler):
async def post(self):
data = json.loads(self.request.body.decode('utf-8'))
# 异步处理接收到的数据
await self.process_data(data)
# 返回响应
self.write("POST request handled asynchronously in main thread")
async def process_data(self, data):
# 在这里异步处理接收到的数据,例如打印或执行其他操作
print("Received data:", data)
# 模拟异步处理
print("Data processed asynchronously")
print('data: ', data)
user_name = data['user_name']
report_id = data['report_id']
file_name = data['file_name']
report_file_name = CONFIG.up_file_path + file_name
with open(report_file_name, 'r') as file:
data = json.load(file)
databases_type = 'mysql'
if data.get('databases_type') is not None:
databases_type = data['databases_type']
chat_class = ChatClass(None, user_name)
json_str = {
"file_name": file_name,
"report_id": report_id
}
if databases_type == 'starrocks':
autopilot_starrocks = AutopilotStarrocks(chat_class)
await autopilot_starrocks.deal_question(json_str)
elif "mongodb" == databases_type:
autopilot_mongodb = AutopilotMongoDB(chat_class)
# new db
await autopilot_mongodb.deal_question(json_str)
elif "csv" == databases_type:
autopilot_csv = AutopilotCSV(chat_class)
await autopilot_csv.deal_question(json_str)
else:
autopilotMysql = AutopilotMysql(chat_class)
await autopilotMysql.deal_question(json_str)
class DashboardHandler(tornado.web.RequestHandler):
def get(self, page_name):
print("view html :", page_name)
if str(page_name).endswith('.html'):
self.render(f"{page_name}")
async def post(self):
data = json.loads(self.request.body.decode('utf-8'))
print('/api/dashboard data : ', data)
# 异步处理接收到的数据
await self.process_data(data)
# 返回响应
self.write("POST request handled asynchronously in main thread")
async def process_data(self, data):
# 在这里异步处理接收到的数据,例如打印或执行其他操作
print("Received data:", data)
# 模拟异步处理
print("Data processed asynchronously")
user_name = data['user_name']
task_id = data['task_id']
file_name = data['file_name']
chat_class = ChatClass(None, user_name)
prettifyDashboard = PrettifyDashboard(chat_class)
json_str = {
"file_name": file_name,
"task_id": task_id
}
await prettifyDashboard.deal_question(json_str)
def make_app():
return tornado.web.Application([
(r"/api/autopilot", MainHandler),
(r"/api/dashboard", DashboardHandler),
])
class CustomApplication(tornado.web.Application):
def __init__(self):
handlers = [
(r"/api/autopilot", MainHandler),
(r"/api/dashboard", DashboardHandler),
(r"/api/dashboard/(.*)", DashboardHandler),
]
print('template_path :', CONFIG.up_file_path)
settings = {
"template_path": CONFIG.up_file_path, # 指定模板路径
}
super().__init__(handlers, **settings)
# if __name__ == "__main__":
# app = make_app()
# app.listen(8340)
# tornado.ioloop.IOLoop.current().start()