Manual review for text
Updated at:
This topic describes how to use the Go software development kit (SDK) to perform a manual review of text.
Description
If the text detection results do not meet your expectations, you can perform a manual review. For more information about the parameters, see the 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 Go dependencies. See Installation for the required Go version. Using an unsupported version causes subsequent operation calls to fail.
A RAM user AccessKey ID and AccessKey secret stored as environment variables:
ALIBABA_CLOUD_ACCESS_KEY_IDALIBABA_CLOUD_ACCESS_KEY_SECRET
Submit a text manual review task
package main
import (
"encoding/json"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
"strconv"
)
func main() {
/**
* Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common methods to obtain environment variables:
* Obtain the AccessKey ID of a Resource Access Management (RAM) user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* Obtain the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"Get the RAM user AccessKey ID from an environment variable",
"Get the RAM user AccessKey secret from an environment variable")
if _err != nil {
fmt.Println(_err.Error())
return
}
task := map[string]interface{}{"dataId": "Data ID", "content": "Text to be detected"}
// The callback and seed parameters are used for callback notifications and are optional.
content, _ := json.Marshal(
map[string]interface{}{
"tasks": [...]map[string]interface{}{task},
"callback": "Webhook address", "seed": "Random string",
},
)
request := green.CreateTextAsyncManualScanRequest()
request.SetContent(content)
response, err := client.TextAsyncManualScan(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
}
fmt.Println(response.GetHttpContentString())
}Query the result of a text manual review task
package main
import (
"encoding/json"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
"strconv"
)
func main() {
/**
* Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common methods to obtain environment variables:
* Obtain the AccessKey ID of a Resource Access Management (RAM) user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* Obtain the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"Get the RAM user AccessKey ID from an environment variable",
"Get the RAM user AccessKey secret from an environment variable")
if _err != nil {
fmt.Println(_err.Error())
return
}
content, _ := json.Marshal([...]string{"Text manual review task ID"})
request := green.CreateTextAsyncManualScanResultsRequest()
request.SetContent(content)
response, err := client.TextAsyncManualScanResults(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
}
fmt.Println(response.GetHttpContentString())
}Is this page helpful?