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
|
||||||
10
app/main.py
10
app/main.py
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user