Manual review for text
This topic describes how to use the PHP software development kit (SDK) to perform a manual review of text.
Description
If you believe the text detection results do not meet your expectations, you can perform a manual review. For more information about the parameters, see Text manual review API documentation.
You must use the AI Guardrails endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.
Prerequisites
Before you begin, make sure you have:
Installed PHP dependencies using the required PHP version. Using a different version causes operation calls to fail. See Install PHP dependencies.
An Alibaba Cloud RAM user with AccessKey ID and AccessKey secret stored as environment variables:
ALIBABA_CLOUD_ACCESS_KEY_IDALIBABA_CLOUD_ACCESS_KEY_SECRET
Submit a manual review task for text
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
/**
* Note: To improve detection performance, reuse the instantiated client as much as possible. This avoids repeatedly establishing connections.
* Common methods to obtain environment variables:
* Obtain the AccessKey ID of a Resource Access Management (RAM) user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
* Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
*/
AlibabaCloud::accessKeyClient('Obtain the AccessKey ID of the RAM user from an environment variable', 'Obtain the AccessKey secret of the RAM user from an environment variable')
->timeout(10) // Timeout period: 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout period configured.
->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout period configured.
->regionId('cn-shanghai')
->asDefaultClient();
$task1 = array('dataId' => 'Business data ID', 'content' => 'Text to be moderated');
// The callback and seed parameters are optional and used for callback notifications.
$response = Green::v20180509()->textAsyncManualScan()
->timeout(10) // Timeout period: 10 seconds. This request-level timeout setting is valid only for the current request.
->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This request-level timeout setting is valid only for the current request.
->body(json_encode(array('tasks' => array($task1),
'callback' => 'Webhook address',
'seed' => 'Random string')))
->request();
print_r($response->toArray());
} catch (ClientException $exception) {
echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
echo $exception->getMessage() . PHP_EOL;
echo $exception->getErrorCode() . PHP_EOL;
echo $exception->getRequestId() . PHP_EOL;
echo $exception->getErrorMessage() . PHP_EOL;
}Query the result of a manual review task for text
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
/**
* Note: To improve detection performance, reuse the instantiated client as much as possible. This avoids repeatedly establishing connections.
* Common methods to obtain environment variables:
* Obtain the AccessKey ID of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
* Obtain the AccessKey secret of a RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
*/
AlibabaCloud::accessKeyClient('Obtain the AccessKey ID of the RAM user from an environment variable', 'Obtain the AccessKey secret of the RAM user from an environment variable')
->timeout(10) // Timeout period: 10 seconds. This setting applies to all requests that use this client and do not have a separate timeout period configured.
->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This setting applies to all requests that use this client and do not have a separate connection timeout period configured.
->regionId('cn-shanghai')
->asDefaultClient();
$response = Green::v20180509()->textAsyncManualScanResults()
->timeout(10) // Timeout period: 10 seconds. This request-level timeout setting is valid only for the current request.
->connectTimeout(3) // Connection timeout period: 3 seconds. If the unit is less than 1, it is automatically converted to milliseconds. This request-level timeout setting is valid only for the current request.
->body(json_encode(array('Manual text review task ID')))
->request();
print_r($response->toArray());
} catch (ClientException $exception) {
echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
echo $exception->getMessage() . PHP_EOL;
echo $exception->getErrorCode() . PHP_EOL;
echo $exception->getRequestId() . PHP_EOL;
echo $exception->getErrorMessage() . PHP_EOL;
}