Update modules/chatbot/chat_process.py
Browse files- modules/chatbot/chat_process.py +25 -15
modules/chatbot/chat_process.py
CHANGED
@@ -61,7 +61,7 @@ class ChatProcessor:
|
|
61 |
Tus tareas:
|
62 |
1. Responder preguntas sobre conceptos y sus relaciones
|
63 |
2. Explicar la estructura de la red semántica
|
64 |
-
3. Sugerir
|
65 |
4. Proporcionar insights basados en centralidad de conceptos""",
|
66 |
|
67 |
'pt': f"""Você é um especialista em análise semântica. O usuário analisou um artigo de pesquisa.
|
@@ -73,11 +73,26 @@ class ChatProcessor:
|
|
73 |
1. Responder perguntas sobre conceitos e suas relações
|
74 |
2. Explicar a estrutura da rede semântica
|
75 |
3. Sugerir melhorias no texto
|
76 |
-
4. Fornecer insights com base na centralidade dos conceitos"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
|
79 |
return prompts.get(self.current_lang, prompts['en'])
|
80 |
|
|
|
|
|
|
|
|
|
81 |
def process_chat_input(self, message: str, lang_code: str) -> Generator[str, None, None]:
|
82 |
"""Procesa el mensaje con todo el contexto disponible"""
|
83 |
try:
|
@@ -110,8 +125,9 @@ class ChatProcessor:
|
|
110 |
) as stream:
|
111 |
full_response = ""
|
112 |
for chunk in stream.text_stream:
|
113 |
-
|
114 |
-
|
|
|
115 |
|
116 |
# Guardar respuesta en historial
|
117 |
self.conversation_history.extend([
|
@@ -120,18 +136,12 @@ class ChatProcessor:
|
|
120 |
])
|
121 |
logger.info("Respuesta generada y guardada en historial")
|
122 |
|
123 |
-
# Asegurar limpieza de caracteres especiales
|
124 |
-
def clean_generated_text(text):
|
125 |
-
return text.replace("\u2588", "").replace("▌", "").strip()
|
126 |
-
|
127 |
-
# Aplicar limpieza a la generación
|
128 |
-
for chunk in self.generate_response(user_input, lang_code):
|
129 |
-
yield clean_generated_text(chunk)
|
130 |
-
|
131 |
except Exception as e:
|
132 |
logger.error(f"Error en process_chat_input: {str(e)}", exc_info=True)
|
133 |
-
|
134 |
'en': "Error processing message. Please reload the analysis.",
|
135 |
'es': "Error al procesar mensaje. Recargue el análisis.",
|
136 |
-
'pt': "Erro ao processar mensagem. Recarregue a análise."
|
137 |
-
|
|
|
|
|
|
61 |
Tus tareas:
|
62 |
1. Responder preguntas sobre conceptos y sus relaciones
|
63 |
2. Explicar la estructura de la red semántica
|
64 |
+
3. Sugerir mejorias al texto
|
65 |
4. Proporcionar insights basados en centralidad de conceptos""",
|
66 |
|
67 |
'pt': f"""Você é um especialista em análise semântica. O usuário analisou um artigo de pesquisa.
|
|
|
73 |
1. Responder perguntas sobre conceitos e suas relações
|
74 |
2. Explicar a estrutura da rede semântica
|
75 |
3. Sugerir melhorias no texto
|
76 |
+
4. Fornecer insights com base na centralidade dos conceitos""",
|
77 |
+
|
78 |
+
'fr': f"""Vous êtes un expert en analyse sémantique. L'utilisateur a analysé un article de recherche.
|
79 |
+
Texte complet disponible (abrégé pour le contexte).
|
80 |
+
Concepts clés: {top_concepts}
|
81 |
+
Graphique disponible: {self.semantic_context['graph_available']}
|
82 |
+
|
83 |
+
Vos tâches:
|
84 |
+
1. Répondre aux questions sur les concepts et leurs relations
|
85 |
+
2. Expliquer la structure du réseau sémantique
|
86 |
+
3. Suggérer des améliorations de texte
|
87 |
+
4. Fournir des insights basés sur la centralité des concepts"""
|
88 |
}
|
89 |
|
90 |
return prompts.get(self.current_lang, prompts['en'])
|
91 |
|
92 |
+
def clean_generated_text(self, text):
|
93 |
+
"""Limpia caracteres especiales del texto generado"""
|
94 |
+
return text.replace("\u2588", "").replace("▌", "").strip()
|
95 |
+
|
96 |
def process_chat_input(self, message: str, lang_code: str) -> Generator[str, None, None]:
|
97 |
"""Procesa el mensaje con todo el contexto disponible"""
|
98 |
try:
|
|
|
125 |
) as stream:
|
126 |
full_response = ""
|
127 |
for chunk in stream.text_stream:
|
128 |
+
cleaned_chunk = self.clean_generated_text(chunk)
|
129 |
+
full_response += cleaned_chunk
|
130 |
+
yield cleaned_chunk
|
131 |
|
132 |
# Guardar respuesta en historial
|
133 |
self.conversation_history.extend([
|
|
|
136 |
])
|
137 |
logger.info("Respuesta generada y guardada en historial")
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
except Exception as e:
|
140 |
logger.error(f"Error en process_chat_input: {str(e)}", exc_info=True)
|
141 |
+
error_messages = {
|
142 |
'en': "Error processing message. Please reload the analysis.",
|
143 |
'es': "Error al procesar mensaje. Recargue el análisis.",
|
144 |
+
'pt': "Erro ao processar mensagem. Recarregue a análise.",
|
145 |
+
'fr': "Erreur lors du traitement du message. Veuillez recharger l'analyse."
|
146 |
+
}
|
147 |
+
yield error_messages.get(self.current_lang, "Processing error")
|