fix: buffer split reasoning wrapper deltas

maintainer edit: native reasoning streams can split <thinking> wrapper tags across chunks. Buffer the stream and emit only cleaned incremental reasoning so raw partial tags do not reach WebUI.
This commit is contained in:
chengyongru authored and Xubin Ren committed 2026-06-24 15:45:34 +08:00
1 parent 35bd1be109
commit 98dd883ce8
3 files changed
+16 -5

No files matched your search

+5
View File
@@ -134,10 +134,15 @@ def strip_reasoning_tags(text: object) -> str:
"""Remove wrapper tags from text that is already known to be reasoning."""
if not isinstance(text, str):
return ""
partial_reasoning_tag = (
r"</?(?:t|th|thi|thin|think|thinki|thinkin|thinking|tho|thou|thoug|though|thought)>?"
)
text = re.sub(rf"^\s*(?:{partial_reasoning_tag})$", "", text)
text = re.sub(r"^\s*<(?:think|thinking|thought)/>\s*", "", text)
text = re.sub(r"\s*<(?:think|thinking|thought)/>\s*$", "", text)
text = re.sub(r"^\s*<(?:think|thinking|thought)>\s*", "", text)
text = re.sub(r"\s*</(?:think|thinking|thought)>\s*$", "", text)
text = re.sub(rf"\s*(?:{partial_reasoning_tag})$", "", text)
return text.strip()