Fix speech text truncation bug where Assistant: prefix caused multi-line responses to drop remaining sentences
This commit is contained in:
+4
-2
@@ -46,8 +46,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
|
||||
|
||||
Reference in New Issue
Block a user