Spaces:
Running
Running
axeronis commited on
Commit ·
81b3ca5
1
Parent(s): df6fb4c
feat: use smart LLM detection result in webhook, keywords as fallback
Browse files
backend/app/api/webhook.py
CHANGED
|
@@ -1267,20 +1267,26 @@ async def process_ai_response_background(
|
|
| 1267 |
# AI can add [SEND_VOICE] tag when it detects persuasion/trust moment
|
| 1268 |
ai_wants_voice = "[SEND_VOICE]" in ai_response["text"]
|
| 1269 |
|
| 1270 |
-
# === CHECK IF USER REQUESTED NO VOICE
|
| 1271 |
-
|
| 1272 |
-
|
| 1273 |
-
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
|
| 1278 |
-
|
| 1279 |
-
|
| 1280 |
-
|
| 1281 |
-
|
| 1282 |
-
|
| 1283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1284 |
|
| 1285 |
# If user requested no voice, disable all voice triggers
|
| 1286 |
if user_requested_no_voice:
|
|
|
|
| 1267 |
# AI can add [SEND_VOICE] tag when it detects persuasion/trust moment
|
| 1268 |
ai_wants_voice = "[SEND_VOICE]" in ai_response["text"]
|
| 1269 |
|
| 1270 |
+
# === CHECK IF USER REQUESTED NO VOICE ===
|
| 1271 |
+
# First use smart LLM-based detection from response_generator (if available)
|
| 1272 |
+
user_requested_no_voice = ai_response.get("user_requested_no_voice", False)
|
| 1273 |
+
|
| 1274 |
+
# Fallback: keyword check if LLM check didn't run
|
| 1275 |
+
if not user_requested_no_voice:
|
| 1276 |
+
no_voice_keywords = [
|
| 1277 |
+
'не присылай', 'не отправляй', 'не шли', 'не надо голос', 'не голос',
|
| 1278 |
+
'без голосов', 'только текст', 'пиши текст', 'текстом', 'зачем голос',
|
| 1279 |
+
'no voice', 'text only', 'хватит голос', 'голосовые не нужны'
|
| 1280 |
+
]
|
| 1281 |
+
for msg in conversation_history:
|
| 1282 |
+
if getattr(msg, 'sender_type', None) == 'user':
|
| 1283 |
+
msg_text = getattr(msg, 'content', '') or ''
|
| 1284 |
+
if any(kw in msg_text.lower() for kw in no_voice_keywords):
|
| 1285 |
+
user_requested_no_voice = True
|
| 1286 |
+
logger.info(f"🔇 USER REQUESTED NO VOICE (keyword fallback): {msg_text[:50]}")
|
| 1287 |
+
break
|
| 1288 |
+
else:
|
| 1289 |
+
logger.info("🔇 USER REQUESTED NO VOICE (smart LLM detection)")
|
| 1290 |
|
| 1291 |
# If user requested no voice, disable all voice triggers
|
| 1292 |
if user_requested_no_voice:
|
backend/app/services/ai_core/response_generator.py
CHANGED
|
@@ -217,7 +217,8 @@ Message Count: {ai_message_count} (0-1 = Первое сообщение, исп
|
|
| 217 |
"total_tokens": response["total_tokens"],
|
| 218 |
"rag_context_used": False,
|
| 219 |
"products_found": True,
|
| 220 |
-
"scripts_used": 0
|
|
|
|
| 221 |
}
|
| 222 |
|
| 223 |
|
|
|
|
| 217 |
"total_tokens": response["total_tokens"],
|
| 218 |
"rag_context_used": False,
|
| 219 |
"products_found": True,
|
| 220 |
+
"scripts_used": 0,
|
| 221 |
+
"user_requested_no_voice": user_requested_no_voice # Pass to webhook
|
| 222 |
}
|
| 223 |
|
| 224 |
|