你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
当 Azure OpenAI 的内容筛选系统可以区分提示的各种元素(如系统输入、用户输入和 AI 助手的输出)时,其性能会更好。 对于增强的检测功能,应根据以下建议的方法设置提示格式。
聊天完成 API 中的默认行为
聊天完成 API 是按定义构建的。 输入包括一个消息列表,每个消息都有一个分配的角色。
安全系统会分析此结构化格式并应用以下行为:
- 在最新的“用户”内容中,检测到以下类别的 RAI 风险:
- 仇恨
- 性
- 暴力
- 自残
- 提示防护(可选)
这是一个示例消息数组:
{"role": "system", "content": "Provide some context and/or instructions to the model."},
{"role": "user", "content": "Example question goes here."},
{"role": "assistant", "content": "Example answer goes here."},
{"role": "user", "content": "First question/message for the model to actually respond to."}
在提示中嵌入文档
除了对上一个用户内容进行检测外,Azure OpenAI 还支持通过 Prompt Shields ( 间接提示攻击检测)检测上下文文档中的特定风险。 您应该使用以下文档分隔符来标识输入中作为文档(例如,检索的网站、电子邮件等)的部分。
\"\"\" <documents> *insert your document content here* </documents> \"\"\"
当您这样做时,以下选项可以用于检测已标记的文档:
- 间接攻击(可选)
下面是聊天补全消息数组示例:
{"role": "system", "content": "Provide some context and/or instructions to the model.},
{"role": "user", "content": "First question/message for the model to actually respond to, including document context. \"\"\" <documents>\n*insert your document content here*\n</documents> \"\"\"""}
JSON 转义
在标记未经审查的文档以进行检测时,文档内容应经过 JSON 转义,以确保 Azure OpenAI 安全系统成功分析。
例如,请参阅以下电子邮件正文:
Hello Josè,
I hope this email finds you well today.
通过 JSON 转义,它将读作:
Hello Jos\u00E9,\nI hope this email finds you well today.
聊天完成上下文中的转义文本将读作:
{"role": "system", "content": "Provide some context and/or instructions to the model, including document context. \"\"\" <documents>\n Hello Jos\\u00E9,\\nI hope this email finds you well today. \n</documents> \"\"\""},
{"role": "user", "content": "First question/message for the model to actually respond to."}