JeCabrera commited on
Commit
cfcb320
verified
1 Parent(s): 8c94b5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -14,7 +14,7 @@ from session_state import (
14
 
15
  # Inicializar el estado de la sesi贸n
16
  state = SessionState()
17
- STREAM_SETTINGS = {'batch_size': 1, 'delay_seconds': 0.01}
18
  user_past_chats_list_path = None
19
 
20
  def get_user_namespace():
@@ -261,6 +261,7 @@ with st.sidebar:
261
  state.chat_id = new_chat_id
262
  st.session_state.pending_example_prompt = None
263
  st.session_state.hide_initial_menu = False
 
264
  st.rerun()
265
 
266
  st.caption('Sesiones')
@@ -299,6 +300,7 @@ with st.sidebar:
299
  ):
300
  if state.chat_id != chat_id:
301
  state.chat_id = chat_id
 
302
  st.rerun()
303
 
304
  with menu_col:
@@ -341,11 +343,26 @@ elif st.session_state.active_chat_id != state.chat_id:
341
  st.session_state.active_chat_id = state.chat_id
342
  st.session_state.pending_example_prompt = None
343
  st.session_state.hide_initial_menu = state.has_messages()
 
344
 
345
  # Inicializar el modelo y el chat
346
  system_prompt = get_unified_email_prompt()
347
- state.initialize_model(DEFAULT_GEMINI_MODEL, api_key=GOOGLE_API_KEY)
348
- state.initialize_chat(system_instruction=system_prompt) # Siempre inicializar el chat despu茅s del modelo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
 
350
  # Mostrar mensajes del historial
351
  for message in state.messages:
 
14
 
15
  # Inicializar el estado de la sesi贸n
16
  state = SessionState()
17
+ STREAM_SETTINGS = {'batch_size': 24, 'delay_seconds': 0.0}
18
  user_past_chats_list_path = None
19
 
20
  def get_user_namespace():
 
261
  state.chat_id = new_chat_id
262
  st.session_state.pending_example_prompt = None
263
  st.session_state.hide_initial_menu = False
264
+ st.session_state.editing_chat_id = None
265
  st.rerun()
266
 
267
  st.caption('Sesiones')
 
300
  ):
301
  if state.chat_id != chat_id:
302
  state.chat_id = chat_id
303
+ st.session_state.editing_chat_id = None
304
  st.rerun()
305
 
306
  with menu_col:
 
343
  st.session_state.active_chat_id = state.chat_id
344
  st.session_state.pending_example_prompt = None
345
  st.session_state.hide_initial_menu = state.has_messages()
346
+ st.session_state.editing_chat_id = None
347
 
348
  # Inicializar el modelo y el chat
349
  system_prompt = get_unified_email_prompt()
350
+ if (
351
+ st.session_state.get('initialized_model_name') != DEFAULT_GEMINI_MODEL
352
+ or getattr(state, 'client', None) is None
353
+ ):
354
+ state.initialize_model(DEFAULT_GEMINI_MODEL, api_key=GOOGLE_API_KEY)
355
+ st.session_state.initialized_model_name = DEFAULT_GEMINI_MODEL
356
+
357
+ should_reinitialize_chat = (
358
+ state.chat is None
359
+ or st.session_state.get('initialized_chat_id') != state.chat_id
360
+ or st.session_state.get('initialized_system_prompt') != system_prompt
361
+ )
362
+ if should_reinitialize_chat:
363
+ state.initialize_chat(system_instruction=system_prompt)
364
+ st.session_state.initialized_chat_id = state.chat_id
365
+ st.session_state.initialized_system_prompt = system_prompt
366
 
367
  # Mostrar mensajes del historial
368
  for message in state.messages: