fix(utils): anchor unclosed think-tag regex to string start (#3004)

This commit is contained in:
04cb
2026-04-11 13:46:15 +08:00
committed by Xubin Ren
parent 9bccfa63d2
commit e392c27f7e
2 changed files with 31 additions and 2 deletions
+2 -2
View File
@@ -17,10 +17,10 @@ from loguru import logger
def strip_think(text: str) -> str:
"""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)
text = re.sub(r"^\s*<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)
text = re.sub(r"^\s*<thought>[\s\S]*$", "", text)
return text.strip()