Spaces:
Running
Running
Update modules/chatbot/sidebar_chat.py
Browse files
modules/chatbot/sidebar_chat.py
CHANGED
@@ -26,16 +26,32 @@ def display_sidebar_chat(lang_code: str, chatbot_t: dict):
|
|
26 |
translations = {**default_translations, **chatbot_t}
|
27 |
|
28 |
with st.sidebar:
|
29 |
-
# Chatbot expandible
|
30 |
with st.expander(translations['expand_chat'], expanded=False):
|
31 |
try:
|
32 |
-
#
|
33 |
-
|
|
|
|
|
|
|
34 |
try:
|
35 |
st.session_state.chat_processor = ChatProcessor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
except Exception as e:
|
37 |
-
logger.error(f"Error inicializando ChatProcessor: {str(e)}")
|
38 |
-
st.error("Error: No se pudo inicializar el chat
|
39 |
return
|
40 |
|
41 |
# Inicializar mensajes si no existen
|
|
|
26 |
translations = {**default_translations, **chatbot_t}
|
27 |
|
28 |
with st.sidebar:
|
|
|
29 |
with st.expander(translations['expand_chat'], expanded=False):
|
30 |
try:
|
31 |
+
# Verificar si hay contexto semántico activo
|
32 |
+
semantic_context = st.session_state.get('semantic_agent_data')
|
33 |
+
|
34 |
+
# Inicializar el chat con contexto especializado si existe
|
35 |
+
if semantic_context and 'chat_processor' not in st.session_state:
|
36 |
try:
|
37 |
st.session_state.chat_processor = ChatProcessor()
|
38 |
+
|
39 |
+
# Mensaje inicial especializado para análisis semántico
|
40 |
+
initial_message = (
|
41 |
+
f"He analizado tu texto con {len(semantic_context['metrics'].get('key_concepts', []))} conceptos clave. "
|
42 |
+
"¿Qué aspecto te gustaría discutir? Por ejemplo:\n"
|
43 |
+
"- ¿Por qué estos conceptos son los más centrales?\n"
|
44 |
+
"- ¿Qué patrones ves en las relaciones conceptuales?\n"
|
45 |
+
"- ¿Cómo podrías mejorar la estructura del texto?"
|
46 |
+
)
|
47 |
+
|
48 |
+
st.session_state.sidebar_messages = [
|
49 |
+
{"role": "assistant", "content": initial_message}
|
50 |
+
]
|
51 |
+
|
52 |
except Exception as e:
|
53 |
+
logger.error(f"Error inicializando ChatProcessor con contexto semántico: {str(e)}")
|
54 |
+
st.error("Error: No se pudo inicializar el chat especializado.")
|
55 |
return
|
56 |
|
57 |
# Inicializar mensajes si no existen
|