Logo
Section 1 / 2

审核

学习如何使用 OpenAI 的内容审核接口,为语音内容添加各种标签,例如仇恨言论、暴力、自残等。

导入

审核

学习如何使用 OpenAI 的内容审核接口,为语音内容添加各种标签,例如仇恨言论、暴力、自残等。

...
内容审核

代码示例

1https://api.openai.com/v1/moderations

字段格式类型说明
model字符串可选用于请求的模型ID。
input字符串/数组必填需要由API在预定义类别中进行检测并标记的文本内容。

字段格式说明
id字符串当前请求响应的唯一标识符。
model字符串用于生成结果的模型名称。
results数组结果包含三个对象:
flagged(布尔值):表示该文本是否违反OpenAI使用策略的简单分类。
categories(对象):文本被评估的所有预定义类别。若任一类被违反,则对应值为true。
category_scores(对象):文本在各预定义类别中的置信度评分。

类别说明
Hate当语句针对他人基于性别、种族、民族、宗教、国籍、性取向、残障状况或种姓表达、煽动或鼓吹仇恨时,该类别标记为true。
Hate/threatening当语句包含针对上述群体的暴力行为或煽动暴力时,该类别标记为true。
Harassment当语句使用、煽动或鼓吹对任何人进行骚扰性语言时,该类别标记为true。
Harassment/threatening当语句包含对任何人的暴力内容时,该类别标记为true。
Self-harm当语句宣传、鼓励或展示任何形式的自残行为时,该类别标记为true。
Self-harm/intent当用户表达出自残意图或参与自残行为时,该类别标记为true。
Self-harm/instructions当语句提供自残方法或鼓励实施自残行为时,该类别标记为true。
Sexual当语句描述性行为或出于性唤起目的推广性服务时,该类别标记为true(不包括性教育和健康相关内容)。
Sexual/minors当语句涉及未满18周岁的未成年人的性内容时,该类别标记为true。
Violence当语句描绘死亡、暴力或身体伤害时,该类别标记为true。
Violence/graphic当语句以图像化方式描绘死亡、暴力或身体伤害时,该类别标记为true。
...
内容审核:输入与输出模型
1// 定义接口地址 2const endpointUrl = "https://api.openai.com/v1/moderations"; 3 4// 定义请求头参数 5const headerParameters = { 6 "Authorization": "Bearer {{SECRET_KEY}}", 7 "Content-Type": "application/json" 8}; 9 10// 请求体参数 11const bodyParameters = JSON.stringify({ 12 model: "text-moderation-latest", 13 input: ("棕色物种是低等的。") 14}); 15 16// 设置API调用选项 17const options = { 18 method: "POST", 19 headers: headerParameters, 20 body: bodyParameters 21}; 22 23// 发起API调用函数 24async function checkHateSpeech() { 25 try { 26 const response = await fetch(`${endpointUrl}`, options); 27 28 // 输出响应结果 29 printResponse(response); 30 } catch (error) { 31 // 输出错误信息 32 printError(error); 33 } 34} 35 36// 调用函数发起请求 37checkHateSpeech();
1// 定义接口地址 2const endpointUrl = "https://api.openai.com/v1/moderations"; 3 4// 定义请求头参数 5const headerParameters = { 6 "Authorization": "Bearer {{SECRET_KEY}}", 7 "Content-Type": "application/json" 8}; 9 10// 请求体参数 11const bodyParameters = JSON.stringify({ 12 model: "text-moderation-latest", 13 input: ("无名小丑将炸毁哥谭市的一栋大楼。") 14}); 15 16// 设置API调用选项 17const options = { 18 method: "POST", 19 headers: headerParameters, 20 body: bodyParameters 21}; 22 23// 发起API调用函数 24async function checkViolence() { 25 try { 26 const response = await fetch(`${endpointUrl}`, options); 27 28 // 输出响应结果 29 printResponse(response); 30 } catch (error) { 31 // 输出错误信息 32 printError(error); 33 } 34} 35 36// 调用函数发起请求 37checkViolence();
1// 定义接口地址 2const endpointUrl = "https://api.openai.com/v1/moderations"; 3 4// 定义请求头参数 5const headerParameters = { 6 "Authorization": "Bearer {{SECRET_KEY}}", 7 "Content-Type": "application/json" 8}; 9 10// 请求体参数 11const bodyParameters = JSON.stringify({ 12 model: "text-moderation-latest", 13 input: ("小丑大笑时会伤害自己。") 14}); 15 16// 设置API调用选项 17const options = { 18 method: "POST", 19 headers: headerParameters, 20 body: bodyParameters 21}; 22 23// 发起API调用函数 24async function checkSelfHarm() { 25 try { 26 const response = await fetch(`${endpointUrl}`, options); 27 28 // 输出响应结果 29 printResponse(response); 30 } catch (error) { 31 // 输出错误信息 32 printError(error); 33 } 34} 35 36// 调用函数发起请求 37checkSelfHarm();

补全端点

嵌入(Embeddings)