stream: strip <think> blocks + broaden meta-leak filter for Nemotron reasoning output
Browse files17 unmodified lines18192021222378 unmodified lines1021031041051061071081098 unmodified lines11811912012112212312412517 unmodified linesfrom __future__ import annotationsimport tracebackfrom backend.factory import get_llm78 unmodified linesreturn ", ".join(out)def _clean(text: str) -> str:text = (text or "").strip()# Strip markdown code fences if the model wrapped its reply in them.if text.startswith("```"):text = text.lstrip("`").lstrip()8 unmodified linesMETA_MARKERS = ("the user wants","we need to produce","i'll write","i will write","2-3 sentence","2 to 3 sentence","inner monologue",17 unmodified lines1819202122232478 unmodified lines1031041051061071081091101111121131141151161171181191201218 unmodified lines13013113213313413513613713813914014114214314414514614714817 unmodified linesfrom __future__ import annotationsimport reimport tracebackfrom backend.factory import get_llm78 unmodified linesreturn ", ".join(out)_THINK_RX = re.compile(r"<think>.*?</think>", re.DOTALL | re.IGNORECASE)def _clean(text: str) -> str:text = (text or "").strip()# Nemotron 3 Nano and other reasoning models wrap chain-of-thought in# <think>...</think> blocks; the final answer follows. Drop the block.text = _THINK_RX.sub("", text).strip()# If the reply was truncated mid-reasoning (open tag, no close), drop# everything before the dangling opener so we don't surface meta-text.if "<think>" in text.lower():idx = text.lower().rfind("<think>")text = text[idx + len("<think>"):].lstrip()# Strip markdown code fences if the model wrapped its reply in them.if text.startswith("```"):text = text.lstrip("`").lstrip()8 unmodified linesMETA_MARKERS = ("the user wants","we need to produce","we need to output","i need to output","i need to write","i need to craft","i need to produce","i'll write","i will write","let me craft","let me write","let's craft","let's write","should reflect","should be in","2-3 sentence","2 to 3 sentence","inner monologue",
game/stream.py+23