Set Qwen2.5-7B-Instruct-4bit as default MLX model and add spoken text filtering

This commit is contained in:
Adolfo Reyna
2026-08-07 18:46:05 -04:00
parent 3fad171905
commit 1a8a93695b
2 changed files with 26 additions and 3 deletions
+22 -1
View File
@@ -86,13 +86,34 @@ def _latest_user_text(context) -> str:
return ""
import re
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"):
if marker in text:
text = text.split(marker)[0]
# Remove markdown code blocks
text = re.sub(r"```[\s\S]*?```", "", text)
# Remove inline code ticks
text = re.sub(r"`[^`]*`", "", text)
# Remove markdown syntax characters
text = re.sub(r"[\#\*\_\~]", "", text)
# Flatten newlines into clear speech
lines = [line.strip() for line in text.splitlines() if line.strip()]
return " ".join(lines).strip()
class MacOSLLM(FrameProcessor):
"""Runs user turns through macOS native LLM (Apple Intelligence or MLX)."""
def __init__(
self,
*,
model: str = "mlx-community/gemma-2-2b-it-4bit",
model: str = "mlx-community/Qwen2.5-7B-Instruct-4bit",
system_prompt: str | None = None,
observer=None,
**kwargs,