Use the AI Guardrails SDK for .NET to create a business scenario, which defines the machine-assisted moderation policy applied when you call the AI Guardrails API. By default, each account can create up to 100 business scenarios.
For the full parameter reference, see CreateBizType.
Prerequisites
Before you begin, ensure that you have:
The .NET dependencies installed using the required .NET version. For instructions, see Install .NET dependencies
Use the .NET version specified in the installation guide. Mismatched versions cause subsequent operation calls to fail.
Supported regions
The CreateBizType operation is available in the following regions:
| Region ID | Location |
|---|---|
cn-shanghai | China (Shanghai) |
cn-beijing | China (Beijing) |
cn-shenzhen | China (Shenzhen) |
ap-southeast-1 | Singapore |
Create a business scenario
Parameters
Before running the sample code, set the following parameters:
| Parameter | Required | Description |
|---|---|---|
BizTypeName | Yes | Name of the business scenario to create. |
BizTypeImport | No | Name of an existing business scenario whose configuration to copy. |
CiteTemplate | No | Set to true to base the scenario on an industry template. When true, IndustryInfo is required. |
IndustryInfo | Conditional | Industry classification. Required when CiteTemplate is true. Valid values: Social-Registration information-Profile picture, Social-Registration information-Nickname. |
Sample code
Replace the following values in the sample code before running it:
BizTypeName: the name of the business scenario to createBizTypeImport: the name of an existing business scenario to import (remove this line if not needed)IndustryInfo: the industry classification (remove this line ifCiteTemplateisfalse)
Store your credentials as environment variables before running the code. The sample reads the AccessKey ID and AccessKey secret from ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20170823;
using System.Collections.Generic;
namespace csharp_sdk_sample
{
class Program
{
static void Main(string[] args)
{
// Read credentials from environment variables
DefaultProfile profile = DefaultProfile.GetProfile(
"cn-shanghai",
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
CreateBizTypeRequest createBizTypeRequest = new CreateBizTypeRequest();
// Name of the business scenario to create
createBizTypeRequest.BizTypeName = "<your-biz-type-name>";
// (Optional) Copy configuration from an existing business scenario
createBizTypeRequest.BizTypeImport = "<existing-biz-type-name>";
// (Optional) Set to true to use an industry template
createBizTypeRequest.CiteTemplate = true;
// Required when CiteTemplate is true
// Valid values: Social-Registration information-Profile picture
// Social-Registration information-Nickname
createBizTypeRequest.IndustryInfo = "Social-Registration information-Profile picture";
createBizTypeRequest.AcceptFormat = FormatType.JSON;
createBizTypeRequest.Method = MethodType.POST;
createBizTypeRequest.Encoding = "utf-8";
try
{
CreateBizTypeResponse response = client.GetAcsResponse(createBizTypeRequest);
if (response.HttpResponse.Status != 200)
{
Console.WriteLine("Request failed. Status: {0}", response.HttpResponse.Status);
}
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (Exception ex)
{
Console.WriteLine("Failed with error: {0}", ex.Message);
}
}
}
}What's next
After creating a business scenario, customize its moderation policy and then pass the scenario name as a parameter when calling the AI Guardrails API.