From 65ea3dc582ee99135237be26cce0c6fb02733601 Mon Sep 17 00:00:00 2001 From: StarHeartHunt Date: Mon, 17 Feb 2025 16:12:41 +0800 Subject: [PATCH] :bug: remove tag in normal element --- nonebot_plugin_llmchat/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/nonebot_plugin_llmchat/__init__.py b/nonebot_plugin_llmchat/__init__.py index 168bb3c..95bc743 100644 --- a/nonebot_plugin_llmchat/__init__.py +++ b/nonebot_plugin_llmchat/__init__.py @@ -59,15 +59,13 @@ def pop_reasoning_content( if content is None: return None, None - think_content: Optional[str] = None - # 匹配 标签和其中的内容 - if matched := re.match(r"(.*?)", content, flags=re.DOTALL): - think_content = matched.group(1) - # 如果找到了 标签内容,返回过滤后的文本和标签内的内容,否则只返回过滤后的文本和None - if think_content: - filtered_content = content.replace(think_content, "").strip() - return filtered_content, think_content.strip() + if matched := re.match(r"(.*?)", content, flags=re.DOTALL): + reasoning_element = matched.group(0) + reasoning_content = matched.group(1).strip() + filtered_content = content.replace(reasoning_element, "").strip() + + return filtered_content, reasoning_content else: return content, None