Files
dify-docs/zh-hans/guides/application-orchestrate/app-toolkits/moderation-tool.mdx
2025-04-24 17:16:59 +08:00

31 lines
2.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 敏感内容审查
---
我们在与 AI 应用交互的过程中,往往在内容安全性,用户体验,法律法规等方面有较为苛刻的要求,此时我们需要“敏感词审查”功能,来为终端用户创造一个更好的交互环境。 在提示词编排页面,点击“添加功能”,找到底部的工具箱“内容审核”:
![Content moderation](https://assets-docs.dify.ai/dify-enterprise-mintlify/zh_CN/guides/application-orchestrate/app-toolkits/09c3d5be9b7194e54d0333242c501719.png)
### 功能一:调用 OpenAI Moderation API
OpenAI 和大多数 LLM 公司提供的模型,都带有内容审查功能,确保不会输出包含有争议的内容,比如暴力,性和非法行为,并且 OpenAI 还开放了这种内容审查能力,具体可以参考 [platform.openai.com](https://platform.openai.com/docs/guides/moderation/overview) 。现在你也可以直接在 Dify 上调用 OpenAI Moderation API你可以审核输入内容或输出内容只要输入对应的“预设回复”即可。
![OpenAI Moderation API](https://assets-docs.dify.ai/dify-enterprise-mintlify/zh_CN/guides/application-orchestrate/app-toolkits/6b09f91a05c993e0aa6bb56eca71e607.png)
### 功能二:自定义关键词
开发者可以自定义需要审查的敏感词比如把“kill”作为关键词在用户输入的时候作审核动作要求预设回复内容为“The content is violating usage policies.”可以预见的结果是当用户在终端输入包含“kill”的语料片段就会触发敏感词审查工具返回预设回复内容。
![Keywords](https://assets-docs.dify.ai/dify-enterprise-mintlify/zh_CN/guides/application-orchestrate/app-toolkits/644c2b024f59497aed3cd8ac984c96e3.png)
### 功能三: 敏感词审查 Moderation 扩展
不同的企业内部往往有着不同的敏感词审查机制,企业在开发自己的 AI 应用如企业内部知识库 ChatBot需要对员工输入的查询内容作敏感词审查。为此开发者可以根据自己企业内部的敏感词审查机制写一个 API 扩展,具体可参考 [敏感内容审查](/zh-hans/guides/tools/extensions/api-based/moderation),从而在 Dify 上调用,实现敏感词审查的高度自定义和隐私保护。
![Moderation Settings](https://assets-docs.dify.ai/dify-enterprise-mintlify/zh_CN/guides/application-orchestrate/app-toolkits/d8b6dff6fce6d70795b87aefc56eb02b.png)
比如我们在自己的本地服务中自定义敏感词审查规则:不能查询有关美国总统的名字的问题。当用户在`query`变量输入"Trump",则在对话时会返回 "Your content violates our usage policy." 测试效果如下:
![Moderation Test](https://assets-docs.dify.ai/dify-enterprise-mintlify/zh_CN/guides/application-orchestrate/app-toolkits/970c894a68f017def62c0f7253b0f44e.png)