Spaces:
Running
Running
axeronis commited on
Commit ·
3ff107f
1
Parent(s): af3b3ec
feat: add user_requested_voice flag to trigger voice when user asks for it
Browse files
backend/app/api/webhook.py
CHANGED
|
@@ -1297,8 +1297,15 @@ async def process_ai_response_background(
|
|
| 1297 |
voice_allowed_by_frequency = recent_ai_voice_count < 1 or ai_msg_count % 5 == 0
|
| 1298 |
|
| 1299 |
if not ai_wants_voice and tenant.voice_enabled and not user_requested_no_voice and voice_allowed_by_frequency:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1300 |
# 1. FIRST MESSAGE - greeting (always voice for trust)
|
| 1301 |
-
|
| 1302 |
voice_trigger_reason = "FIRST_MESSAGE"
|
| 1303 |
ai_wants_voice = True
|
| 1304 |
|
|
|
|
| 1297 |
voice_allowed_by_frequency = recent_ai_voice_count < 1 or ai_msg_count % 5 == 0
|
| 1298 |
|
| 1299 |
if not ai_wants_voice and tenant.voice_enabled and not user_requested_no_voice and voice_allowed_by_frequency:
|
| 1300 |
+
# 0. USER EXPLICITLY REQUESTED VOICE - highest priority trigger
|
| 1301 |
+
user_requested_voice = ai_response.get("user_requested_voice", False)
|
| 1302 |
+
if user_requested_voice:
|
| 1303 |
+
voice_trigger_reason = "USER_REQUESTED"
|
| 1304 |
+
ai_wants_voice = True
|
| 1305 |
+
logger.info("🎙️ Voice triggered: USER explicitly requested voice")
|
| 1306 |
+
|
| 1307 |
# 1. FIRST MESSAGE - greeting (always voice for trust)
|
| 1308 |
+
elif is_first_message:
|
| 1309 |
voice_trigger_reason = "FIRST_MESSAGE"
|
| 1310 |
ai_wants_voice = True
|
| 1311 |
|
backend/app/services/ai_core/response_generator.py
CHANGED
|
@@ -93,6 +93,7 @@ async def generate_sales_response_impl(
|
|
| 93 |
# DETECT USER'S LATEST VOICE PREFERENCE
|
| 94 |
# DUAL approach: fast keyword check + smart LLM semantic analysis
|
| 95 |
user_requested_no_voice = False
|
|
|
|
| 96 |
user_messages_with_idx = [(i, get_content(m)) for i, m in enumerate(conversation_history or []) if get_sender_type(m) == 'user']
|
| 97 |
|
| 98 |
# DEBUG: Log what we're checking
|
|
@@ -169,6 +170,7 @@ Answer with ONE word only:
|
|
| 169 |
logger.warning(f"LLM voice preference check failed: {e}")
|
| 170 |
|
| 171 |
user_requested_no_voice = (last_voice_preference == 'no')
|
|
|
|
| 172 |
if last_voice_preference:
|
| 173 |
logger.info(f"📢 FINAL voice preference: {last_voice_preference.upper()}")
|
| 174 |
|
|
@@ -256,7 +258,8 @@ Message Count: {ai_message_count} (0-1 = Первое сообщение, исп
|
|
| 256 |
"rag_context_used": False,
|
| 257 |
"products_found": True,
|
| 258 |
"scripts_used": 0,
|
| 259 |
-
"user_requested_no_voice": user_requested_no_voice # Pass to webhook
|
|
|
|
| 260 |
}
|
| 261 |
|
| 262 |
|
|
|
|
| 93 |
# DETECT USER'S LATEST VOICE PREFERENCE
|
| 94 |
# DUAL approach: fast keyword check + smart LLM semantic analysis
|
| 95 |
user_requested_no_voice = False
|
| 96 |
+
user_requested_voice = False # True when user explicitly asks for voice
|
| 97 |
user_messages_with_idx = [(i, get_content(m)) for i, m in enumerate(conversation_history or []) if get_sender_type(m) == 'user']
|
| 98 |
|
| 99 |
# DEBUG: Log what we're checking
|
|
|
|
| 170 |
logger.warning(f"LLM voice preference check failed: {e}")
|
| 171 |
|
| 172 |
user_requested_no_voice = (last_voice_preference == 'no')
|
| 173 |
+
user_requested_voice = (last_voice_preference == 'yes') # User explicitly wants voice
|
| 174 |
if last_voice_preference:
|
| 175 |
logger.info(f"📢 FINAL voice preference: {last_voice_preference.upper()}")
|
| 176 |
|
|
|
|
| 258 |
"rag_context_used": False,
|
| 259 |
"products_found": True,
|
| 260 |
"scripts_used": 0,
|
| 261 |
+
"user_requested_no_voice": user_requested_no_voice, # Pass to webhook
|
| 262 |
+
"user_requested_voice": user_requested_voice # True when user explicitly asks for voice
|
| 263 |
}
|
| 264 |
|
| 265 |
|