fix(utils): cover complete trailing think markers

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-05-01 20:09:59 +08:00
committed by Xubin Ren
parent 2c397ad442
commit 188e6df757
3 changed files with 25 additions and 2 deletions
+2 -2
View File
@@ -63,8 +63,8 @@ def strip_think(text: str) -> str:
# Stream chunks may end in the middle of a control tag. Strip only known
# control-token prefixes at the very end.
partial_control_tag = (
r"</?(?:t|th|thi|thin|think|tho|thou|thoug|though|thought)"
r"|<\|?(?:c|ch|cha|chan|chann|channe|channel|channel\|?)"
r"</?(?:t|th|thi|thin|think|tho|thou|thoug|though|thought)>?"
r"|<\|?(?:c|ch|cha|chan|chann|channe|channel)(?:\|?>?)?"
)
text = re.sub(rf"(?:{partial_control_tag})$", "", text)
text = re.sub(r"^\s*<\|?$", "", text)