AIdeaText commited on
Commit
aa3daf7
·
verified ·
1 Parent(s): 77d6f24

Rename modules/database/chat_db.py to modules/database/chat_mongo_db.py

Browse files
modules/database/{chat_db.py → chat_mongo_db.py} RENAMED
@@ -1,45 +1,45 @@
1
- #/modules/database/chat_db.py
2
- from .mongo_db import insert_document, find_documents
3
- from datetime import datetime, timezone
4
- import logging
5
- from .database_init import get_mongodb # Asegúrate de que esta importación esté al principio del archivo
6
-
7
- logger = logging.getLogger(__name__)
8
-
9
- COLLECTION_NAME = 'chat_history-v3'
10
-
11
- def store_chat_history(username, messages, analysis_type):
12
- chat_document = {
13
- 'username': username,
14
- 'timestamp': datetime.now(timezone.utc).isoformat(),
15
- 'messages': messages,
16
- 'analysis_type': analysis_type
17
- }
18
-
19
- result = insert_document(COLLECTION_NAME, chat_document)
20
- if result:
21
- logger.info(f"Historial de chat guardado con ID: {result} para el usuario: {username}")
22
- return True
23
- return False
24
-
25
- def get_chat_history(username, analysis_type, limit=None):
26
- query = {"username": username}
27
- if analysis_type:
28
- query["analysis_type"] = analysis_type
29
-
30
- db = get_mongodb()
31
- collection = db['chat_history-v3']
32
- cursor = collection.find(query).sort("timestamp", -1)
33
- if limit:
34
- cursor = cursor.limit(limit)
35
-
36
- return list(cursor)
37
-
38
- #def get_chat_history(username, analysis_type=None, limit=10):
39
- # query = {"username": username}
40
- # if analysis_type:
41
- # query["analysis_type"] = analysis_type
42
-
43
- # return find_documents(COLLECTION_NAME, query, sort=[("timestamp", -1)], limit=limit)
44
-
45
  # Agregar funciones para actualizar y eliminar chat si es necesario
 
1
+ #/modules/database/chat_mongo_db.py
2
+ from .mongo_db import insert_document, find_documents, get_collections
3
+ from datetime import datetime, timezone
4
+ import logging
5
+ from .database_init import get_mongodb # Asegúrate de que esta importación esté al principio del archivo
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ COLLECTION_NAME = 'chat_history-v3'
10
+
11
+ def store_chat_history(username, messages, analysis_type):
12
+ chat_document = {
13
+ 'username': username,
14
+ 'timestamp': datetime.now(timezone.utc).isoformat(),
15
+ 'messages': messages,
16
+ 'analysis_type': analysis_type
17
+ }
18
+
19
+ result = insert_document(COLLECTION_NAME, chat_document)
20
+ if result:
21
+ logger.info(f"Historial de chat guardado con ID: {result} para el usuario: {username}")
22
+ return True
23
+ return False
24
+
25
+ def get_chat_history(username, analysis_type, limit=None):
26
+ query = {"username": username}
27
+ if analysis_type:
28
+ query["analysis_type"] = analysis_type
29
+
30
+ db = get_mongodb()
31
+ collection = db['chat_history-v3']
32
+ cursor = collection.find(query).sort("timestamp", -1)
33
+ if limit:
34
+ cursor = cursor.limit(limit)
35
+
36
+ return list(cursor)
37
+
38
+ #def get_chat_history(username, analysis_type=None, limit=10):
39
+ # query = {"username": username}
40
+ # if analysis_type:
41
+ # query["analysis_type"] = analysis_type
42
+
43
+ # return find_documents(COLLECTION_NAME, query, sort=[("timestamp", -1)], limit=limit)
44
+
45
  # Agregar funciones para actualizar y eliminar chat si es necesario