Spaces:
Sleeping
Sleeping
Update session_state.py
Browse files- session_state.py +12 -4
session_state.py
CHANGED
|
@@ -3,6 +3,8 @@ import joblib
|
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
DEFAULT_GEMINI_MODEL = 'gemini-3.1-flash-lite-preview'
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class SessionState:
|
| 8 |
"""
|
|
@@ -170,8 +172,8 @@ class SessionState:
|
|
| 170 |
if chat_id is None:
|
| 171 |
chat_id = self.chat_id
|
| 172 |
|
| 173 |
-
joblib.dump(self.messages,
|
| 174 |
-
joblib.dump(self.gemini_history,
|
| 175 |
|
| 176 |
def load_chat_history(self, chat_id=None):
|
| 177 |
"""Carga el historial del chat"""
|
|
@@ -179,13 +181,19 @@ class SessionState:
|
|
| 179 |
chat_id = self.chat_id
|
| 180 |
|
| 181 |
try:
|
| 182 |
-
self.messages = joblib.load(
|
| 183 |
-
self.gemini_history = joblib.load(
|
| 184 |
return True
|
| 185 |
except (FileNotFoundError, EOFError):
|
| 186 |
self.messages = []
|
| 187 |
self.gemini_history = []
|
| 188 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
def has_messages(self):
|
| 191 |
"""Verifica si hay mensajes en el historial"""
|
|
|
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
DEFAULT_GEMINI_MODEL = 'gemini-3.1-flash-lite-preview'
|
| 6 |
+
DATA_DIR = 'data'
|
| 7 |
+
PAST_CHATS_LIST_PATH = f'{DATA_DIR}/past_chats_list'
|
| 8 |
|
| 9 |
class SessionState:
|
| 10 |
"""
|
|
|
|
| 172 |
if chat_id is None:
|
| 173 |
chat_id = self.chat_id
|
| 174 |
|
| 175 |
+
joblib.dump(self.messages, self._st_messages_path(chat_id))
|
| 176 |
+
joblib.dump(self.gemini_history, self._gemini_messages_path(chat_id))
|
| 177 |
|
| 178 |
def load_chat_history(self, chat_id=None):
|
| 179 |
"""Carga el historial del chat"""
|
|
|
|
| 181 |
chat_id = self.chat_id
|
| 182 |
|
| 183 |
try:
|
| 184 |
+
self.messages = joblib.load(self._st_messages_path(chat_id))
|
| 185 |
+
self.gemini_history = joblib.load(self._gemini_messages_path(chat_id))
|
| 186 |
return True
|
| 187 |
except (FileNotFoundError, EOFError):
|
| 188 |
self.messages = []
|
| 189 |
self.gemini_history = []
|
| 190 |
return False
|
| 191 |
+
|
| 192 |
+
def _st_messages_path(self, chat_id):
|
| 193 |
+
return f'{DATA_DIR}/{chat_id}-st_messages'
|
| 194 |
+
|
| 195 |
+
def _gemini_messages_path(self, chat_id):
|
| 196 |
+
return f'{DATA_DIR}/{chat_id}-gemini_messages'
|
| 197 |
|
| 198 |
def has_messages(self):
|
| 199 |
"""Verifica si hay mensajes en el historial"""
|