Share via


ContentSafetyClient.AddBlockItemsAsync Method

Definition

Overloads

AddBlockItemsAsync(String, AddBlockItemsOptions, CancellationToken)

Add BlockItems To Text Blocklist.

AddBlockItemsAsync(String, RequestContent, RequestContext)

[Protocol Method] Add BlockItems To Text Blocklist

AddBlockItemsAsync(String, AddBlockItemsOptions, CancellationToken)

Source:
ContentSafetyClient.cs

Add BlockItems To Text Blocklist.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AddBlockItemsResult>> AddBlockItemsAsync (string blocklistName, Azure.AI.ContentSafety.AddBlockItemsOptions addBlockItemsOptions, System.Threading.CancellationToken cancellationToken = default);
abstract member AddBlockItemsAsync : string * Azure.AI.ContentSafety.AddBlockItemsOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AddBlockItemsResult>>
override this.AddBlockItemsAsync : string * Azure.AI.ContentSafety.AddBlockItemsOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AddBlockItemsResult>>
Public Overridable Function AddBlockItemsAsync (blocklistName As String, addBlockItemsOptions As AddBlockItemsOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AddBlockItemsResult))

Parameters

blocklistName
String

Text blocklist name.

addBlockItemsOptions
AddBlockItemsOptions

The request of adding blockItems to text blocklist.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

blocklistName or addBlockItemsOptions is null.

blocklistName is an empty string, and was expected to be non-empty.

Examples

This sample shows how to call AddBlockItemsAsync with required parameters.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new ContentSafetyClient(endpoint, credential);

var addBlockItemsOptions = new AddBlockItemsOptions(new TextBlockItemInfo[] 
{
    new TextBlockItemInfo("<text>")
{
        Description = "<Description>",
    }
});
var result = await client.AddBlockItemsAsync("<blocklistName>", addBlockItemsOptions);

Remarks

Add blockItems to a text blocklist. You can add at most 100 BlockItems in one request.

Applies to

AddBlockItemsAsync(String, RequestContent, RequestContext)

Source:
ContentSafetyClient.cs

[Protocol Method] Add BlockItems To Text Blocklist

public virtual System.Threading.Tasks.Task<Azure.Response> AddBlockItemsAsync (string blocklistName, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member AddBlockItemsAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.AddBlockItemsAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function AddBlockItemsAsync (blocklistName As String, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

blocklistName
String

Text blocklist name.

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

blocklistName or content is null.

blocklistName is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call AddBlockItemsAsync with required parameters and request content and parse the result.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new ContentSafetyClient(endpoint, credential);

var data = new {
    blockItems = new[] {
        new {
            description = "<description>",
            text = "<text>",
        }
    },
};

Response response = await client.AddBlockItemsAsync("<blocklistName>", RequestContent.Create(data), new RequestContext());

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("value")[0].GetProperty("blockItemId").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("value")[0].GetProperty("text").ToString());

Applies to