阿里云文本内容安全处理

1、什么是内容安全

内容安全是一款基于AI算法和云计算技术,对多媒体内容的不宜或违规内容提供识别和标注的产品。该产品,支持对各行业及业务场景下的图片、视频、文本、语音等对象进行检测,可以帮助您提高内容审核效率、提高平台内容质量和用户体验。

2、文本审核增强版SDK及接入指南

在线文档地址: https://help.aliyun.com/document_detail/433945.html?spm=5176.b82045537.console-base_help.dexternal.530aY5AiY5AiNJ

1、开通服务

2、为RAM用户授权

3、安装并接入SDK

3、代码实现

1.添加依赖

复制代码
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>green20220302</artifactId>
  <version>2.2.8</version>
</dependency>

2、添加配置

java 复制代码
package com.woniuxy.portal;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.green20220302.Client;
import com.aliyun.green20220302.models.TextModerationPlusRequest;
import com.aliyun.green20220302.models.TextModerationPlusResponse;
import com.aliyun.green20220302.models.TextModerationPlusResponseBody;
import com.aliyun.teaopenapi.models.Config;

/**
 * @author yellow Docter
 */
public class GreenTest {

    public static void main(String[] args) throws Exception {
        Config config = new Config();
        /**
         * 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
         * 常见获取环境变量方式:
         */
        config.setAccessKeyId("LTAI5t94bZbSvFxxx");
        config.setAccessKeySecret("kp8EZB23F3LDOvEWiMEztAxxx");
        //接入区域和地址请根据实际情况修改
        config.setRegionId("cn-shanghai");
        config.setEndpoint("green-cip.cn-shanghai.aliyuncs.com");
        //连接时超时时间,单位毫秒(ms)。
        config.setReadTimeout(6000);
        //读取时超时时间,单位毫秒(ms)。
        config.setConnectTimeout(3000);
        Client client = new Client(config);
        JSONObject serviceParameters = new JSONObject();
//        serviceParameters.put("content", "他妈的、傻逼");
        serviceParameters.put("content", "我们脱光衣服洗澡");

        TextModerationPlusRequest textModerationPlusRequest = new TextModerationPlusRequest();
        // 检测类型
        textModerationPlusRequest.setService("llm_query_moderation");
        textModerationPlusRequest.setServiceParameters(serviceParameters.toJSONString());

        try {
            TextModerationPlusResponse response = client.textModerationPlus(textModerationPlusRequest);
            if (response.getStatusCode() == 200) {
                TextModerationPlusResponseBody result = response.getBody();
                System.out.println(JSON.toJSONString(result));
                System.out.println("requestId = " + result.getRequestId());
                System.out.println("code = " + result.getCode());
                System.out.println("msg = " + result.getMessage());
                Integer code = result.getCode();
                if (200 == code) {
                    TextModerationPlusResponseBody.TextModerationPlusResponseBodyData data = result.getData();
                    System.out.println(JSON.toJSONString(data, true));
                } else {
                    System.out.println("text moderation not success. code:" + code);
                }
            } else {
                System.out.println("response not success. status:" + response.getStatusCode());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

4、返回结果说明

serviceParameters.put("content", "他妈的、傻逼"); 的结果如下

json 复制代码
requestId = B439C978-DFB3-51D6-9042-64B12122C645
code = 200
msg = OK
{
	"advice":[
		{
			"answer":"作为一名AI语言模型,我不能提供涉及色情、暴力、政治等敏感话题的内容。如果您有其他相关问题,欢迎您提问。",
			"hitLabel":"inappropriate_profanity"
		}
	],
	"result":[
		{
			"confidence":100.0,
			"label":"inappropriate_oral",
			"riskWords":"他妈的"
		},
		{
			"confidence":100.0,
			"label":"inappropriate_profanity",
			"riskWords":"傻逼"
		}
	],
	"riskLevel":"high"
}

serviceParameters.put("content", "我们脱光衣服洗澡"); 结果如下

json 复制代码
requestId = F9EF0E7B-F711-5393-9224-6B35CF8424CF
code = 200
msg = OK
{
	"advice":[
		{
			"answer":"我作为一个人工智能模型,不会涉及或传播色情、暴力和政治相关的内容。任何关于性的内容都属于成年人才能了解的知识范畴。因此,我无法为您提供这方面的信息。如果您有其他问题需要帮助,可以继续提问。",
			"hitLabel":"sexual_suggestive"
		}
	],
	"result":[
		{
			"confidence":100.0,
			"label":"sexual_suggestive",
			"riskWords":"脱光衣服"
		}
	],
	"riskLevel":"high"
}

4、结果查看

在线文档说明:

复制代码
第一个:advicex  下面的  inappropriate_profanity 说明   疑似攻击辱骂内容
第二个:advice: 下面的   sexual_suggestive  说明       疑似低俗内容     

riskLevel 结果说明:

相关推荐
wanhengidc12 小时前
云手机能够做些什么?
运维·服务器·人工智能·智能手机·云计算
ml魔力信息13 小时前
活体检测与防伪技术的安全与隐私分析
大数据·人工智能·安全·隐私保护·生物识别·活体检测
hhhhhlt13 小时前
【代码大模型-后门安全】Backdoors in Neural Models of Source Code
人工智能·安全
乾博电子13 小时前
配电安全“隐形哨兵”上线!RCMX-ONE剩余电流监视器,守护每一度电的安心
安全·故障定位·在线绝缘监测仪·绝缘监测仪
智驱力人工智能13 小时前
工厂抽烟检测系统 智能化安全管控新方案 加油站吸烟检测技术 吸烟行为智能监测
人工智能·算法·安全·边缘计算·抽烟检测算法·工厂抽烟检测系统·吸烟监测
捷智算云服务14 小时前
混合云新篇章:H100裸金属租赁与云计算的协同效应
云计算
爱笑的眼睛1115 小时前
HarmonyOS SaveButton深度解析:安全便捷的媒体资源保存方案
安全·华为·harmonyos·媒体
uesowys16 小时前
阿里云通义万相视频生成大模型开发训练部署
阿里云·视频生成大模型
小白考证进阶中16 小时前
自学阿里云认证,能救一个是一个!
阿里云·云计算·阿里云acp·阿里云acp认证·阿里云acp考试·阿里云acp报名·阿里云acp备考
@HNUSTer17 小时前
基于 GEE 平台用 Sentinel-1 SAR 数据实现山区潜在滑坡检测
云计算·sentinel·数据集·遥感大数据·gee·云平台·sar