Add smalltalk responses for how-are-you queries

This commit is contained in:
2026-02-02 23:50:10 +03:00
parent 3caa099232
commit b6178f0952
2 changed files with 53 additions and 0 deletions

43
app/core/smalltalk.py Normal file
View 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", re.IGNORECASE),
re.compile(r"\ак делишки\b", re.IGNORECASE),
re.compile(r"\ак поживаешь\b", re.IGNORECASE),
re.compile(r"\ак жизнь\b", re.IGNORECASE),
re.compile(r"\ак ты\b", re.IGNORECASE),
re.compile(r"\ак сам\b", re.IGNORECASE),
re.compile(r"\ак себя чувствуешь\b", re.IGNORECASE),
re.compile(r"\ак настроение\b", re.IGNORECASE),
re.compile(r"\bчто нового\b", re.IGNORECASE),
re.compile(r"\ак оно\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