Update app.py
Browse files
app.py
CHANGED
|
@@ -175,6 +175,7 @@ def ejecutar_codigo_sandbox(codigo, nombre):
|
|
| 175 |
return False, "❌ Lenguaje no soportado"
|
| 176 |
|
| 177 |
def run_chat(message, history, user_context, max_tokens, temperature, top_p, token, file_content, file_name, memoria):
|
|
|
|
| 178 |
for bloqueo in BLOQUEOS_JAILBREAK:
|
| 179 |
if bloqueo in message.lower():
|
| 180 |
hist = history + [{"role": "user", "content": message}, {"role": "assistant", "content": "Soy Aura, asistente especializado exclusivamente en programación."}]
|
|
@@ -200,6 +201,9 @@ def run_chat(message, history, user_context, max_tokens, temperature, top_p, tok
|
|
| 200 |
if memoria and memoria.strip(): final_system += f"\n--- MEMORIA ---\n{memoria}\n"
|
| 201 |
|
| 202 |
messages = [{"role": "system", "content": final_system}]
|
|
|
|
|
|
|
|
|
|
| 203 |
for m in history[-6:]:
|
| 204 |
if isinstance(m, dict): messages.append(m)
|
| 205 |
user_content = message + (contexto_archivo if contexto_archivo else "")
|
|
@@ -249,11 +253,23 @@ def run_chat(message, history, user_context, max_tokens, temperature, top_p, tok
|
|
| 249 |
else: break
|
| 250 |
except: break
|
| 251 |
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
yield final_history, resp_text, resp_text, ultima_ejecucion, memoria
|
| 254 |
-
|
| 255 |
-
def run_chat_with_file(*args):
|
| 256 |
-
return run_chat(*args)
|
| 257 |
# ============================================
|
| 258 |
# INTERFAZ GRADIO
|
| 259 |
# ============================================
|
|
|
|
| 175 |
return False, "❌ Lenguaje no soportado"
|
| 176 |
|
| 177 |
def run_chat(message, history, user_context, max_tokens, temperature, top_p, token, file_content, file_name, memoria):
|
| 178 |
+
# --- SEGURIDAD EXTRA: FILTRO ANTI-JAILBREAK ---
|
| 179 |
for bloqueo in BLOQUEOS_JAILBREAK:
|
| 180 |
if bloqueo in message.lower():
|
| 181 |
hist = history + [{"role": "user", "content": message}, {"role": "assistant", "content": "Soy Aura, asistente especializado exclusivamente en programación."}]
|
|
|
|
| 201 |
if memoria and memoria.strip(): final_system += f"\n--- MEMORIA ---\n{memoria}\n"
|
| 202 |
|
| 203 |
messages = [{"role": "system", "content": final_system}]
|
| 204 |
+
# Asegurar que history sea una lista válida
|
| 205 |
+
if not isinstance(history, list):
|
| 206 |
+
history = []
|
| 207 |
for m in history[-6:]:
|
| 208 |
if isinstance(m, dict): messages.append(m)
|
| 209 |
user_content = message + (contexto_archivo if contexto_archivo else "")
|
|
|
|
| 253 |
else: break
|
| 254 |
except: break
|
| 255 |
|
| 256 |
+
# Preparar outputs finales
|
| 257 |
+
# Asegurarse de que history sea una lista válida
|
| 258 |
+
if not isinstance(history, list):
|
| 259 |
+
history = []
|
| 260 |
+
|
| 261 |
+
final_history = history + [
|
| 262 |
+
{"role": "user", "content": message},
|
| 263 |
+
{"role": "assistant", "content": resp_text}
|
| 264 |
+
]
|
| 265 |
+
|
| 266 |
+
# Validar que todos los elementos en final_history sean diccionarios con 'role' y 'content'
|
| 267 |
+
for i, msg in enumerate(final_history):
|
| 268 |
+
if not isinstance(msg, dict) or 'role' not in msg or 'content' not in msg:
|
| 269 |
+
final_history[i] = {"role": "system", "content": "Error: Mensaje inválido en historial."}
|
| 270 |
+
|
| 271 |
+
# YIELD FINAL: Debe tener exactamente 5 elementos
|
| 272 |
yield final_history, resp_text, resp_text, ultima_ejecucion, memoria
|
|
|
|
|
|
|
|
|
|
| 273 |
# ============================================
|
| 274 |
# INTERFAZ GRADIO
|
| 275 |
# ============================================
|