fix: strip <thought> blocks from Gemma 4 and similar models

This commit is contained in:
flobo3 2026-04-09 17:51:29 +03:00 committed by chengyongru
parent 3bece171c2
commit 7b1ce24600

View File

@ -15,9 +15,12 @@ from loguru import logger
def strip_think(text: str) -> str:
"""Remove <think>…</think> blocks and any unclosed trailing <think> tag."""
"""Remove thinking blocks and any unclosed trailing tag."""
text = re.sub(r"<think>[\s\S]*?</think>", "", text)
text = re.sub(r"<think>[\s\S]*$", "", text)
# Gemma 4 and similar models use <thought>...</thought> blocks
text = re.sub(r"<thought>[\s\S]*?</thought>", "", text)
text = re.sub(r"<thought>[\s\S]*$", "", text)
return text.strip()