feat(ai): clean reasoning content from replies

This commit is contained in:
liuwei
2026-04-07 09:23:48 +08:00
parent 496463c442
commit 51fe971cda
4 changed files with 73 additions and 10 deletions

View File

@@ -21,7 +21,7 @@ from utils.revoke.message_auto_revoke import MessageAutoRevoke
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
from utils.decorator.points_decorator import plugin_points_cost
from utils.media_downloader import MediaDownloader
from utils.string_utils import remove_trailing_content, remove_grok_render_tags
from utils.string_utils import remove_reasoning_content, remove_trailing_content, remove_grok_render_tags
from wechat_ipad import WechatAPIClient
from wechat_ipad.models.message import MessageType
import aiohttp
@@ -250,6 +250,12 @@ class DifyPlugin(MessagePluginInterface):
response: str, roomid: str) -> Tuple[bool, str]:
"""发送响应消息的辅助方法"""
try:
if response and not os.path.isfile(response):
response = remove_reasoning_content(response)
response = remove_trailing_content(response)
response = remove_grok_render_tags(response)
response = re.sub(r'\n{3,}', '\n\n', response).strip()
# 判断是否为本地文件路径
if os.path.isfile(response):
# 如果是文件路径,使用发送文件方法
@@ -549,6 +555,12 @@ class DifyPlugin(MessagePluginInterface):
# 获取token使用情况
total_tokens = response_data.get("data", {}).get("total_tokens", 0)
if answer and not os.path.isfile(answer):
answer = remove_reasoning_content(answer)
answer = remove_trailing_content(answer)
answer = remove_grok_render_tags(answer)
answer = re.sub(r'\n{3,}', '\n\n', answer).strip()
# 更新会话历史
self.conversations[session_id].append({
"role": "user",