Merge pull request #10 from StarHeartHunt/fix/reasoning-tag

Fix: 移除普通内容里的 `<think>` 标签
This commit is contained in:
FuQuan233 2025-02-17 16:36:20 +08:00 committed by GitHub
commit 54e4766dfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -59,15 +59,13 @@ def pop_reasoning_content(
if content is None: if content is None:
return None, None return None, None
think_content: Optional[str] = None
# 匹配 <think> 标签和其中的内容
if matched := re.match(r"<think>(.*?)</think>", content, flags=re.DOTALL):
think_content = matched.group(1)
# 如果找到了 <think> 标签内容返回过滤后的文本和标签内的内容否则只返回过滤后的文本和None # 如果找到了 <think> 标签内容返回过滤后的文本和标签内的内容否则只返回过滤后的文本和None
if think_content: if matched := re.match(r"<think>(.*?)</think>", content, flags=re.DOTALL):
filtered_content = content.replace(think_content, "").strip() reasoning_element = matched.group(0)
return filtered_content, think_content.strip() reasoning_content = matched.group(1).strip()
filtered_content = content.replace(reasoning_element, "").strip()
return filtered_content, reasoning_content
else: else:
return content, None return content, None