Spaces:
Sleeping
Sleeping
File size: 1,164 Bytes
699e0ab |
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 |
# src/intent.py
def detect_intent(text: str) -> str:
"""
Fast rule-based intent detection.
Returns one of: "code", "math", "civics", "exam_prep", "general".
"""
if not text:
return "general"
t = text.lower()
# Code-related keywords
code_keys = ["python", "code", "error", "function", "class", "script", "import", "stack trace", "traceback", "bug"]
if any(k in t for k in code_keys):
return "code"
# Math keywords
math_keys = ["solve", "equation", "calculate", "simplify", "factor", "integrate", "differentiate", "sum", "prove", "find x", "x +"]
if any(k in t for k in math_keys):
return "math"
# Civics / SST keywords (class 10)
civics_keys = ["civics", "democracy", "constitution", "rights", "ncert", "class 10", "class 10th", "social studies", "sst"]
if any(k in t for k in civics_keys):
return "civics"
# Exam prep keywords
exam_keys = ["important questions", "exam", "board", "revision", "prepare", "question paper", "important", "mcq", "short answer"]
if any(k in t for k in exam_keys):
return "exam_prep"
# Default
return "general"
|