-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
90 lines (73 loc) · 3.48 KB
/
main.py
File metadata and controls
90 lines (73 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Punto de entrada principal del sistema de debate.
Solo importa y ejecuta los componentes modulares.
"""
from typing import Dict, Any
from langchain_core.messages import HumanMessage
from src.debate.graph import create_debate_graph
from src.errors.handler import handle_error
from src.utils.logger import setup_logging, get_logger
from src.debate.config_loader import load_config
if __name__ == "__main__":
# Cargar configuración
config = load_config()
# Configurar logging
logging_config = config.get("logging", {})
logger = setup_logging(
level=logging_config.get("level", "INFO"),
format_string=logging_config.get("format"),
log_file=logging_config.get("file")
)
# Cargar constantes desde configuración
default_topic = config.get("default_topic", "Deberíamos permitir que las IAs tengan derechos legales como los humanos")
initial_message = config.get("initial_message", "Presenten sus argumentos iniciales.")
separator_width = config.get("debate", {}).get("separator_width", 60)
# Solicitar el tema del debate al usuario
logger.info("=" * separator_width)
logger.info("🎙️ SISTEMA DE DEBATE - INGRESO DE TEMA")
logger.info("=" * separator_width)
logger.info(f"\n📝 Tema por defecto: {default_topic}")
logger.info("\n💡 Ingresa un nuevo tema para el debate (o presiona Enter para usar el tema por defecto):")
from src.debate.constants import MAX_TOPIC_LENGTH, MIN_TOPIC_LENGTH
while True:
tema_usuario = input(" ➜ ").strip()
# Si el usuario no ingresó nada, usar el tema por defecto
if not tema_usuario:
TEMA_DEBATE = default_topic
logger.info(f"\n✅ Usando tema por defecto: {TEMA_DEBATE}")
break
# Validar longitud
if len(tema_usuario) < MIN_TOPIC_LENGTH:
logger.warning(f"\n⚠️ El tema es demasiado corto (mínimo {MIN_TOPIC_LENGTH} caracteres). Por favor, ingresa un tema más descriptivo.")
continue
if len(tema_usuario) > MAX_TOPIC_LENGTH:
logger.warning(f"\n⚠️ El tema es demasiado largo (máximo {MAX_TOPIC_LENGTH} caracteres). Por favor, ingresa un tema más corto.")
continue
# Validar caracteres peligrosos (opcional, sanitización básica)
# Eliminar caracteres de control no visibles
tema_usuario_sanitizado = ''.join(char for char in tema_usuario if ord(char) >= 32 or char in '\n\r\t')
if tema_usuario_sanitizado != tema_usuario:
logger.warning("\n⚠️ Se eliminaron caracteres no válidos del tema.")
tema_usuario = tema_usuario_sanitizado
TEMA_DEBATE = tema_usuario
logger.info(f"\n✅ Tema seleccionado: {TEMA_DEBATE}")
break
logger.info("\n" + "=" * separator_width)
logger.info(f"🎙️ INICIANDO DEBATE: {TEMA_DEBATE}")
logger.info("=" * separator_width)
# Crear el grafo del debate
app = create_debate_graph()
# Estado inicial
inputs: Dict[str, Any] = {
"messages": [HumanMessage(content=initial_message)],
"topic": TEMA_DEBATE,
"turn_count": 0
}
# Ejecutar el grafo (stream para ver el progreso)
try:
for event in app.stream(inputs):
# Los nodos ya logean su contenido directamente
pass
except Exception as e:
handle_error(e, TEMA_DEBATE, inputs)
logger.info("\n🏁 Fin del debate.")