Spaces:
Runtime error
Runtime error
Download modules/parser_intent.py from Garimind/GariGariMind-Frontend-Memory-Engine: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/Garimind/GariGariMind-Frontend-Memory-Engine/resolve/main/modules/parser_intent.py
- Command line
-
hf download hf://spaces/Garimind/GariGariMind-Frontend-Memory-Engine/modules/parser_intent.py
-
curl -L -o parser_intent.py https://huggingface.co/spaces/Garimind/GariGariMind-Frontend-Memory-Engine/resolve/main/modules/parser_intent.py
2.73 kB
| # modules/utils/parser_intent.py | |
| import re | |
| from datetime import datetime, timedelta | |
| def parse_date(text): | |
| txt = text.lower().strip() | |
| if txt == "hoy": | |
| return datetime.today().date().isoformat() | |
| if txt in ("mañana", "manana"): | |
| return (datetime.today() + timedelta(days=1)).date().isoformat() | |
| m = re.match(r"(\d{4}-\d{2}-\d{2})", txt) | |
| return m.group(1) if m else None | |
| def split_list(text): | |
| return [x.strip() for x in re.split(r"[;,:]|\by\b", text) if x.strip()] | |
| def parse_task_command(msg: str): | |
| mmsg = msg.strip() | |
| # 1) ¿Es un "crear/añadir/agregar tarea"? | |
| if not re.search(r"\b(crear|añadir|agregar)\s+tarea\b", mmsg, re.I): | |
| return None | |
| # 2) Email de usuario | |
| u = re.search(r"para\s+([^\s;:,]+@[^\s;:,]+)", mmsg, re.I) | |
| usuario = u.group(1) if u else None | |
| # 3) Título: | |
| # - Entre comillas normales "..." o curvas “...” | |
| # - O bien, sin comillas: de "para ... " hasta "desde|hasta|;|$" | |
| t = re.search(r"[“\"]([^”\"]+)[”\"]", mmsg) | |
| if t: | |
| titulo = t.group(1).strip() | |
| else: | |
| # buscamos lo que hay justo después del email | |
| after = re.split(r"para\s+[^\s]+@[^\s]+\s+", mmsg, 1) | |
| if len(after) > 1: | |
| titulo = re.split(r"\bdesde\b|\bhasta\b|;|$", | |
| after[1], flags=re.I)[0].strip() | |
| else: | |
| titulo = None | |
| # 4) Fechas "desde X hasta Y" | |
| di = df = None | |
| dh = re.search(r"\bdesde\s+([^\s;]+)\s+hasta\s+([^\s;]+)", mmsg, re.I) | |
| if dh: | |
| di = parse_date(dh.group(1)) | |
| df = parse_date(dh.group(2)) | |
| else: | |
| # Si no, miramos "para mañana" | |
| p = re.search(r"\bpara\s+(hoy|mañana|\d{4}-\d{2}-\d{2})", mmsg, re.I) | |
| if p: | |
| df = parse_date(p.group(1)) | |
| # 5) Checklist / lista_chequeo | |
| cl = re.search(r"checklist[:\s]+(.+?)(;|$)", mmsg, re.I) | |
| lista_chequeo = split_list(cl.group(1)) if cl else None | |
| # 6) Comentarios | |
| com = re.search(r"comentarios?[:\s]+(.+?)(;|$)", mmsg, re.I) | |
| comentarios = com.group(1).strip() if com else None | |
| # 7) Esfuerzo | |
| ef = re.search(r"esfuerzo[:\s]+([0-9]+h?)", mmsg, re.I) | |
| esfuerzo = ef.group(1) if ef else None | |
| # 8) Responsable | |
| rp = re.search(r"responsable[:\s]+([^\s;:,]+@[^\s;:,]+)", mmsg, re.I) | |
| responsable = rp.group(1) if rp else None | |
| return { | |
| "action": "create_task", | |
| "task": { | |
| "usuario_id": usuario, | |
| "titulo": titulo, | |
| "fecha_inicio": di, | |
| "fecha_fin": df, | |
| "lista_chequeo": lista_chequeo, | |
| "comentarios": comentarios, | |
| "esfuerzo": esfuerzo, | |
| "responsable_id": responsable | |
| } | |
| } | |