Fix speech text truncation bug where Assistant: prefix caused multi-line responses to drop remaining sentences
This commit is contained in:
+4
-2
@@ -92,8 +92,10 @@ def _clean_spoken_text(text: str) -> str:
|
|||||||
"""Clean text for speech output and truncate fake turn generations."""
|
"""Clean text for speech output and truncate fake turn generations."""
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
# Truncate if model hallucinates fake turn markers
|
# Strip leading or inline role headers (e.g. "Assistant:")
|
||||||
for marker in ("User:", "Human:", "Assistant:", "\nUser", "\nHuman", "\nAssistant"):
|
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:
|
if marker in text:
|
||||||
text = text.split(marker)[0]
|
text = text.split(marker)[0]
|
||||||
# Remove markdown code blocks
|
# Remove markdown code blocks
|
||||||
|
|||||||
+4
-2
@@ -42,8 +42,10 @@ def _clean_spoken_text(text: str) -> str:
|
|||||||
"""Clean text for speech output and truncate fake turn generations."""
|
"""Clean text for speech output and truncate fake turn generations."""
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
# Truncate if model hallucinates fake turn markers
|
# Strip leading or inline role headers (e.g. "Assistant:")
|
||||||
for marker in ("User:", "Human:", "Assistant:", "\nUser", "\nHuman", "\nAssistant"):
|
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:
|
if marker in text:
|
||||||
text = text.split(marker)[0]
|
text = text.split(marker)[0]
|
||||||
# Remove markdown code blocks
|
# Remove markdown code blocks
|
||||||
|
|||||||
+4
-2
@@ -46,8 +46,10 @@ def _clean_spoken_text(text: str) -> str:
|
|||||||
"""Clean text for speech output and truncate fake turn generations."""
|
"""Clean text for speech output and truncate fake turn generations."""
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
# Truncate if model hallucinates fake turn markers
|
# Strip leading or inline role headers (e.g. "Assistant:")
|
||||||
for marker in ("User:", "Human:", "Assistant:", "\nUser", "\nHuman", "\nAssistant"):
|
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:
|
if marker in text:
|
||||||
text = text.split(marker)[0]
|
text = text.split(marker)[0]
|
||||||
# Remove markdown code blocks
|
# Remove markdown code blocks
|
||||||
|
|||||||
Reference in New Issue
Block a user