Text Moderation (V2)
Function
Moderation (Text) analyzes and identifies whether the uploaded text contains sensitive information and returns the result to you.
- Currently, only Chinese content moderation is supported.
- By default, the maximum number of concurrent API calls is 50. To increase concurrency, contact Huawei technical support.
- 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
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. |
Request 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. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
categories |
No |
Array of strings |
Indicates the detection scenario. Currently, the following scenarios are supported:
|
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:
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. |
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
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. |
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:
|
Status code: 400
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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot