Set person information

更新时间:
复制 MD 格式

Use the Go SDK to add a display name and remarks to a custom person in your person library. After you set person information, the name and remarks appear in custom retrieval results for that person.

Usage notes

Setting person information is optional. It attaches metadata—a display name and free-text remarks—to an existing person in your custom person library. This is useful when you want retrieval results to carry identifiable labels or business annotations alongside the match.

This operation fits into the following workflow:

  1. Create a person library.

  2. Add a person to the library.

  3. Set person information (this topic) — optional.

  4. Run custom retrieval to search by face.

Call the SDK using the AI Guardrails API endpoints. For the list of endpoints, see Endpoint.

For the full parameter reference, see API operation for setting person information.

Prerequisites

Before you begin, ensure that you have:

  • Go dependencies installed using the Go version specified in Installation. Using a different Go version causes subsequent operation calls to fail.

  • A custom person already added to your person library (the personId must exist before you can set information for it).

Call the SetPerson operation

The example below initializes a client, builds the request with the target personId, and sends it. Reuse the client instance across calls to improve moderation performance and avoid repeated connections.

package main

import (
    "encoding/json"
    "fmt"
    "os"
    "strconv"

    "github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)

func main() {
    // Initialize the client. Reuse this instance across calls.
    // Get the AccessKey ID and AccessKey secret from environment variables
    // to avoid hardcoding credentials in your code.
    client, err := green.NewClientWithAccessKey(
        "cn-shanghai",
        os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    )
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Build the request body.
    // personId is required. name and note are optional.
    content, _ := json.Marshal(map[string]interface{}{
        "personId": "<your-person-id>", // Required: ID of the custom person
        "name":     "<person-name>",    // Optional: display name
        "note":     "<remarks>",        // Optional: free-text remarks
    })

    request := green.CreateSetPersonRequest()
    request.SetContent(content)

    response, err := client.SetPerson(request)
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    if response.GetHttpStatus() != 200 {
        fmt.Println("Request failed. HTTP status: " + strconv.Itoa(response.GetHttpStatus()))
        return
    }
    fmt.Println(response.GetHttpContentString())
}

Replace the following placeholders before running the example:

PlaceholderDescription
<your-person-id>ID of the custom person. Must already exist in your person library.
<person-name>Display name for the person. Optional.
<remarks>Free-text remarks. Optional.

Parameters

ParameterRequiredDescription
personIdYesID of the custom person to update.
nameNoDisplay name for the person.
noteNoFree-text remarks attached to the person.

After a successful call (HTTP 200), the name and note values appear in subsequent custom retrieval results for this person.

What's next