fix: ignore non-string reasoning wrappers

This commit is contained in:
Zhou
2026-06-24 15:45:34 +08:00
committed by Xubin Ren
parent 596bf5398c
commit 35bd1be109
2 changed files with 6 additions and 1 deletions
+3 -1
View File
@@ -130,8 +130,10 @@ def strip_think(text: str) -> str:
return text.strip() return text.strip()
def strip_reasoning_tags(text: str) -> str: def strip_reasoning_tags(text: object) -> str:
"""Remove wrapper tags from text that is already known to be reasoning.""" """Remove wrapper tags from text that is already known to be reasoning."""
if not isinstance(text, str):
return ""
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(r"^\s*<(?:think|thinking|thought)>\s*", "", text) text = re.sub(r"^\s*<(?:think|thinking|thought)>\s*", "", text)
+3
View File
@@ -327,3 +327,6 @@ class TestStripReasoningTags:
assert strip_reasoning_tags("Preparing final response</thinking>") == ( assert strip_reasoning_tags("Preparing final response</thinking>") == (
"Preparing final response" "Preparing final response"
) )
def test_non_string_reasoning_ignored(self):
assert strip_reasoning_tags(object()) == ""