Updated on 2024-03-27 GMT+08:00

Text Moderation (V2)

Function

Moderation (Text) analyzes and identifies whether the uploaded text contains sensitive information and returns the result to you.

  1. Currently, only Chinese content moderation is supported.
  2. By default, the maximum number of concurrent API calls is 50. To increase concurrency, contact Huawei technical support.
  3. You can configure a custom dictionary to filter and detect specified text content. For details about how to create and use a custom dictionary, see Configuring a Custom Dictionary.

Prerequisites

Before using Text Moderation, you need to apply for the service and complete authentication. For details, see Getting Started with Moderation (Text).

URI

POST /v2/{project_id}/moderation/text

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Indicates the user token.

Used to obtain the permission to operate APIs. For details about how to obtain the token, see Authentication. The value of X-Subject-Token in the response header is the token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

categories

No

Array of strings

Indicates the detection scenario.

Currently, the following scenarios are supported:

  • Default scenarios:
    • porn: indicates pornographic information detection.
    • abuse: indicates offensive content detection.
    • contraband: indicates contraband information detection.
    • flood: indicates the spamming detection. (Spamming refers to one or more digits, characters, or punctuations that appear repeatedly in a text.)
  • Custom scenario: custom blocklist dictionary
    NOTE:
    • In the default scenarios, AI-based text detection technology is used to identify the text you upload. In the custom scenario, you can configure a blocklist library to filter and detect specified text.
    • For details about how to create and use a custom dictionary, see Configuring a Custom Dictionary.
    • The custom allowlist dictionary cannot be used in the flood scenario.

white_glossaries

No

Array of strings

Indicates the enabled whitelists. If this parameter is not set, the whitelist dictionaries created before 16:00:00 on September 2, 2022 are used by default.

The rules for configuring this parameter are as follows:
  • If you set this parameter to an empty list (that is, [ ]), no whitelist dictionary will be used.
  • If you set this parameter to the name of the whitelist dictionary you have created, the dictionary will be used.
    NOTE:

    If you want to use multiple whitelist dictionaries, for example, A, B, and C, set this parameter to ["A", "B", "C"].

For details about how to create and use whitelist dictionaries, see Creating a Custom Allowlist Dictionary.

items

Yes

Array of TextDetectionItemsReq objects

Indicates the items to be checked. Currently, only one item can be checked each time.

Table 4 TextDetectionItemsReq parameters

Parameter

Mandatory

Type

Description

text

Yes

String

Indicates the text to be detected. The text is encoded using UTF-8 and contains 1 to 5,000 characters. If the text contains more than 5,000 characters, only the first 5,000 characters are detected.

type

No

String

Indicates the text type. The default value is content. Currently, only the content type is supported.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

result

result object

Indicates the calling result of a successful API call.

This parameter is not included when the API fails to be called.

Table 6 result parameters

Parameter

Type

Description

suggestion

String

Indicates whether the check is passed.

block: indicates that sensitive information is detected and the information fails to pass the check.

pass: indicates that no sensitive information is detected and the information passes the check.

review: indicates that a manual review is required.

detail

Object

Indicates details about the returned check result. Possible values are as follows:

  • porn: indicates a list of pornographic words.
  • abuse: indicates a list of offensive words.
  • contraband: indicates a list of words related to contraband.
  • flood: indicates spam, or unwanted content particularly in forums that provide little value to readers.
    NOTE:
    • The spam content contains a maximum of 200 characters.
    • The details about the returned check result of each scenario refer to only the detected words instead of the whole content.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Indicates the error code of a failed API call. For details, see Error Codes.

This parameter is not included when the API is successfully called.

error_msg

String

Indicates the error message of a failed API call.

This parameter is not included when the API is successfully called.

fail_category

String

Indicates the API calling failure scenario when there are multiple scenarios.

Example Requests

Check whether the asdfasdfasdf text contains sensitive content, including advertisements, abuse, porn, contraband, and spam.

endpoint is the request URL for calling an API. Endpoints vary depending on services and regions. For details, see Endpoints.

For example, the endpoint of the service deployed in the CN-Hong Kong region is moderation.ap-southeast-1.myhuaweicloud.com, the request URL is https://moderation.ap-southeast-1.myhuaweicloud.com/v2/{project_id}/moderation/text, and project_id is the project ID. For details, see Obtaining a Project ID and Name.

POST https://{endpoint}/v2/{project_id}/moderation/text

{
  "categories" : [  "abuse", "porn", "contraband", "flood" ],
  "items" : [ {
    "text" :  "asdfasdfasdf",
    "type" : "content"
  }
 ]
}

Example Responses

Status code: 200

Example of a successful response

{
  "result" : {
    "detail" : {
      "abuse" : [ "fuck" ]
    },
    "suggestion" : "block"
  }
}

Status code: 400

Example of a failed response

{
  "error_code" : "AIS.0005",
  "error_msg" : "The service does not exist."
}

Status Codes

Status Code

Description

200

Example of a successful response

400

Example of a failed response

Error Codes

For details, see Error Codes.