Text Moderation
Function
This API analyzes and identifies whether the uploaded text contains pornographic elements or politically sensitive words, and returns the result to you.
Prerequisites
- Before using Text Moderation, you need to apply for the service and complete authentication. For details, see Getting Started with Moderation (Text).
- By default, the maximum number of concurrent API calls is 50. To increase concurrency, contact Huawei technical support.
URI
URI format
POST /v1.0/moderation/text
Request Message
Table 1 describes the request parameters.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| items | Yes | Array | Indicates the items to be checked. Currently, only one item can be checked each time. |
| text | Yes | String | Indicates the text to be checked. The encoding format is UTF-8. A maximum of 5,000 characters is allowed. If the number of characters to be checked exceeds the upper limit, only the first 5,000 characters will be checked. |
| type | No | String | Indicates the text type. The default value is content. Currently, only the content type is supported. |
| categories | No | Array | Indicates the detection scenario. Currently, the following scenarios are supported:
|
Response Message
Table 2 describes the response parameters.
| Parameter | Type | Description |
|---|---|---|
| result | Object | Indicates the calling result when the API is successfully called. This parameter is not included when the API fails to be called. |
| detail | Object | Indicates details about the returned check result. Possible values are as follows:
|
| 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 the text needs to be manually reviewed. |
| 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. |
Examples
- Example request
POST https://moderation.cn-north-1.myhuaweicloud.com/v1.0/moderation/text Request Header: Content-Type:application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "categories":["ad","politics","abuse","porn","contraband","flood"], "items":[ { "text": "asdfasdfasdf", "type": "content" } ] }
- Example successful response
{ "result": { "detail": { "flood": "asdfasdfasdf" }, "suggestion": "block" } } - Example failed response
{ "error_code": "AIS.0005", "error_msg": "The service does not exist." }
Status Code
- Normal
- Abnormal
Return Value
Description
400
- The request cannot be understood by the server due to malformed syntax. The client should not repeat the request without modifications.
- The request parameter is incorrect.
401
The request requires user authentication.
403
No operation permission.
404
The server has not found anything matching the Request-URI.
500
The server encountered an unexpected condition which prevented it from fulfilling the request.
Last Article: Moderation (Text)
Next Article: Moderation (Image)
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.