""" Fallback parsing logic. Attempts fast regex-based parsing first, falling back to local heuristic/embedding parser, and finally to the cloud Gemini LLM parser. """ from __future__ import annotations from core.intent_parser import parse_intent from core.parser.local_parser.parser import LocalIntentParser _local_parser: LocalIntentParser | None = None def get_local_parser() -> LocalIntentParser: """Lazily load the local heuristic & embedding parser.""" global _local_parser if _local_parser is None: _local_parser = LocalIntentParser() return _local_parser def parse_intent_hybrid(session_id: str, command: str) -> dict | None: """Parse user command using fast regex path, local orchestrator parser, or cloud Gemini.""" # 1. Fast Path: Regex / keyword resolution fast_result = parse_intent(session_id, command) if fast_result is not None: print(f"[Hybrid Parser] Fast path success: {fast_result}") return fast_result # 2. Local Heuristic / Spelling / Synonym / Embeddings Parser try: local_parser = get_local_parser() local_result = local_parser.parse_intent(session_id, command) if local_result is not None: confidence = local_result.pop("confidence", "low") if confidence == "high": print(f"[Hybrid Parser] Local parser high-confidence success: {local_result}") return local_result else: print(f"[Hybrid Parser] Local parser yielded low confidence: {local_result}") except Exception as e: print(f"[Hybrid Parser] Exception in local parser: {e}") print("[Hybrid Parser] All local paths failed. Returning None.") return None