Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 非官方 API 使用 Deepseek R1 模型时,隐藏 <think> 标签内容 #369

Closed
samnyan opened this issue Feb 1, 2025 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@samnyan
Copy link

samnyan commented Feb 1, 2025

现在的<think></think>内容太长,在群里发送比较刷屏。

是不是应该增加一个选项隐藏think内容?

支持编辑消息的平台或许可以显示成 已思考...s

更新:解决方案见 #369 (comment)

@dingyi222666
Copy link
Member

这种标签不是通用标准,ChatLuna 暂时不打算兼容。
但是你可以使用 postHandler,要求模型将内容输出在 output 标签里,然后手动过滤。

或者:

format_user_prompt: |-
  # 当前时间
  {time_UTC+8}
  {weekday}

  # 消息发送者
  QQ 号: {sender_id}
  群昵称: "{sender}"

  # 消息内容
  {prompt}

  # 输出规范
  <output> 将回复内容包裹在 xml 标记中。在一行内输出,不在标记后换行。output 标签是绝对不可以省略的!</output>

config:
  postHandler:
    censor: false
    prefix: '<output>'
    postfix: '</output>'

@dingyi222666 dingyi222666 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2025
@dingyi222666 dingyi222666 self-assigned this Feb 1, 2025
@dingyi222666 dingyi222666 added the enhancement New feature or request label Feb 1, 2025
@samnyan
Copy link
Author

samnyan commented Feb 1, 2025

试了下,本地模型它不太想遵循。。

然后我想着Regex会好一些,不过这个是不是还没有实现

bodyRegex?: RegExp

@dingyi222666
Copy link
Member

dingyi222666 commented Feb 1, 2025

更好的方案是使用 censor 服务过滤 think 标签的内容,你可以看看 https://github.com/Hoshino-Yumetsuki/koishi-plugin-text-censor 。他这个支持正则过滤...

@dingyi222666
Copy link
Member

bodyRegex 这个确实没实现,不过也没实现的打算

@samnyan
Copy link
Author

samnyan commented Feb 1, 2025

试了下不行,然后新建个censor插件print出来看看原因,发现censor服务获取到的内容是不含标签的,可能被koishi当渲染模板去掉了

Image

@dingyi222666
Copy link
Member

Image

看到了,我晚点发个 1.0.1 版本。

@Kimaru-bili
Copy link

不知道为什么 所有插件功能正常,正则表达式也填了,依旧过滤不了think标签里的内容,看了日志也没什么奇怪的地方输出也带think标签,是我写的正则表达式有问题么?😭
Image
Image
Image

Image

@Kimaru-bili
Copy link

Kimaru-bili commented Feb 3, 2025

没有问题了,昨晚看到https://github.com/Hoshino-Yumetsuki/koishi-plugin-text-censor 项目更新了 试了一下成功了,感谢大佬,感谢Hoshino-Yumetsuki更新的过滤器😘

@samnyan
Copy link
Author

samnyan commented Feb 3, 2025

给有这个需求的朋友们指指路:

在插件市场安装 @q78kg/text-censor

Image

然后 text-censor 插件,添加一个正则表达式规则。

规则可以用

^[\s\S]*<\/think>(?![\s\S]*<\/think>)

或者更简单一点的

<think>.*?<\/think>

同时打开是否直接删除敏感词

Image

chatluna 的选项开启 censor,应该就可以了。

如果不行的话,或许要把你现在用的预设,加一个 postHandler

config:
  postHandler:
    censor: true

Image

@dingyi222666 dingyi222666 changed the title [Feature] 隐藏<think>标签内容 [Feature] 非官方 API 使用 Deepseek r1 模型时,隐藏 <think> 标签内容 Feb 3, 2025
@dingyi222666 dingyi222666 pinned this issue Feb 3, 2025
@dingyi222666 dingyi222666 changed the title [Feature] 非官方 API 使用 Deepseek r1 模型时,隐藏 <think> 标签内容 [Feature] 非官方 API 使用 Deepseek R1 模型时,隐藏 <think> 标签内容 Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants