Spaces:
Sleeping
Sleeping
kltn20133118
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -24,7 +24,8 @@ 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",
|
@@ -41,7 +42,8 @@ app = FastAPI(
|
|
41 |
}
|
42 |
)
|
43 |
origins = [
|
44 |
-
"
|
|
|
45 |
]
|
46 |
|
47 |
app.add_middleware(
|
@@ -51,8 +53,7 @@ app.add_middleware(
|
|
51 |
allow_methods=["*"],
|
52 |
allow_headers=["*"],
|
53 |
)
|
54 |
-
ALLOWED_EXTENSIONS = {'csv', 'txt', 'doc', 'docx', 'pdf', 'xlsx', 'pptx', 'json', 'md'
|
55 |
-
|
56 |
|
57 |
def allowed_file(filename):
|
58 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
@@ -62,7 +63,6 @@ if not firebase_admin._apps:
|
|
62 |
cred = credentials.Certificate("firebase_certificate.json")
|
63 |
fred = firebase_admin.initialize_app(cred)
|
64 |
|
65 |
-
|
66 |
class JWTBearer(HTTPBearer):
|
67 |
def __init__(self, auto_error: bool = True):
|
68 |
super(JWTBearer, self).__init__(auto_error=auto_error)
|
@@ -112,7 +112,28 @@ async def override_render_chat(user_id: str,
|
|
112 |
if check is not True:
|
113 |
return check
|
114 |
request = RequestMySQL.RequestRenderChatHistory(user_id=user_id)
|
115 |
-
return MySQLService.render_chat_history(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
@app.put("/api/v1/mysql/edit_chat", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
118 |
async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
|
@@ -127,7 +148,7 @@ async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
|
|
127 |
name_old = request.name_old
|
128 |
if name_old is None or name_old.strip() == "":
|
129 |
raise HTTPException(status_code=400, detail="name_old field is required.")
|
130 |
-
return MySQLService.edit_chat(request)
|
131 |
|
132 |
@app.delete("/api/v1/mysql/chat_history/delete", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
133 |
async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
|
@@ -139,7 +160,7 @@ async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
|
|
139 |
chat_name = request.chat_name
|
140 |
if chat_name is None or chat_name.strip() == "":
|
141 |
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
142 |
-
return MySQLService.delete_chat(request)
|
143 |
|
144 |
@app.delete("/api/v1/mysql/detail_chat/delete", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
145 |
async def override_delete_detail_chat_detail(request: RequestMySQL.RequestDeleteDetailChat,
|
@@ -151,7 +172,7 @@ async def override_delete_detail_chat_detail(request: RequestMySQL.RequestDelete
|
|
151 |
id_chat_detail = request.id_chat_detail
|
152 |
if id_chat_detail is None or id_chat_detail.strip() == "":
|
153 |
raise HTTPException(status_code=400, detail="id_chat_detail field is required.")
|
154 |
-
return MySQLService.delete_chat_detail_by_id(request)
|
155 |
|
156 |
@app.get("/api/v1/mysql/detail_chat/{user_id}/{chat_id}", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
157 |
async def override_load_chat(chat_id: str, user_id: str,
|
@@ -172,7 +193,7 @@ async def override_load_chat(chat_id: str, user_id: str,
|
|
172 |
return res.ReponseError(status=400,
|
173 |
data=res.Message(message="chat_id must be greater than 0"))
|
174 |
request = RequestMySQL.RequestLoadChatHistory(chat_id=chat_id, user_id=user_id)
|
175 |
-
return MySQLService.load_chat_history(request)
|
176 |
|
177 |
|
178 |
@app.get("/api/v1/default/info_user/{user_id}", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
@@ -181,10 +202,10 @@ async def override_get_user(user_id: str , current_user_email: str = Depends(get
|
|
181 |
if check is not True:
|
182 |
return check
|
183 |
request = RequestDefault.RequestInfoUser(user_id=user_id)
|
184 |
-
return DefaultService.info_user(request)
|
185 |
|
186 |
|
187 |
-
@app.
|
188 |
async def override_update_user_info(request: RequestUser.RequestUpdateUserInfo,
|
189 |
current_user_email: str = Depends(get_current_user_email)):
|
190 |
user_id = request.user_id
|
@@ -206,8 +227,7 @@ async def override_update_user_info(request: RequestUser.RequestUpdateUserInfo,
|
|
206 |
if photo_url is None or photo_url.strip() == "":
|
207 |
return res.ReponseError(status=400,
|
208 |
data=res.Message(message="photo_url field is required."))
|
209 |
-
return UserService.update_user_info(request)
|
210 |
-
|
211 |
|
212 |
@app.put('/api/v1/users/change_password', dependencies=[Depends(JWTBearer())], tags=["User"])
|
213 |
async def override_reset_password_firebase(request: RequestUser.RequestChangePassword,
|
@@ -230,7 +250,7 @@ async def override_reset_password_firebase(request: RequestUser.RequestChangePas
|
|
230 |
return res.ReponseError(status=400,
|
231 |
data=res.Message(message="confirm_new_password field is required."))
|
232 |
|
233 |
-
return UserService.change_password(request)
|
234 |
|
235 |
@app.delete("/api/v1/file/delete", dependencies=[Depends(JWTBearer())], tags=["File"])
|
236 |
async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
|
@@ -238,7 +258,7 @@ async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
|
|
238 |
check = support_function.check_value_user_id(request.user_id, current_user_email)
|
239 |
if check != True:
|
240 |
return check
|
241 |
-
return FileService.deleteAllFile(request)
|
242 |
|
243 |
@app.delete("/api/v1/file/delete_file", dependencies=[Depends(JWTBearer())], tags=["File"])
|
244 |
async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
|
@@ -251,8 +271,7 @@ async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
|
|
251 |
if name_file is None or name_file.strip() == "":
|
252 |
return res.ReponseError(status=400,
|
253 |
data=res.Message(message="name_file is required."))
|
254 |
-
return FileService.deleteFile(request)
|
255 |
-
|
256 |
|
257 |
@app.post("/api/v1/file/chatbot/download_folder", dependencies=[Depends(JWTBearer())], tags=["File"])
|
258 |
async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder,
|
@@ -261,8 +280,7 @@ async def override_download_folder_from_dropbox(request: RequestFile.RequestDown
|
|
261 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
262 |
if check is not True:
|
263 |
return check
|
264 |
-
return FileService.download_folder(request)
|
265 |
-
|
266 |
|
267 |
@app.post("/api/v1/file/chatbot/download_files", dependencies=[Depends(JWTBearer())], tags=["File"])
|
268 |
async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
|
@@ -271,8 +289,7 @@ async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
|
|
271 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
272 |
if check is not True:
|
273 |
return check
|
274 |
-
return FileService.download_file(request)
|
275 |
-
|
276 |
|
277 |
@app.post("/api/v1/file/upload_files", dependencies=[Depends(JWTBearer())], tags=["File"])
|
278 |
async def override_upload_files_dropbox(
|
@@ -283,9 +300,12 @@ async def override_upload_files_dropbox(
|
|
283 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
284 |
if check is not True:
|
285 |
return check
|
|
|
|
|
|
|
|
|
286 |
request = RequestFile.RequestUploadFile(files=files, user_id=user_id)
|
287 |
-
return FileService.upload_files(request)
|
288 |
-
|
289 |
|
290 |
@app.post("/api/v1/chat/chatbot/query", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
291 |
async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...),
|
@@ -296,8 +316,7 @@ async def override_handle_query2_upgrade_old(request: Request, user_id: str = Fo
|
|
296 |
return check
|
297 |
request = RequestChat.RequestQuery2UpgradeOld(user_id=user_id, text_all=text_all, question=question,
|
298 |
chat_name=chat_name)
|
299 |
-
return ChatService.query2_upgrade_old(request)
|
300 |
-
|
301 |
|
302 |
@app.get("/api/v1/chat/chatbot/extract_file/{user_id}", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
303 |
async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
@@ -305,8 +324,7 @@ async def override_extract_file(user_id: str, current_user_email: str = Depends(
|
|
305 |
if check is not True:
|
306 |
return check
|
307 |
request = RequestChat.RequestExtractFile(user_id=user_id)
|
308 |
-
return ChatService.extract_file(request)
|
309 |
-
|
310 |
|
311 |
@app.get("/api/v1/chat/chatbot/generate_question/{user_id}", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
312 |
async def override_generate_question(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
@@ -314,17 +332,18 @@ async def override_generate_question(user_id: str, current_user_email: str = Dep
|
|
314 |
if check is not True:
|
315 |
return check
|
316 |
request = RequestChat.RequestGenerateQuestion(user_id=user_id)
|
317 |
-
return ChatService.generate_question(request)
|
318 |
|
319 |
-
|
320 |
-
@app.post("/api/v1/default/upload_images", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
321 |
async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),
|
322 |
current_user_email: str = Depends(get_current_user_email)):
|
|
|
|
|
323 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
324 |
if check is not True:
|
325 |
return check
|
326 |
request = RequestDefault.RequestUpLoadImage(user_id=user_id, files=file)
|
327 |
-
return DefaultService.upload_image_service(request)
|
328 |
|
329 |
app.include_router(AuthenticationController.router, tags=["Authentication"], prefix="/api/v1/auth")
|
330 |
app.include_router(MySQLController.router, prefix="/api/v1/mysql")
|
@@ -338,7 +357,7 @@ routes_to_override = {
|
|
338 |
"/api/v1/mysql/detail_chat/{user_id}/{chat_id}": {"GET"},
|
339 |
"/api/v1/mysql/edit_chat": {"PUT"},
|
340 |
"/api/v1/mysql/chat_history/delete": {"DELETE"},
|
341 |
-
"/api/v1/users/update_user_info": {"
|
342 |
"/api/v1/users/change_password": {"PUT"},
|
343 |
"/api/v1/file/delete": {"DELETE"},
|
344 |
"/api/v1/file/delete_file": {"DELETE"},
|
@@ -348,9 +367,11 @@ routes_to_override = {
|
|
348 |
"/api/v1/chat/chatbot/query": {"POST"},
|
349 |
"/api/v1/chat/chatbot/extract_file/{user_id}": {"GET"},
|
350 |
"/api/v1/chat/chatbot/generate_question/{user_id}": {"GET"},
|
351 |
-
"/api/v1/default/
|
352 |
"/api/v1/default/info_user/{user_id}": {"GET"},
|
353 |
-
"/api/v1/mysql/detail_chat/delete":{"DELETE"}
|
|
|
|
|
354 |
}
|
355 |
|
356 |
app.router.routes = [
|
@@ -367,11 +388,15 @@ app.add_api_route("/api/v1/mysql/detail_chat/{user_id}/{chat_id}", override_load
|
|
367 |
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
368 |
app.add_api_route("/api/v1/mysql/edit_chat", override_edit_chat, methods=["PUT"], dependencies=[Depends(JWTBearer())],
|
369 |
tags=["MySQL"])
|
|
|
|
|
370 |
app.add_api_route("/api/v1/mysql/chat_history/delete", override_delete_chat, methods=["DELETE"],
|
371 |
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
|
|
|
|
372 |
app.add_api_route("/api/v1/mysql/detail_chat/delete", override_delete_detail_chat_detail, methods=["DELETE"],
|
373 |
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
374 |
-
app.add_api_route("/api/v1/users/update_user_info", override_update_user_info, methods=["
|
375 |
dependencies=[Depends(JWTBearer())], tags=["User"])
|
376 |
app.add_api_route("/api/v1/users/change_password", override_reset_password_firebase, methods=["PUT"],
|
377 |
dependencies=[Depends(JWTBearer())], tags=["User"])
|
@@ -391,7 +416,7 @@ app.add_api_route("/api/v1/chat/chatbot/extract_file/{user_id}", override_extrac
|
|
391 |
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
392 |
app.add_api_route("/api/v1/chat/chatbot/generate_question/{user_id}", override_generate_question, methods=["GET"],
|
393 |
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
394 |
-
app.add_api_route("/api/v1/default/
|
395 |
dependencies=[Depends(JWTBearer())], tags=["Default"])
|
396 |
app.add_api_route("/api/v1/default/info_user/{user_id}", override_get_user, methods=["GET"], dependencies=[Depends(JWTBearer())],
|
397 |
tags=["Default"])
|
|
|
24 |
import json
|
25 |
from function import support_function
|
26 |
from response import ResponseDefault as res
|
27 |
+
import os
|
28 |
+
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
|
29 |
app = FastAPI(
|
30 |
title="ChatBot HCMUTE",
|
31 |
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",
|
|
|
42 |
}
|
43 |
)
|
44 |
origins = [
|
45 |
+
"https://kltn20133118-pychatbot.hf.space",
|
46 |
+
"https://pychatbot20133.streamlit.app"
|
47 |
]
|
48 |
|
49 |
app.add_middleware(
|
|
|
53 |
allow_methods=["*"],
|
54 |
allow_headers=["*"],
|
55 |
)
|
56 |
+
ALLOWED_EXTENSIONS = {'csv', 'txt', 'doc', 'docx', 'pdf', 'xlsx', 'pptx', 'json', 'md'}
|
|
|
57 |
|
58 |
def allowed_file(filename):
|
59 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
|
|
63 |
cred = credentials.Certificate("firebase_certificate.json")
|
64 |
fred = firebase_admin.initialize_app(cred)
|
65 |
|
|
|
66 |
class JWTBearer(HTTPBearer):
|
67 |
def __init__(self, auto_error: bool = True):
|
68 |
super(JWTBearer, self).__init__(auto_error=auto_error)
|
|
|
112 |
if check is not True:
|
113 |
return check
|
114 |
request = RequestMySQL.RequestRenderChatHistory(user_id=user_id)
|
115 |
+
return await MySQLService.render_chat_history(request)
|
116 |
+
|
117 |
+
@app.delete("/api/v1/mysql/chat_history/delete_last_chat_record",dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
118 |
+
async def override_delete_last_chat_record(request: RequestMySQL.RequestStopChat, current_user_email: str = Depends(get_current_user_email)):
|
119 |
+
user_id = request.user_id
|
120 |
+
check = support_function.check_value_user_id_controller(user_id)
|
121 |
+
if check is not True:
|
122 |
+
return check
|
123 |
+
chat_name = request.chat_name
|
124 |
+
if chat_name is None or chat_name.strip() == "":
|
125 |
+
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
126 |
+
return await MySQLService.delete_last_chat_detail_by_chat_name(request)
|
127 |
+
|
128 |
+
@app.post("/api/v1/mysql/chat_history/create",dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
129 |
+
async def override_create_chat_history(request:RequestMySQL.RequestCreateChatHistory,current_user_email: str = Depends(get_current_user_email)):
|
130 |
+
check = support_function.check_value_user_id(request.user_id, current_user_email)
|
131 |
+
if check is not True:
|
132 |
+
return check
|
133 |
+
chat_name = request.chat_name
|
134 |
+
if chat_name is None or chat_name.strip() == "":
|
135 |
+
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
136 |
+
return await MySQLService.create_chat_history(request)
|
137 |
|
138 |
@app.put("/api/v1/mysql/edit_chat", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
139 |
async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
|
|
|
148 |
name_old = request.name_old
|
149 |
if name_old is None or name_old.strip() == "":
|
150 |
raise HTTPException(status_code=400, detail="name_old field is required.")
|
151 |
+
return await MySQLService.edit_chat(request)
|
152 |
|
153 |
@app.delete("/api/v1/mysql/chat_history/delete", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
154 |
async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
|
|
|
160 |
chat_name = request.chat_name
|
161 |
if chat_name is None or chat_name.strip() == "":
|
162 |
raise HTTPException(status_code=400, detail="chat_name field is required.")
|
163 |
+
return await MySQLService.delete_chat(request)
|
164 |
|
165 |
@app.delete("/api/v1/mysql/detail_chat/delete", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
166 |
async def override_delete_detail_chat_detail(request: RequestMySQL.RequestDeleteDetailChat,
|
|
|
172 |
id_chat_detail = request.id_chat_detail
|
173 |
if id_chat_detail is None or id_chat_detail.strip() == "":
|
174 |
raise HTTPException(status_code=400, detail="id_chat_detail field is required.")
|
175 |
+
return await MySQLService.delete_chat_detail_by_id(request)
|
176 |
|
177 |
@app.get("/api/v1/mysql/detail_chat/{user_id}/{chat_id}", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
178 |
async def override_load_chat(chat_id: str, user_id: str,
|
|
|
193 |
return res.ReponseError(status=400,
|
194 |
data=res.Message(message="chat_id must be greater than 0"))
|
195 |
request = RequestMySQL.RequestLoadChatHistory(chat_id=chat_id, user_id=user_id)
|
196 |
+
return await MySQLService.load_chat_history(request)
|
197 |
|
198 |
|
199 |
@app.get("/api/v1/default/info_user/{user_id}", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
|
|
202 |
if check is not True:
|
203 |
return check
|
204 |
request = RequestDefault.RequestInfoUser(user_id=user_id)
|
205 |
+
return await DefaultService.info_user(request)
|
206 |
|
207 |
|
208 |
+
@app.put("/api/v1/users/update_user_info", dependencies=[Depends(JWTBearer())], tags=["User"])
|
209 |
async def override_update_user_info(request: RequestUser.RequestUpdateUserInfo,
|
210 |
current_user_email: str = Depends(get_current_user_email)):
|
211 |
user_id = request.user_id
|
|
|
227 |
if photo_url is None or photo_url.strip() == "":
|
228 |
return res.ReponseError(status=400,
|
229 |
data=res.Message(message="photo_url field is required."))
|
230 |
+
return await UserService.update_user_info(request)
|
|
|
231 |
|
232 |
@app.put('/api/v1/users/change_password', dependencies=[Depends(JWTBearer())], tags=["User"])
|
233 |
async def override_reset_password_firebase(request: RequestUser.RequestChangePassword,
|
|
|
250 |
return res.ReponseError(status=400,
|
251 |
data=res.Message(message="confirm_new_password field is required."))
|
252 |
|
253 |
+
return await UserService.change_password(request)
|
254 |
|
255 |
@app.delete("/api/v1/file/delete", dependencies=[Depends(JWTBearer())], tags=["File"])
|
256 |
async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
|
|
|
258 |
check = support_function.check_value_user_id(request.user_id, current_user_email)
|
259 |
if check != True:
|
260 |
return check
|
261 |
+
return await FileService.deleteAllFile(request)
|
262 |
|
263 |
@app.delete("/api/v1/file/delete_file", dependencies=[Depends(JWTBearer())], tags=["File"])
|
264 |
async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
|
|
|
271 |
if name_file is None or name_file.strip() == "":
|
272 |
return res.ReponseError(status=400,
|
273 |
data=res.Message(message="name_file is required."))
|
274 |
+
return await FileService.deleteFile(request)
|
|
|
275 |
|
276 |
@app.post("/api/v1/file/chatbot/download_folder", dependencies=[Depends(JWTBearer())], tags=["File"])
|
277 |
async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder,
|
|
|
280 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
281 |
if check is not True:
|
282 |
return check
|
283 |
+
return await FileService.download_folder(request)
|
|
|
284 |
|
285 |
@app.post("/api/v1/file/chatbot/download_files", dependencies=[Depends(JWTBearer())], tags=["File"])
|
286 |
async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
|
|
|
289 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
290 |
if check is not True:
|
291 |
return check
|
292 |
+
return await FileService.download_file(request)
|
|
|
293 |
|
294 |
@app.post("/api/v1/file/upload_files", dependencies=[Depends(JWTBearer())], tags=["File"])
|
295 |
async def override_upload_files_dropbox(
|
|
|
300 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
301 |
if check is not True:
|
302 |
return check
|
303 |
+
for file in files:
|
304 |
+
if file.size > 15 * 1024 * 1024:
|
305 |
+
raise HTTPException(status_code=413,
|
306 |
+
detail=f"File {file.filename} too large. Maximum size allowed is 15MB.")
|
307 |
request = RequestFile.RequestUploadFile(files=files, user_id=user_id)
|
308 |
+
return await FileService.upload_files(request)
|
|
|
309 |
|
310 |
@app.post("/api/v1/chat/chatbot/query", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
311 |
async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...),
|
|
|
316 |
return check
|
317 |
request = RequestChat.RequestQuery2UpgradeOld(user_id=user_id, text_all=text_all, question=question,
|
318 |
chat_name=chat_name)
|
319 |
+
return await ChatService.query2_upgrade_old(request)
|
|
|
320 |
|
321 |
@app.get("/api/v1/chat/chatbot/extract_file/{user_id}", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
322 |
async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
|
|
324 |
if check is not True:
|
325 |
return check
|
326 |
request = RequestChat.RequestExtractFile(user_id=user_id)
|
327 |
+
return await ChatService.extract_file(request)
|
|
|
328 |
|
329 |
@app.get("/api/v1/chat/chatbot/generate_question/{user_id}", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
|
330 |
async def override_generate_question(user_id: str, current_user_email: str = Depends(get_current_user_email)):
|
|
|
332 |
if check is not True:
|
333 |
return check
|
334 |
request = RequestChat.RequestGenerateQuestion(user_id=user_id)
|
335 |
+
return await ChatService.generate_question(request)
|
336 |
|
337 |
+
@app.post("/api/v1/default/upload_image", dependencies=[Depends(JWTBearer())], tags=["Default"])
|
|
|
338 |
async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),
|
339 |
current_user_email: str = Depends(get_current_user_email)):
|
340 |
+
if file.file.size > 10 * 1024 * 1024:
|
341 |
+
raise HTTPException(status_code=413, detail="File too large")
|
342 |
check = support_function.check_value_user_id(user_id, current_user_email)
|
343 |
if check is not True:
|
344 |
return check
|
345 |
request = RequestDefault.RequestUpLoadImage(user_id=user_id, files=file)
|
346 |
+
return await DefaultService.upload_image_service(request)
|
347 |
|
348 |
app.include_router(AuthenticationController.router, tags=["Authentication"], prefix="/api/v1/auth")
|
349 |
app.include_router(MySQLController.router, prefix="/api/v1/mysql")
|
|
|
357 |
"/api/v1/mysql/detail_chat/{user_id}/{chat_id}": {"GET"},
|
358 |
"/api/v1/mysql/edit_chat": {"PUT"},
|
359 |
"/api/v1/mysql/chat_history/delete": {"DELETE"},
|
360 |
+
"/api/v1/users/update_user_info": {"PUT"},
|
361 |
"/api/v1/users/change_password": {"PUT"},
|
362 |
"/api/v1/file/delete": {"DELETE"},
|
363 |
"/api/v1/file/delete_file": {"DELETE"},
|
|
|
367 |
"/api/v1/chat/chatbot/query": {"POST"},
|
368 |
"/api/v1/chat/chatbot/extract_file/{user_id}": {"GET"},
|
369 |
"/api/v1/chat/chatbot/generate_question/{user_id}": {"GET"},
|
370 |
+
"/api/v1/default/upload_image": {"POST"},
|
371 |
"/api/v1/default/info_user/{user_id}": {"GET"},
|
372 |
+
"/api/v1/mysql/detail_chat/delete":{"DELETE"},
|
373 |
+
"/api/v1/mysql/chat_history/create": {"POST"},
|
374 |
+
"/api/v1/mysql/chat_history/delete_last_chat_record": {"DELETE"}
|
375 |
}
|
376 |
|
377 |
app.router.routes = [
|
|
|
388 |
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
389 |
app.add_api_route("/api/v1/mysql/edit_chat", override_edit_chat, methods=["PUT"], dependencies=[Depends(JWTBearer())],
|
390 |
tags=["MySQL"])
|
391 |
+
app.add_api_route("/api/v1/mysql/chat_history/create", override_create_chat_history, methods=["POST"], dependencies=[Depends(JWTBearer())],
|
392 |
+
tags=["MySQL"])
|
393 |
app.add_api_route("/api/v1/mysql/chat_history/delete", override_delete_chat, methods=["DELETE"],
|
394 |
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
395 |
+
app.add_api_route("/api/v1/mysql/chat_history/delete_last_chat_record", override_delete_last_chat_record, methods=["DELETE"],
|
396 |
+
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
397 |
app.add_api_route("/api/v1/mysql/detail_chat/delete", override_delete_detail_chat_detail, methods=["DELETE"],
|
398 |
dependencies=[Depends(JWTBearer())], tags=["MySQL"])
|
399 |
+
app.add_api_route("/api/v1/users/update_user_info", override_update_user_info, methods=["PUT"],
|
400 |
dependencies=[Depends(JWTBearer())], tags=["User"])
|
401 |
app.add_api_route("/api/v1/users/change_password", override_reset_password_firebase, methods=["PUT"],
|
402 |
dependencies=[Depends(JWTBearer())], tags=["User"])
|
|
|
416 |
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
417 |
app.add_api_route("/api/v1/chat/chatbot/generate_question/{user_id}", override_generate_question, methods=["GET"],
|
418 |
dependencies=[Depends(JWTBearer())], tags=["Chat"])
|
419 |
+
app.add_api_route("/api/v1/default/upload_image", override_upload_image, methods=["POST"],
|
420 |
dependencies=[Depends(JWTBearer())], tags=["Default"])
|
421 |
app.add_api_route("/api/v1/default/info_user/{user_id}", override_get_user, methods=["GET"], dependencies=[Depends(JWTBearer())],
|
422 |
tags=["Default"])
|