Spaces:
Runtime error
Runtime error
Download modules/utils/parser_intent.py from Garimind/GariGariMind-Frontend-Memory-Engine: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/Garimind/GariGariMind-Frontend-Memory-Engine/resolve/main/modules/utils/parser_intent.py
- Command line
-
hf download hf://spaces/Garimind/GariGariMind-Frontend-Memory-Engine/modules/utils/parser_intent.py
-
curl -L -o parser_intent.py https://huggingface.co/spaces/Garimind/GariGariMind-Frontend-Memory-Engine/resolve/main/modules/utils/parser_intent.py
2.19 kB
| # modules/utils/parser_intent.py | |
| import re | |
| from datetime import date, timedelta | |
| def parse_task_command(text): | |
| """ | |
| Detecta comandos sencillos de tarea en NL: | |
| - Crea tarea para <responsable> <título> [mañana|hoy] | |
| - Actualiza tarea id=<ID> estado <nuevo_estado> | |
| - Completa tarea id=<ID> | |
| Devuelve dict con 'action' y 'task' o None. | |
| """ | |
| low = text.lower().strip() | |
| # — Crear tarea — | |
| if low.startswith("crea tarea"): | |
| # Responsable (email o UUID) tras "para" | |
| m = re.search(r"para\s+(\S+@\S+|\w{8}-\w{4}-\w{4}-\w{4}-\w{12})", text) | |
| responsable = m.group(1) if m else None | |
| # Fecha: mañana/hoy | |
| if "mañana" in low: | |
| inicio = date.today() + timedelta(days=1) | |
| else: | |
| inicio = date.today() | |
| # Título: texto tras "crea tarea" recortando "para ..." y "mañana" | |
| titulo = re.sub(r"crea tarea\s*", "", text, flags=re.IGNORECASE) | |
| titulo = re.sub(r"para\s+\S+", "", titulo).replace("mañana", "").strip() | |
| return { | |
| "action": "create_task", | |
| "task": { | |
| "titulo": titulo or "Sin título", | |
| "responsable_id": responsable, | |
| "fecha_inicio": inicio.isoformat(), | |
| "fecha_fin": inicio.isoformat(), | |
| "prioridad": "media" | |
| } | |
| } | |
| # — Actualizar tarea — | |
| if low.startswith("actualiza tarea"): | |
| # Extraer id y campo | |
| m = re.search(r"id\s*=\s*([0-9a-fA-F\-]+)", low) | |
| task_id = m.group(1) if m else None | |
| # Estado nuevo | |
| m2 = re.search(r"estado\s+(\w+)", low) | |
| nuevo_estado = m2.group(1) if m2 else None | |
| return { | |
| "action": "update_task", | |
| "task": { | |
| "id": task_id, | |
| **({"estado": nuevo_estado} if nuevo_estado else {}) | |
| } | |
| } | |
| # — Completar tarea — | |
| if low.startswith("completa tarea"): | |
| m = re.search(r"id\s*=\s*([0-9a-fA-F\-]+)", low) | |
| task_id = m.group(1) if m else None | |
| return { | |
| "action": "complete_task", | |
| "task": {"id": task_id} | |
| } | |
| return None | |