kin/core/chat_intent.py

49 lines
1.4 KiB
Python
Raw Permalink Normal View History

"""Kin — chat intent classifier (heuristic, no LLM).
classify_intent(text) 'task_request' | 'status_query' | 'question'
"""
import re
from typing import Literal
_STATUS_PATTERNS = [
r'что сейчас',
r'в работе',
r'\bстатус\b',
r'список задач',
r'покажи задачи',
r'покажи список',
r'какие задачи',
r'что идёт',
r'что делается',
r'что висит',
]
_QUESTION_STARTS = (
'почему', 'зачем', 'как ', 'что такое', 'что значит',
'объясни', 'расскажи', 'что делает', 'как работает',
'в чём', 'когда', 'кто',
)
def classify_intent(text: str) -> Literal['task_request', 'status_query', 'question']:
"""Classify user message intent.
Returns:
'status_query' user is asking about current project status/tasks
'question' user is asking a question (no action implied)
'task_request' everything else; default: create a task and run pipeline
"""
lower = text.lower().strip()
for pattern in _STATUS_PATTERNS:
if re.search(pattern, lower):
return 'status_query'
if lower.endswith('?'):
for word in _QUESTION_STARTS:
if lower.startswith(word):
return 'question'
return 'task_request'