├── README.md ├── _conf_schema.json ├── main.py └── metadata.yaml /README.md: -------------------------------------------------------------------------------- 1 | # deepseek-r1-filter 2 | 3 | 这个插件可以选择是否显示 Deepseek-R1 模型产生的思考内容。 4 | 5 | This plugin provides a way to show the reasoning content or not. 6 | -------------------------------------------------------------------------------- /_conf_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "display_reasoning_text": { 3 | "description": "显示思考内容", 4 | "type": "bool" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import re 2 | from astrbot.api.event import filter, AstrMessageEvent 3 | from astrbot.api.star import Context, Star, register 4 | from astrbot.api.provider import LLMResponse 5 | from openai.types.chat.chat_completion import ChatCompletion 6 | 7 | @register("r1-filter", "Soulter", "可选择是否过滤推理模型的思考内容", "1.0.0", 'https://github.com/Soulter/astrbot_plugin_r1_filter') 8 | class R1Filter(Star): 9 | def __init__(self, context: Context, config: dict): 10 | super().__init__(context) 11 | self.config = config 12 | self.display_reasoning_text = self.config.get('display_reasoning_text', True) 13 | 14 | @filter.on_llm_response() 15 | async def resp(self, event: AstrMessageEvent, response: LLMResponse): 16 | if self.display_reasoning_text: 17 | if response and response.raw_completion and isinstance(response.raw_completion, ChatCompletion): 18 | if len(response.raw_completion.choices) \ 19 | and response.raw_completion.choices[0].message: 20 | message = response.raw_completion.choices[0].message 21 | reasoning_content = "" # 初始化 reasoning_content 22 | 23 | # 检查 Groq deepseek-r1-distill-llama-70b模型的 'reasoning' 属性 24 | if hasattr(message, 'reasoning') and message.reasoning: 25 | reasoning_content = message.reasoning 26 | # 检查 DeepSeek deepseek-reasoner模型的 'reasoning_content' 27 | elif hasattr(message, 'reasoning_content') and message.reasoning_content: 28 | reasoning_content = message.reasoning_content 29 | 30 | if reasoning_content: 31 | response.completion_text = f"🤔思考:{reasoning_content}\n\n{message.content}" 32 | else: 33 | response.completion_text = message.content 34 | 35 | else: 36 | # DeepSeek 官方的模型的思考存在了 reason_content 字段因此不需要过滤 37 | completion_text = response.completion_text 38 | # 适配 ollama deepseek-r1 模型 39 | if r'' in completion_text or r'' in completion_text: 40 | completion_text = re.sub(r'.*?', '', completion_text, flags=re.DOTALL).strip() 41 | # 可能有单标签情况 42 | completion_text = completion_text.replace(r'', '').replace(r'', '').strip() 43 | response.completion_text = completion_text 44 | -------------------------------------------------------------------------------- /metadata.yaml: -------------------------------------------------------------------------------- 1 | name: r1-filter # 这是你的插件的唯一识别名。 2 | desc: 可选择是否过滤推理模型的思考内容 # 插件简短描述 3 | help: # 插件的帮助信息 4 | version: v1.0.0 # 插件版本号。格式:v1.1.1 或者 v1.1 5 | author: Soulter # 作者 6 | repo: https://github.com/Soulter/astrbot_plugin_r1_filter # 插件的仓库地址 7 | --------------------------------------------------------------------------------