Add smalltalk responses for how-are-you queries
This commit is contained in:
43
app/core/smalltalk.py
Normal file
43
app/core/smalltalk.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Short, human-like responses for small talk.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
|
||||
_SMALLTALK_PATTERNS = [
|
||||
re.compile(r"\bкак дела\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак делишки\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак поживаешь\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак жизнь\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак ты\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак сам\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак себя чувствуешь\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак настроение\b", re.IGNORECASE),
|
||||
re.compile(r"\bчто нового\b", re.IGNORECASE),
|
||||
re.compile(r"\bкак оно\b", re.IGNORECASE),
|
||||
]
|
||||
|
||||
_SMALLTALK_RESPONSES = [
|
||||
"Все нормально, спасибо. А у тебя?",
|
||||
"Хорошо, спасибо. Чем помочь?",
|
||||
"Нормально. Что-то нужно?",
|
||||
"Все в порядке. Как ты?",
|
||||
"Отлично. Слушаю тебя.",
|
||||
]
|
||||
|
||||
|
||||
def get_smalltalk_response(text: str) -> Optional[str]:
|
||||
if not text:
|
||||
return None
|
||||
|
||||
normalized = text.lower().replace("ё", "е")
|
||||
for pattern in _SMALLTALK_PATTERNS:
|
||||
if pattern.search(normalized):
|
||||
return random.choice(_SMALLTALK_RESPONSES)
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user