Spaces:
Sleeping
Sleeping
kltn20133118
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -1,336 +1,332 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException, Depends, Request
|
2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
3 |
-
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
4 |
-
from controller import LoginController, FileController, MySQLController,
|
5 |
-
import firebase_admin
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
10 |
-
from
|
11 |
-
from
|
12 |
-
from
|
13 |
-
from
|
14 |
-
from
|
15 |
-
from
|
16 |
-
from
|
17 |
-
from
|
18 |
-
from
|
19 |
-
from fastapi
|
20 |
-
from
|
21 |
-
import
|
22 |
-
from
|
23 |
-
from
|
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 |
-
def
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
return
|
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 |
-
if
|
116 |
-
|
117 |
-
|
118 |
-
if
|
119 |
-
raise HTTPException(status_code=400, detail="
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
if
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
chat_id
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
return res.ReponseError(status=400,
|
150 |
-
data=res.Message(message="
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
if
|
178 |
-
return res.ReponseError(status=400,
|
179 |
-
data=res.Message(message="
|
180 |
-
if
|
181 |
-
return res.ReponseError(status=400,
|
182 |
-
data=res.Message(message="
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
if
|
197 |
-
return res.ReponseError(status=400,
|
198 |
-
data=res.Message(message="
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
"/api/
|
295 |
-
"/api/
|
296 |
-
"/api/
|
297 |
-
"/api/
|
298 |
-
"/api/
|
299 |
-
"/api/
|
300 |
-
"/api/
|
301 |
-
"/api/
|
302 |
-
"/api/
|
303 |
-
"/api/
|
304 |
-
"/api/
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
]
|
319 |
-
|
320 |
-
app.add_api_route("/api/
|
321 |
-
app.add_api_route("/api/
|
322 |
-
app.add_api_route("/api/
|
323 |
-
app.add_api_route("/api/
|
324 |
-
app.add_api_route("/api/
|
325 |
-
app.add_api_route("/api/
|
326 |
-
app.add_api_route("/api/file/
|
327 |
-
|
328 |
-
app.add_api_route("/api/
|
329 |
-
app.add_api_route("/api/
|
330 |
-
app.add_api_route("/api/
|
331 |
-
app.add_api_route("/api/
|
332 |
-
app.add_api_route("/api/chat/chatbot/query/",override_handle_query2_upgrade_old,methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
333 |
-
app.add_api_route("/api/chat/chatbot/extract_file/",override_extract_file,methods=["GET"],dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
334 |
-
app.add_api_route("/api/chat/chatbot/generate_question/",override_generate_question,methods=["GET"],dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
335 |
-
app.add_api_route("/api/default/upload_image/",override_upload_image,methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["Default"])
|
336 |
app.include_router(OTPController.router, tags = ["OTP"], prefix="/api/otp")
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, Depends, Request
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
4 |
+
from controller import LoginController, FileController, MySQLController, DefaultController, OTPController
|
5 |
+
import firebase_admin
|
6 |
+
from controller import ChatController
|
7 |
+
from firebase_admin import credentials
|
8 |
+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
9 |
+
from service import MySQLService,LoginService,ChatService
|
10 |
+
from request import RequestMySQL,RequestLogin,RequestDefault
|
11 |
+
from auth.authentication import decodeJWT
|
12 |
+
from repository import UserRepository
|
13 |
+
from auth import authentication
|
14 |
+
from datetime import datetime, timedelta
|
15 |
+
from fastapi import Depends, HTTPException, Form, File, UploadFile
|
16 |
+
from typing import List
|
17 |
+
from service import FileService,DefaultService,LoginService
|
18 |
+
from request import RequestFile,RequestChat,RequestDefault
|
19 |
+
from fastapi import FastAPI, Request, HTTPException
|
20 |
+
from fastapi.responses import JSONResponse
|
21 |
+
from pydantic.error_wrappers import ErrorWrapper
|
22 |
+
from fastapi import Query
|
23 |
+
from typing import Optional
|
24 |
+
import json
|
25 |
+
from function import support_function
|
26 |
+
from response import ResponseDefault as res
|
27 |
+
|
28 |
+
app = FastAPI(
|
29 |
+
title="ChatBot HCMUTE",
|
30 |
+
description="Python ChatBot is intended for use in the topic Customizing chatbots. With the construction of 2 students Vo Nhu Y - 20133118 and Nguyen Quang Phuc 20133080",
|
31 |
+
swagger_ui_parameters={"syntaxHighlight.theme": "obsidian"},
|
32 |
+
version="1.0.0",
|
33 |
+
contact={
|
34 |
+
"name": "Vo Nhu Y",
|
35 |
+
"url": "https://pychatbot1.streamlit.app",
|
36 |
+
"email": "vonhuy5112002@gmail.com",
|
37 |
+
},
|
38 |
+
license_info={
|
39 |
+
"name": "Apache 2.0",
|
40 |
+
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
|
41 |
+
}
|
42 |
+
)
|
43 |
+
origins = [
|
44 |
+
"http://localhost:9090",
|
45 |
+
]
|
46 |
+
|
47 |
+
app.add_middleware(
|
48 |
+
CORSMiddleware,
|
49 |
+
allow_origins=origins,
|
50 |
+
allow_credentials=True,
|
51 |
+
allow_methods=["*"],
|
52 |
+
allow_headers=["*"],
|
53 |
+
)
|
54 |
+
ALLOWED_EXTENSIONS = {'csv', 'txt', 'doc', 'docx', 'pdf', 'xlsx', 'pptx', 'json', 'md', 'xlsx'}
|
55 |
+
|
56 |
+
def allowed_file(filename):
|
57 |
+
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
58 |
+
|
59 |
+
if not firebase_admin._apps:
|
60 |
+
cred = credentials.Certificate("firebase_certificate.json")
|
61 |
+
fred = firebase_admin.initialize_app(cred)
|
62 |
+
|
63 |
+
class JWTBearer(HTTPBearer):
|
64 |
+
def __init__(self, auto_error: bool = True):
|
65 |
+
super(JWTBearer, self).__init__(auto_error=auto_error)
|
66 |
+
|
67 |
+
async def __call__(self, request: Request):
|
68 |
+
credentials: HTTPAuthorizationCredentials = await super(JWTBearer, self).__call__(request)
|
69 |
+
if credentials:
|
70 |
+
if credentials.scheme != "Bearer":
|
71 |
+
raise HTTPException(status_code=403, detail="Invalid authentication scheme.")
|
72 |
+
if not self.verify_accesstoken(credentials.credentials):
|
73 |
+
raise HTTPException(status_code=403, detail="Token does not exist")
|
74 |
+
if not self.verify_jwt(credentials.credentials):
|
75 |
+
raise HTTPException(status_code=403, detail="Invalid token or expired token.")
|
76 |
+
return credentials.credentials
|
77 |
+
else:
|
78 |
+
raise HTTPException(status_code=401, detail="Invalid authorization code.")
|
79 |
+
|
80 |
+
def verify_accesstoken(self, jwtoken: str) -> bool:
|
81 |
+
check = LoginService.check_token_is_valid(jwtoken)
|
82 |
+
return check
|
83 |
+
def verify_jwt(self, jwtoken: str) -> bool:
|
84 |
+
try:
|
85 |
+
payload = decodeJWT(jwtoken)
|
86 |
+
email_encode = payload.get('sub')
|
87 |
+
self.email = authentication.str_decode(email_encode)
|
88 |
+
return True
|
89 |
+
except Exception as e:
|
90 |
+
print(e)
|
91 |
+
return False
|
92 |
+
|
93 |
+
def get_current_user_email(credentials: str = Depends(JWTBearer())):
|
94 |
+
try:
|
95 |
+
payload = decodeJWT(credentials)
|
96 |
+
email_encode = payload.get('sub')
|
97 |
+
email = authentication.str_decode(email_encode)
|
98 |
+
return email
|
99 |
+
except Exception as e:
|
100 |
+
print(e)
|
101 |
+
raise HTTPException(status_code=403, detail="Invalid token or expired token.")
|
102 |
+
|
103 |
+
@app.get("/api/mysql/render_chat_history",dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
104 |
+
async def override_render_chat(user_id: Optional[str] = Query(None), current_user_email: str = Depends(get_current_user_email)):
|
105 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
106 |
+
if check is not True:
|
107 |
+
return check
|
108 |
+
request = RequestMySQL.RequestRenderChatHistory(user_id=user_id)
|
109 |
+
return MySQLService.render_chat_history(request)
|
110 |
+
|
111 |
+
@app.put("/api/mysql/edit_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
112 |
+
async def override_edit_chat(request: RequestMySQL.RequestEditNameChat, current_user_email: str = Depends(get_current_user_email)):
|
113 |
+
user_id = request.user_id
|
114 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
115 |
+
if check is not True:
|
116 |
+
return check
|
117 |
+
name_new = request.name_new
|
118 |
+
if name_new is None or name_new.strip() == "":
|
119 |
+
raise HTTPException(status_code=400, detail="name_new field is required.")
|
120 |
+
name_old = request.name_old
|
121 |
+
if name_old is None or name_old.strip() == "":
|
122 |
+
raise HTTPException(status_code=400, detail="name_old field is required.")
|
123 |
+
return MySQLService.edit_chat(request)
|
124 |
+
|
125 |
+
@app.delete("/api/mysql/delete_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
126 |
+
async def override_delete_chat(request: RequestMySQL.RequestDeleteChat, current_user_email: str = Depends(get_current_user_email)):
|
127 |
+
user_id = request.user_id
|
128 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
129 |
+
if check is not True:
|
130 |
+
return check
|
131 |
+
chat_name= request.chat_name
|
132 |
+
if chat_name is None or chat_name.strip() == "":
|
133 |
+
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
134 |
+
return MySQLService.delete_chat(request)
|
135 |
+
|
136 |
+
|
137 |
+
@app.get("/api/mysql/load_chat_history",dependencies=[Depends(JWTBearer())] ,tags=["MySQL"])
|
138 |
+
async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Optional[str] = Query(None), current_user_email: str = Depends(get_current_user_email)):
|
139 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
140 |
+
if check is not True:
|
141 |
+
return check
|
142 |
+
if chat_id is None or chat_id.strip() == "":
|
143 |
+
return res.ReponseError(status=400,
|
144 |
+
data=res.Message(message="chat_id field is required."))
|
145 |
+
chat_id = chat_id.strip("'").strip('"')
|
146 |
+
try:
|
147 |
+
chat_id_int = int(chat_id)
|
148 |
+
except ValueError:
|
149 |
+
return res.ReponseError(status=400,
|
150 |
+
data=res.Message(message="chat_id must be an integer"))
|
151 |
+
if not support_function.is_positive_integer(chat_id_int):
|
152 |
+
return res.ReponseError(status=400,
|
153 |
+
data=res.Message(message="chat_id must be greater than 0"))
|
154 |
+
request = RequestMySQL.RequestLoadChatHistory(chat_id=chat_id,user_id = user_id)
|
155 |
+
return MySQLService.load_chat_history(request)
|
156 |
+
|
157 |
+
@app.get("/api/default/info_user",dependencies=[Depends(JWTBearer())], tags=["Default"])
|
158 |
+
async def override_get_user(user_id: str = Query(None),current_user_email: str = Depends(get_current_user_email)):
|
159 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
160 |
+
if check is not True:
|
161 |
+
return check
|
162 |
+
request = RequestDefault.RequestInfoUser(user_id=user_id)
|
163 |
+
return DefaultService.info_user(request)
|
164 |
+
|
165 |
+
@app.post("/api/users/update_user_info", dependencies=[Depends(JWTBearer())], tags=["Login"])
|
166 |
+
async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo, current_user_email: str = Depends(get_current_user_email)):
|
167 |
+
user_id = request.user_id
|
168 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
169 |
+
if check != True:
|
170 |
+
return check
|
171 |
+
uid = request.uid
|
172 |
+
email = request.email
|
173 |
+
display_name = request.display_name
|
174 |
+
photo_url = request.photo_url
|
175 |
+
if uid is None or uid.strip() == "":
|
176 |
+
raise HTTPException(status_code=400, detail="uid field is required.")
|
177 |
+
if email is None or email.strip() == "":
|
178 |
+
return res.ReponseError(status=400,
|
179 |
+
data=res.Message(message="email field is required."))
|
180 |
+
if display_name is None or display_name.strip() == "":
|
181 |
+
return res.ReponseError(status=400,
|
182 |
+
data=res.Message(message="display_name field is required."))
|
183 |
+
if photo_url is None or photo_url.strip() == "":
|
184 |
+
return res.ReponseError(status=400,
|
185 |
+
data=res.Message(message="photo_url field is required."))
|
186 |
+
return LoginService.update_user_info(request)
|
187 |
+
|
188 |
+
@app.put('/api/users/change_password', dependencies=[Depends(JWTBearer())], tags=["Login"])
|
189 |
+
async def override_reset_password_firebase(request: RequestLogin.RequestChangePassword, current_user_email: str = Depends(get_current_user_email)):
|
190 |
+
user_id = request.user_id
|
191 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
192 |
+
if check != True:
|
193 |
+
return check
|
194 |
+
new_password = request.new_password
|
195 |
+
current_password = request.current_password
|
196 |
+
if new_password is None or new_password.strip() == "":
|
197 |
+
return res.ReponseError(status=400,
|
198 |
+
data=res.Message(message="new_password field is required."))
|
199 |
+
if current_password is None or current_password.strip() == "":
|
200 |
+
return res.ReponseError(status=400,
|
201 |
+
data=res.Message(message="current_password field is required."))
|
202 |
+
return LoginService.change_password(request)
|
203 |
+
@app.delete("/api/file/delete_all_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
204 |
+
async def override_delete_folder(request: RequestFile.RequestDeleteAllFile, current_user_email: str = Depends(get_current_user_email)):
|
205 |
+
check = support_function.check_value_user_id(request.user_id, current_user_email)
|
206 |
+
if check != True:
|
207 |
+
return check
|
208 |
+
return FileService.deleteAllFile(request)
|
209 |
+
@app.delete("/api/file/delete_one_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
210 |
+
async def override_delete_one_file(request: RequestFile.RequestDeleteFile, current_user_email: str = Depends(get_current_user_email)):
|
211 |
+
user_id = request.user_id
|
212 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
213 |
+
if check != True:
|
214 |
+
return check
|
215 |
+
name_file = request.name_file
|
216 |
+
if name_file is None or name_file.strip() == "":
|
217 |
+
return res.ReponseError(status=400,
|
218 |
+
data=res.Message(message="name_file is required."))
|
219 |
+
return FileService.deleteFile(request)
|
220 |
+
|
221 |
+
@app.post("/api/file/chatbot/download_folder/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
222 |
+
async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder, current_user_email: str = Depends(get_current_user_email)):
|
223 |
+
user_id = request.user_id
|
224 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
225 |
+
if check is not True:
|
226 |
+
return check
|
227 |
+
return FileService.download_folder(request)
|
228 |
+
|
229 |
+
@app.post("/api/file/chatbot/download_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
230 |
+
async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile, current_user_email: str = Depends(get_current_user_email)):
|
231 |
+
user_id = request.user_id
|
232 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
233 |
+
if check is not True:
|
234 |
+
return check
|
235 |
+
return FileService.download_file(request)
|
236 |
+
|
237 |
+
@app.post("/api/file/upload_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
|
238 |
+
async def override_upload_files_dropbox(
|
239 |
+
user_id: str = Form(None),
|
240 |
+
files: List[UploadFile] = File(None),
|
241 |
+
current_user_email: str = Depends(get_current_user_email)
|
242 |
+
):
|
243 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
244 |
+
if check is not True:
|
245 |
+
return check
|
246 |
+
request = RequestFile.RequestUploadFile(files=files, user_id=user_id)
|
247 |
+
return FileService.upload_files(request)
|
248 |
+
|
249 |
+
@app.post("/api/chat/chatbot/query/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
250 |
+
async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...), question: str = Form(None), chat_name: str = Form(None), current_user_email: str = Depends(get_current_user_email)):
|
251 |
+
check = support_function.check_value_user_id(user_id, current_user_email)
|
252 |
+
if check is not True:
|
253 |
+
return check
|
254 |
+
request = RequestChat.RequestQuery2UpgradeOld(user_id=user_id, text_all=text_all, question=question, chat_name=chat_name)
|
255 |
+
return ChatService.query2_upgrade_old(request)
|
256 |
+
|
257 |
+
@app.get("/api/chat/chatbot/extract_file/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
258 |
+
async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
259 |
+
check = support_function.check_value_user_id(user_id,current_user_email)
|
260 |
+
if check is not True:
|
261 |
+
return check
|
262 |
+
request = RequestChat.RequestExtractFile(user_id=user_id)
|
263 |
+
return ChatService.extract_file(request)
|
264 |
+
|
265 |
+
@app.get("/api/chat/chatbot/generate_question/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
266 |
+
async def override_generate_question(user_id: str , current_user_email: str = Depends(get_current_user_email)):
|
267 |
+
check = support_function.check_value_user_id(user_id,current_user_email)
|
268 |
+
if check is not True:
|
269 |
+
return check
|
270 |
+
request = RequestChat.RequestGenerateQuestion(user_id=user_id)
|
271 |
+
return ChatService.generate_question(request)
|
272 |
+
|
273 |
+
@app.post("/api/default/upload_image/", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
274 |
+
async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),current_user_email: str = Depends(get_current_user_email)):
|
275 |
+
check = support_function.check_value_user_id(user_id,current_user_email)
|
276 |
+
if check is not True:
|
277 |
+
return check
|
278 |
+
request = RequestDefault.RequestUpLoadImage(user_id=user_id, files=file)
|
279 |
+
return DefaultService.upload_image_service(request)
|
280 |
+
|
281 |
+
app.include_router(MySQLController.router, prefix="/api/mysql")
|
282 |
+
app.include_router(LoginController.router, prefix="/api/users")
|
283 |
+
app.include_router(FileController.router, prefix="/api/file")
|
284 |
+
app.include_router(ChatController.router, prefix="/api/chat")
|
285 |
+
app.include_router(DefaultController.router, prefix="/api/default")
|
286 |
+
|
287 |
+
routes_to_override = {
|
288 |
+
"/api/mysql/render_chat_history": {"GET"},
|
289 |
+
"/api/mysql/load_chat_history": {"GET"},
|
290 |
+
"/api/mysql/edit_chat/": {"PUT"},
|
291 |
+
"/api/mysql/delete_chat/": {"DELETE"},
|
292 |
+
"/api/users/update_user_info": {"POST"},
|
293 |
+
"/api/users/change_password": {"PUT"},
|
294 |
+
"/api/file/delete_all_file/": {"DELETE"},
|
295 |
+
"/api/file/delete_one_file/": {"DELETE"},
|
296 |
+
"/api/file/chatbot/download_folder/": {"POST"},
|
297 |
+
"/api/file/chatbot/download_files/": {"POST"},
|
298 |
+
"/api/file/upload_files/": {"POST"},
|
299 |
+
"/api/chat/query2_upgrade/": {"POST"},
|
300 |
+
"/api/chat/chatbot/query/": {"POST"},
|
301 |
+
"/api/chat/chatbot/extract_file/": {"GET"},
|
302 |
+
"/api/chat/chatbot/generate_question/": {"GET"},
|
303 |
+
"/api/default/upload_image/": {"POST"},
|
304 |
+
"/api/default/info_user": {"GET"}
|
305 |
+
|
306 |
+
}
|
307 |
+
|
308 |
+
app.router.routes = [
|
309 |
+
route for route in app.router.routes
|
310 |
+
if not (
|
311 |
+
route.path in routes_to_override and
|
312 |
+
route.methods.intersection(routes_to_override[route.path])
|
313 |
+
)
|
314 |
+
]
|
315 |
+
|
316 |
+
app.add_api_route("/api/mysql/render_chat_history", override_render_chat, methods=["GET"], dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
317 |
+
app.add_api_route("/api/mysql/load_chat_history/", override_load_chat, methods=["GET"], dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
318 |
+
app.add_api_route("/api/mysql/edit_chat/", override_edit_chat, methods=["PUT"], dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
319 |
+
app.add_api_route("/api/mysql/delete_chat/", override_delete_chat, methods=["DELETE"], dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
320 |
+
app.add_api_route("/api/users/update_user_info", override_update_user_info, methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["Login"])
|
321 |
+
app.add_api_route("/api/users/change_password", override_reset_password_firebase, methods=["PUT"],dependencies=[Depends(JWTBearer())], tags=["Login"])
|
322 |
+
app.add_api_route("/api/file/delete_all_file/", override_delete_folder, methods=["DELETE"],dependencies=[Depends(JWTBearer())], tags=["File"])
|
323 |
+
app.add_api_route("/api/file/delete_one_file/", override_delete_one_file, methods=["DELETE"],dependencies=[Depends(JWTBearer())], tags=["File"])
|
324 |
+
app.add_api_route("/api/file/chatbot/download_folder/", override_download_folder_from_dropbox, methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["File"])
|
325 |
+
app.add_api_route("/api/file/chatbot/download_files/", override_download_file_by_id, methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["File"])
|
326 |
+
app.add_api_route("/api/file/upload_files/", override_upload_files_dropbox, methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["File"])
|
327 |
+
app.add_api_route("/api/chat/chatbot/query/", override_handle_query2_upgrade_old, methods=["POST"],dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
328 |
+
app.add_api_route("/api/chat/chatbot/extract_file/", override_extract_file, methods=["GET"], dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
329 |
+
app.add_api_route("/api/chat/chatbot/generate_question/", override_generate_question,methods=["GET"], dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
330 |
+
app.add_api_route("/api/default/upload_image/", override_upload_image, methods=["POST"], dependencies=[Depends(JWTBearer())], tags=["Default"])
|
331 |
+
app.add_api_route("/api/default/info_user",override_get_user, methods=["GET"], dependencies=[Depends(JWTBearer())], tags=["Default"])
|
|
|
|
|
|
|
|
|
332 |
app.include_router(OTPController.router, tags = ["OTP"], prefix="/api/otp")
|