fix(voice): harden noisy streaming turns

This commit is contained in:
Yera All
2026-04-17 00:30:41 +05:00
parent 8ca5f23e93
commit 39096e114f
6 changed files with 267 additions and 15 deletions
+33
View File
@@ -930,6 +930,19 @@ def _voice_topic_prompt(language: str, caller_texts: list[str]) -> str | None:
return None
def _voice_summary_slot_prompt(language: str, context_summary: str | dict[str, Any] | None) -> str | None:
summary = load_context_summary(context_summary)
intent = str(summary.get("active_intent") or "").strip()
facts = summary.get("confirmed_facts") if isinstance(summary.get("confirmed_facts"), dict) else {}
city = str(facts.get("city") or "").strip()
branch_hint = str(facts.get("branch_hint") or "").strip()
if intent == "schedule" and city and not branch_hint:
if language == "kz":
return f"{city} qalasy boiynsha qaysy filial nemese mekenjai qyzyqtyratynyn aitnyz."
return f"По городу {city} уточните, пожалуйста, филиал или адрес."
return None
def _voice_generic_prompt(language: str) -> str:
if language == "kz":
return "Jyldam komektesu ushin eki ush sozben ne kerek ekenin aitnyz: jumys uaqyty, otinish statusy, tarif nemese operator."
@@ -1850,6 +1863,26 @@ def _voice_decision(
decision["metadata"] = v2_metadata
return decision
summary_slot_prompt = _voice_summary_slot_prompt(language, context_summary)
if not kb_results and summary_slot_prompt:
decision = {
"language": language,
"intent": "clarification",
"reply_text": summary_slot_prompt,
"confidence": 0.72,
"needs_handoff": False,
"handoff_reason": None,
"case_action": "keep_open",
"kb_refs": [],
"summary_text": "AI продолжил активный сценарий из conversation summary и уточнил недостающий слот.",
"model": "voice_policy_context_summary",
"latency_ms": 1,
}
if v2_metadata:
decision["reply_text"] = _voice_compact_reply_text(decision["reply_text"], language=language)
decision["metadata"] = {**v2_metadata, "reply_phase": "final"}
return decision
llm_decision = _voice_llm_decision(
language=language,
customer=customer,