Use the AI Guardrails SDK for Python to create a business scenario. A business scenario lets you define a custom machine-assisted moderation policy that the AI Guardrails API applies when moderating content.
Prerequisites
Before you begin, make sure you have:
Python dependencies installed. See Installation for the required Python version. Using a different version causes subsequent operation calls to fail.
The Extension.Uploader utility class downloaded and imported into your project
Operation and supported regions
The CreateBizType operation creates a business scenario in the Content Moderation service. You can optionally copy the configuration from an existing business scenario or base the new scenario on a built-in industry template.
CreateBizType is available in the following regions:
| Region ID | Region |
|---|---|
cn-shanghai | China (Shanghai) |
cn-beijing | China (Beijing) |
cn-shenzhen | China (Shenzhen) |
ap-southeast-1 | Singapore |
Create a business scenario
# coding=utf-8
import os
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20170823 import CreateBizTypeRequest
# Reuse this client instance across calls to improve performance
# and avoid repeated connection overhead.
clt = client.AcsClient(
os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"), # AccessKey ID
os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), # AccessKey secret
"cn-shanghai"
)
region_provider.modify_point("Green", "cn-shanghai", "green.cn-shanghai.aliyuncs.com")
request = CreateBizTypeRequest.CreateBizTypeRequest()
# Required: name for the new business scenario
request.set_BizTypeName("Name of the business scenario")
# Optional: copy configuration from an existing business scenario
request.set_BizTypeImport("Name of an existing business scenario to be imported")
# Optional: use a built-in industry template instead
# If set to True, IndustryInfo is required
request.set_CiteTemplate(True)
request.set_IndustryInfo("Social-Registration information-Profile picture")
request.set_accept_format("JSON")
response = clt.do_action_with_exception(request)
print(response)Store your AccessKey ID and AccessKey secret in environment variables rather than hardcoding them in your source code. Hardcoded credentials are a security risk and can be accidentally committed to version control.
Request parameters
| Parameter | Required | Type | Description | Example |
|---|---|---|---|---|
BizTypeName | Yes | String | Name of the business scenario to create. | my-social-scenario |
BizTypeImport | No | String | Name of an existing business scenario whose configuration to copy. Omit this parameter to start with an empty configuration. | default-scenario |
CiteTemplate | No | Boolean | Set to true to base the scenario on a built-in industry template. If true, IndustryInfo is required. | true |
IndustryInfo | Required if CiteTemplate is true | String | Industry classification for the template. Valid values: Social-Registration information-Profile picture, Social-Registration information-Nickname. | Social-Registration information-Profile picture |
What's next
After creating a business scenario, configure a moderation policy for it and use the business scenario name when calling the AI Guardrails API to apply your custom policy to content moderation requests.