29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from app.settings_cache import SettingsCache
|
|
from app.integrations.yandex_gpt import analyze_emotion_with_gpt
|
|
|
|
_NEGATIVE_WORDS = [
|
|
"ужасно", "плохо", "долго", "кошмар", "отвратительно", "невыносимо",
|
|
"бесполезно", "халтура", "безобразие", "позор", "разочарован", "злюсь",
|
|
"раздражён", "недоволен", "жалоба", "претензия", "скандал", "суд",
|
|
"верните деньги", "мошенники", "обман",
|
|
]
|
|
|
|
|
|
async def detect_emotion(text: str) -> str:
|
|
gpt_key = SettingsCache.get("yandex_gpt_key")
|
|
if gpt_key:
|
|
try:
|
|
result = await analyze_emotion_with_gpt(text)
|
|
if result in ("positive", "neutral", "negative"):
|
|
return result
|
|
except Exception:
|
|
pass
|
|
return _keyword_fallback(text)
|
|
|
|
|
|
def _keyword_fallback(text: str) -> str:
|
|
text_lower = text.lower()
|
|
if any(word in text_lower for word in _NEGATIVE_WORDS):
|
|
return "negative"
|
|
return "neutral"
|