Spaces:
Sleeping
Sleeping
Clean up dead Qwen local model fallback and add .gitignore
Browse files- .gitignore +6 -0
- core/parser/fallback.py +2 -28
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
data/
|
| 4 |
+
models/
|
| 5 |
+
.env
|
| 6 |
+
.env.local
|
core/parser/fallback.py
CHANGED
|
@@ -1,23 +1,14 @@
|
|
| 1 |
"""
|
| 2 |
Fallback parsing logic.
|
| 3 |
Attempts fast regex-based parsing first, falling back to local heuristic/embedding parser,
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
from __future__ import annotations
|
| 7 |
|
| 8 |
-
import os
|
| 9 |
-
import json
|
| 10 |
-
import urllib.request
|
| 11 |
-
from typing import Any
|
| 12 |
-
|
| 13 |
from core.intent_parser import parse_intent
|
| 14 |
from core.parser.local_parser.parser import LocalIntentParser
|
| 15 |
|
| 16 |
-
# Light weight high quality Qwen2.5 GGUF model url
|
| 17 |
-
QWEN_GGUF_URL = "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf"
|
| 18 |
-
|
| 19 |
_local_parser: LocalIntentParser | None = None
|
| 20 |
-
_qwen_model: Any | None = None
|
| 21 |
|
| 22 |
def get_local_parser() -> LocalIntentParser:
|
| 23 |
"""Lazily load the local heuristic & embedding parser."""
|
|
@@ -26,16 +17,8 @@ def get_local_parser() -> LocalIntentParser:
|
|
| 26 |
_local_parser = LocalIntentParser()
|
| 27 |
return _local_parser
|
| 28 |
|
| 29 |
-
def get_qwen_model(models_dir: str) -> Any | None:
|
| 30 |
-
"""Lazily download and load the llama-cpp-python Qwen GGUF model."""
|
| 31 |
-
return None
|
| 32 |
-
|
| 33 |
-
def parse_with_qwen(session_id: str, command: str) -> dict[str, Any] | None:
|
| 34 |
-
"""Run local inference using Qwen GGUF via llama-cpp-python."""
|
| 35 |
-
return None
|
| 36 |
-
|
| 37 |
def parse_intent_hybrid(session_id: str, command: str) -> dict | None:
|
| 38 |
-
"""Parse user command using fast regex path, local orchestrator parser,
|
| 39 |
# 1. Fast Path: Regex / keyword resolution
|
| 40 |
fast_result = parse_intent(session_id, command)
|
| 41 |
if fast_result is not None:
|
|
@@ -56,14 +39,5 @@ def parse_intent_hybrid(session_id: str, command: str) -> dict | None:
|
|
| 56 |
except Exception as e:
|
| 57 |
print(f"[Hybrid Parser] Exception in local parser: {e}")
|
| 58 |
|
| 59 |
-
# 3. Local Qwen GGUF Model Fallback
|
| 60 |
-
try:
|
| 61 |
-
qwen_result = parse_with_qwen(session_id, command)
|
| 62 |
-
if qwen_result is not None:
|
| 63 |
-
print(f"[Hybrid Parser] Local Qwen GGUF success: {qwen_result}")
|
| 64 |
-
return qwen_result
|
| 65 |
-
except Exception as e:
|
| 66 |
-
print(f"[Hybrid Parser] Exception in local Qwen fallback: {e}")
|
| 67 |
-
|
| 68 |
print("[Hybrid Parser] All local paths failed. Returning None.")
|
| 69 |
return None
|
|
|
|
| 1 |
"""
|
| 2 |
Fallback parsing logic.
|
| 3 |
Attempts fast regex-based parsing first, falling back to local heuristic/embedding parser,
|
| 4 |
+
and finally to the cloud Gemini LLM parser.
|
| 5 |
"""
|
| 6 |
from __future__ import annotations
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from core.intent_parser import parse_intent
|
| 9 |
from core.parser.local_parser.parser import LocalIntentParser
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
_local_parser: LocalIntentParser | None = None
|
|
|
|
| 12 |
|
| 13 |
def get_local_parser() -> LocalIntentParser:
|
| 14 |
"""Lazily load the local heuristic & embedding parser."""
|
|
|
|
| 17 |
_local_parser = LocalIntentParser()
|
| 18 |
return _local_parser
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def parse_intent_hybrid(session_id: str, command: str) -> dict | None:
|
| 21 |
+
"""Parse user command using fast regex path, local orchestrator parser, or cloud Gemini."""
|
| 22 |
# 1. Fast Path: Regex / keyword resolution
|
| 23 |
fast_result = parse_intent(session_id, command)
|
| 24 |
if fast_result is not None:
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
print(f"[Hybrid Parser] Exception in local parser: {e}")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
print("[Hybrid Parser] All local paths failed. Returning None.")
|
| 43 |
return None
|