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

View File

@@ -52,6 +52,7 @@ from .core.ai import ask_ai_stream, translate_text
from .core.config import BASE_DIR from .core.config import BASE_DIR
from .core.cleaner import clean_response from .core.cleaner import clean_response
from .core.commands import is_stop_command from .core.commands import is_stop_command
from .core.smalltalk import get_smalltalk_response
from .features.alarm import get_alarm_clock from .features.alarm import get_alarm_clock
from .features.timer import get_timer_manager from .features.timer import get_timer_manager
from .features.weather import get_weather_report from .features.weather import get_weather_report
@@ -377,6 +378,15 @@ def main():
skip_wakeword = True skip_wakeword = True
continue continue
# Короткие ответы на small-talk ("как дела" и т.п.)
smalltalk_response = get_smalltalk_response(user_text)
if smalltalk_response:
clean_smalltalk = clean_response(smalltalk_response, language="ru")
speak(clean_smalltalk)
last_response = clean_smalltalk
skip_wakeword = True
continue
# Проверка команд таймера ("поставь таймер на 6 минут") # Проверка команд таймера ("поставь таймер на 6 минут")
timer_response = timer_manager.parse_command(user_text) timer_response = timer_manager.parse_command(user_text)
if timer_response: if timer_response: