Spaces:
Runtime error
Runtime error
Commit
·
d3eb8bf
1
Parent(s):
a56ad25
fix
Browse files- routers/chat.py +4 -4
routers/chat.py
CHANGED
|
@@ -66,7 +66,7 @@ async def create_chat(
|
|
| 66 |
}
|
| 67 |
|
| 68 |
try:
|
| 69 |
-
mongo_db.conversations.insert_one(conversation_doc)
|
| 70 |
logger.info(f"Đã tạo hội thoại rỗng {chat_id} trong MongoDB cho user {current_user.email}.")
|
| 71 |
except Exception as e:
|
| 72 |
logger.error(f"Lỗi khi tạo hội thoại rỗng trong MongoDB cho chat {chat_id}: {e}", exc_info=True)
|
|
@@ -135,7 +135,7 @@ async def delete_chat(chat_id: str, request: Request, user: UserOut = Depends(ge
|
|
| 135 |
# Xóa chat
|
| 136 |
delete_chat_from_redis(redis, chat_id)
|
| 137 |
# Xóa hội thoại trong MongoDB
|
| 138 |
-
result = mongo_db.conversations.delete_one({"conversation_id": chat_id, "user_id": user.email})
|
| 139 |
if result.deleted_count == 0:
|
| 140 |
raise HTTPException(status_code=404, detail="Chat not found in MongoDB")
|
| 141 |
|
|
@@ -147,7 +147,7 @@ async def delete_chat(chat_id: str, request: Request, user: UserOut = Depends(ge
|
|
| 147 |
async def get_conversations(user: UserOut = Depends(get_current_user)):
|
| 148 |
try:
|
| 149 |
logger.info(f"Attempting to get conversations for user: {user.email}")
|
| 150 |
-
db_conversations_cursor = mongo_db.conversations.find({"user_id": user.email})
|
| 151 |
|
| 152 |
response_list = []
|
| 153 |
|
|
@@ -182,7 +182,7 @@ async def load_conversation_and_sync_redis(
|
|
| 182 |
|
| 183 |
# 1. Kiểm tra hội thoại trong MongoDB
|
| 184 |
try:
|
| 185 |
-
conversation_doc =mongo_db.conversations.find_one(
|
| 186 |
{"conversation_id": chat_id, "user_id": current_user.email}
|
| 187 |
)
|
| 188 |
if not conversation_doc:
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
try:
|
| 69 |
+
await mongo_db.conversations.insert_one(conversation_doc)
|
| 70 |
logger.info(f"Đã tạo hội thoại rỗng {chat_id} trong MongoDB cho user {current_user.email}.")
|
| 71 |
except Exception as e:
|
| 72 |
logger.error(f"Lỗi khi tạo hội thoại rỗng trong MongoDB cho chat {chat_id}: {e}", exc_info=True)
|
|
|
|
| 135 |
# Xóa chat
|
| 136 |
delete_chat_from_redis(redis, chat_id)
|
| 137 |
# Xóa hội thoại trong MongoDB
|
| 138 |
+
result =await mongo_db.conversations.delete_one({"conversation_id": chat_id, "user_id": user.email})
|
| 139 |
if result.deleted_count == 0:
|
| 140 |
raise HTTPException(status_code=404, detail="Chat not found in MongoDB")
|
| 141 |
|
|
|
|
| 147 |
async def get_conversations(user: UserOut = Depends(get_current_user)):
|
| 148 |
try:
|
| 149 |
logger.info(f"Attempting to get conversations for user: {user.email}")
|
| 150 |
+
db_conversations_cursor = await mongo_db.conversations.find({"user_id": user.email})
|
| 151 |
|
| 152 |
response_list = []
|
| 153 |
|
|
|
|
| 182 |
|
| 183 |
# 1. Kiểm tra hội thoại trong MongoDB
|
| 184 |
try:
|
| 185 |
+
conversation_doc = await mongo_db.conversations.find_one(
|
| 186 |
{"conversation_id": chat_id, "user_id": current_user.email}
|
| 187 |
)
|
| 188 |
if not conversation_doc:
|