chatbot-gitconnect / app /services /intent_service.py
quantumbit's picture
preprocessing endpoint fixed and chat endpoint has been updated to specific results-sem wise
d0220ae
import re
from typing import Literal, Tuple
Intent = Literal["attendance", "result", "syllabus", "other"]
def classify_intent(query: str) -> Tuple[Intent, bool]:
q = query.strip().lower()
if not q:
return "other", False
greeting_words = {
"hi",
"hello",
"hey",
"good morning",
"good afternoon",
"good evening",
}
attendance_keywords = {
"attendance",
"attend",
"absent",
"present",
"classes",
"attendance percentage",
"overall attendance",
}
result_keywords = {
"result",
"results",
"marks",
"score",
"sgpa",
"cgpa",
"gpa",
"grade",
"ia",
"exam",
"performance",
"passed",
"fail",
}
syllabus_keywords = {
"syllabus",
"unit",
"units",
"module",
"modules",
"topic",
"topics",
"course content",
"chapters",
"what is covered",
}
education_keywords = (
attendance_keywords
| result_keywords
| syllabus_keywords
| {
"semester",
"course",
"subject",
"study",
"assignment",
"project",
"college",
"class",
"exam prep",
}
)
has_course_code = bool(re.search(r"\b\d{2}[a-z]{2,}[a-z0-9]*\d+[a-z]?\b", q, flags=re.I))
is_greeting = any(word in q for word in greeting_words)
is_education = has_course_code or any(k in q for k in education_keywords) or is_greeting
if any(k in q for k in attendance_keywords):
return "attendance", is_education
if any(k in q for k in result_keywords):
return "result", is_education
if any(k in q for k in syllabus_keywords):
return "syllabus", is_education
return "other", is_education