🐛 filter out think in normal content

This commit is contained in:
StarHeartHunt 2025-02-15 14:46:14 +08:00
parent 65f66be04a
commit 7f284ec4c4

View file

@ -13,6 +13,7 @@ import asyncio
from openai import AsyncOpenAI from openai import AsyncOpenAI
from .config import Config, PresetConfig from .config import Config, PresetConfig
import time import time
import re
import json import json
import os import os
import random import random
@ -37,6 +38,10 @@ __plugin_meta__ = PluginMetadata(
pluginConfig = get_plugin_config(Config).llmchat pluginConfig = get_plugin_config(Config).llmchat
driver = get_driver() driver = get_driver()
def filter_think(content:str) -> str:
filtered_content = re.sub(r"<think>.*?</think>", "", content, flags=re.DOTALL)
return filtered_content.strip()
# 初始化群组状态 # 初始化群组状态
class GroupState: class GroupState:
def __init__(self): def __init__(self):
@ -192,6 +197,9 @@ f'''
) )
logger.debug(f"收到API响应 使用token数{response.usage.total_tokens}") logger.debug(f"收到API响应 使用token数{response.usage.total_tokens}")
if not state.output_reasoning_content:
reply = filter_think(response.choices[0].message.content)
else:
reply = response.choices[0].message.content reply = response.choices[0].message.content
# 请求成功后再保存历史记录保证user和assistant穿插防止R1模型报错 # 请求成功后再保存历史记录保证user和assistant穿插防止R1模型报错