Fix speech text truncation bug where Assistant: prefix caused multi-line responses to drop remaining sentences

This commit is contained in:
Adolfo Reyna
2026-08-07 20:04:34 -04:00
parent af15e64e0a
commit ba16e9ca27
3 changed files with 12 additions and 6 deletions
+4 -2
View File
@@ -42,8 +42,10 @@ def _clean_spoken_text(text: str) -> str:
"""Clean text for speech output and truncate fake turn generations."""
if not text:
return ""
# Truncate if model hallucinates fake turn markers
for marker in ("User:", "Human:", "Assistant:", "\nUser", "\nHuman", "\nAssistant"):
# Strip leading or inline role headers (e.g. "Assistant:")
text = re.sub(r"(?i)\b(Assistant|assistant|Bot|bot):\s*", "", text)
# Truncate if model hallucinates fake subsequent user turns
for marker in ("\nUser:", "\nHuman:", "\nUser", "\nHuman"):
if marker in text:
text = text.split(marker)[0]
# Remove markdown code blocks