Files
smart-speaker/app/core/smalltalk.py

44 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
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