### Install SDK Dependencies Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Command to install the Azure Content Safety REST client library. ```bash npm install @azure-rest/ai-content-safety ``` -------------------------------- ### Install dependencies and configure Python client Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-custom-categories Installs the requests library and sets up the authentication headers for API requests. ```bash pip install requests ``` ```python import requests API_KEY = '' ENDPOINT = '' headers = { 'Ocp-Apim-Subscription-Key': API_KEY, 'Content-Type': 'application/json' } ``` -------------------------------- ### Install Azure AI Content Safety SDK Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Use pip to install the required client library for Python. ```bash python -m pip install azure-ai-contentsafety ``` -------------------------------- ### Install Development Dependencies Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Command to install TypeScript and Node type definitions. ```bash npm install typescript @types/node --save-dev ``` -------------------------------- ### Install Dependencies Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Commands to install the Azure AI Content Safety SDK and the dotenv module for environment variable management. ```bash npm install @azure-rest/ai-content-safety ``` ```bash npm install dotenv ``` -------------------------------- ### Install Python requests library Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories Install the necessary dependency for making HTTP requests in Python. ```bash pip install requests ``` -------------------------------- ### Example Docker Image Output Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/containers/install-run-container Shows the expected output format when listing downloaded container images. ```text IMAGE ID REPOSITORY TAG ``` -------------------------------- ### Start the category build process using cURL Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories Initiates the training process for a specific category version. Append the version number obtained from the creation step to the URL. ```bash curl -X POST "/contentsafety/text/categories/survival-advice:build?api-version=2024-09-15-preview&version={version}" \ -H "Ocp-Apim-Subscription-Key: " \ -H "Content-Type: application/json" ``` -------------------------------- ### Install Azure AI Content Safety SDK Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Adds the required NuGet package to the .NET project. ```bash dotnet add package Azure.AI.ContentSafety ``` -------------------------------- ### View Output Example Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Displays the expected severity scores for content categories after analysis. ```text Hate severity: 0 SelfHarm severity: 0 Sexual severity: 0 Violence severity: 0 ``` -------------------------------- ### Run Content Safety Container with Logging Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/containers/install-run-container Starts the container with default console logging enabled for troubleshooting purposes. ```bash docker run --rm -it -p 5000:5000 --memory 12g --cpus 6 \ mcr.microsoft.com/azure-cognitive-services/content safetyservices/neural-text-to-content safety \ Eula=accept \ Billing={ENDPOINT_URI} \ ApiKey={API_KEY} \ Logging:Console:LogLevel:Default=Information ``` -------------------------------- ### Get the incident sample details Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Look up details about a specific incident sample using its ID. ```Bash curl --location GET 'https:///contentsafety/image/incidents//incidentsamples/?api-version=2024-02-15-preview' \ --header 'Ocp-Apim-Subscription-Key: ' ``` ```Python import requests url = "https:///contentsafety/image/incidents//incidentsamples/?api-version=2024-02-15-preview" payload = {} headers = { 'Ocp-Apim-Subscription-Key': '' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Blocklist Operation Output Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-blocklist Example console output showing the result of updating a blocklist and matching items. ```text Blocklist ProductSaleBlocklist updated. BlockItems added: BlockItemId: 6155969c-1589-4c27-8cb0-61758985b2d9, Text: price, Description: Price word BlockItemId: 0ca9ff49-d89b-4ecd-a451-28bd303342e1, Text: offer, Description: Offer word Blocklist match result: BlocklistName: ProductSaleBlocklist, BlockItemId: 6155969c-1589-4c27-8cb0-61758985b2d9, BlockItemText: price ``` -------------------------------- ### Analyze Image Output Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Example output showing severity levels for different content categories. ```text Hate severity: 0 SelfHarm severity: 0 Sexual severity: 0 Violence severity: 0 ``` -------------------------------- ### Create and use a custom blocklist in TypeScript Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-blocklist This example covers the full lifecycle of a blocklist: creating the container, adding terms, and performing text analysis. Note that changes to blocklists may take a few minutes to propagate. ```TypeScript import ContentSafetyClient, { isUnexpected, CreateOrUpdateTextBlocklistParameters, CreateOrUpdateTextBlocklist200Response, CreateOrUpdateTextBlocklist201Response, CreateOrUpdateTextBlocklistDefaultResponse, AddOrUpdateBlocklistItemsParameters, AddOrUpdateBlocklistItems200Response, AddOrUpdateBlocklistItemsDefaultResponse, AnalyzeTextParameters, AnalyzeText200Response, AnalyzeTextDefaultResponse, AnalyzeTextOptions, TextBlocklist, TextBlocklistItem } from "@azure-rest/ai-content-safety"; import { AzureKeyCredential } from "@azure/core-auth"; // Get endpoint and key from environment variables const key = process.env.CONTENT_SAFETY_KEY; const endpoint = process.env.CONTENT_SAFETY_ENDPOINT; if (!key || !endpoint) { throw new Error("Missing required environment variables: CONTENT_SAFETY_KEY or CONTENT_SAFETY_ENDPOINT"); } // Define your blocklist information // This creates a custom blocklist for words/phrases you want to specifically block const blocklistName = "company-prohibited-terms"; const blocklistDescription = "Custom blocklist for company-specific prohibited terms and phrases"; // Define items to block - these are specific words or phrases you want to flag // Even if Azure AI doesn't naturally flag them, these will be caught const blocklistItemText1 = "confidential project alpha"; const blocklistItemText2 = "internal revenue data"; // Define sample text for analysis that contains one of our blocked terms const inputText = "Please don't share the confidential project alpha details with external teams."; /** * Step 1: Create or update a custom blocklist container */ async function createBlocklistContainer( client: ReturnType, name: string, description: string ): Promise { const blocklistData: TextBlocklist = { blocklistName: name, description: description }; const createBlocklistParams: CreateOrUpdateTextBlocklistParameters = { body: blocklistData, contentType: "application/merge-patch+json" }; const blocklistResult: CreateOrUpdateTextBlocklist200Response | CreateOrUpdateTextBlocklist201Response | CreateOrUpdateTextBlocklistDefaultResponse = await client.path("/text/blocklists/{blocklistName}", name).patch(createBlocklistParams); if (isUnexpected(blocklistResult)) { throw blocklistResult; } console.log("✅ Blocklist created successfully!"); console.log(` Name: ${blocklistResult.body.blocklistName}`); console.log(` Description: ${blocklistResult.body.description || "No description"}\n`); } /** * Step 2: Add specific prohibited terms to the blocklist */ async function addProhibitedTerms( client: ReturnType, blocklistName: string, terms: string[] ): Promise { const blocklistItems: TextBlocklistItem[] = terms.map(text => ({ text })); const addItemsParams: AddOrUpdateBlocklistItemsParameters = { body: { blocklistItems: blocklistItems } }; const addItemsResult: AddOrUpdateBlocklistItems200Response | AddOrUpdateBlocklistItemsDefaultResponse = await client.path("/text/blocklists/{blocklistName}:addOrUpdateBlocklistItems", blocklistName).post(addItemsParams); if (isUnexpected(addItemsResult)) { throw addItemsResult; } console.log("✅ Terms added to blocklist successfully!"); for (const item of addItemsResult.body.blocklistItems) { console.log(` BlocklistItemId: ${item.blocklistItemId}`); console.log(` Text: "${item.text}"`); console.log(` Description: ${item.description || "No description"}\n`); } } /** * Step 3: Wait for blocklist changes to propagate through Azure's system */ async function waitForBlocklistActivation(seconds: number = 5): Promise { await new Promise(resolve => setTimeout(resolve, seconds * 1000)); } /** * Step 4: Analyze text against the custom blocklist */ async function analyzeTextAgainstBlocklist( client: ReturnType, textToAnalyze: string, blocklistName: string ): Promise { const analyzeTextOption: AnalyzeTextOptions = { text: textToAnalyze, blocklistNames: [blocklistName], // Use our custom blocklist haltOnBlocklistHit: false // Continue analysis even if blocklist match found }; const analyzeTextParams: AnalyzeTextParameters = { body: analyzeTextOption }; const analysisResult: AnalyzeText200Response | AnalyzeTextDefaultResponse = await client.path("/text:analyze").post(analyzeTextParams); if (isUnexpected(analysisResult)) { throw analysisResult; } return analysisResult; } ``` -------------------------------- ### Run the text analysis container Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/containers/text-container Execute the container with required billing and authentication parameters. Ensure the host machine has the NVIDIA container toolkit installed if using GPU acceleration. ```bash docker run --rm -it -p 5000:5000 --gpus all \ mcr.microsoft.com/azure-cognitive-services/contentsafety/text-analyze:latest \ Eula=accept \ Billing={ENDPOINT_URI} \ ApiKey={API_KEY} ``` -------------------------------- ### Expected console output Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-text Example output showing severity scores for content categories after successful analysis. ```text Analyze text succeeded: Hate severity: 0 SelfHarm severity: 0 Sexual severity: 0 Violence severity: 0 ``` -------------------------------- ### Initialize project directory Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Create a new directory for the application and navigate into it. ```bash mkdir myapp && cd myapp ``` -------------------------------- ### Initialize Project Directory Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Commands to create and open a new project directory. ```bash mkdir content-safety-image-analysis cd content-safety-image-analysis code . ``` -------------------------------- ### Initialize Node.js Project Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Commands to create a project directory and initialize the package.json file. ```bash mkdir myapp && cd myapp ``` ```bash npm init ``` -------------------------------- ### Build and Run the Sample Application Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-blocklist Commands to compile and execute the TypeScript-based Content Safety sample. ```bash npm run build ``` ```bash npm start ``` -------------------------------- ### Sample Application Output Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-blocklist Expected console output demonstrating successful blocklist creation, term addition, and content detection. ```text ✅ Blocklist created successfully! Name: company-prohibited-terms Description: Custom blocklist for company-specific prohibited terms and phrases ✅ Terms added to blocklist successfully! BlocklistItemId: 6fe21688-f65d-4d0b-9ff5-c6e5859ea83a Text: "internal revenue data" Description: No description BlocklistItemId: b48f958b-a58b-4d49-9e33-8ece75fc6c3b Text: "confidential project alpha" Description: No description 🚨 BLOCKED CONTENT DETECTED! The following prohibited terms were found: Blocklist: company-prohibited-terms Matched Term: "confidential project alpha" Item ID: b48f958b-a58b-4d49-9e33-8ece75fc6c3b ``` -------------------------------- ### Groundedness API Response Example Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-groundedness Example JSON response showing ungrounded content detection and the corresponding correction text. ```json { "ungroundedDetected": true, "ungroundedPercentage": 1, "ungroundedDetails": [ { "text": "The patient name is Kevin" } ], "correctionText": "The patient name is Jane" } ``` -------------------------------- ### GET /contentsafety/text/incidents Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Lists all text incidents. ```APIDOC ## GET /contentsafety/text/incidents ### Description Lists all text incidents. ### Method GET ### Endpoint https:///contentsafety/text/incidents?api-version=2024-02-15-preview ### Parameters #### Query Parameters - **api-version** (string) - Required - The version of the API to use. ``` -------------------------------- ### Build and run .NET application Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Commands to compile and execute the .NET project from the command line. ```bash dotnet build dotnet run ``` -------------------------------- ### GET /contentsafety/image/incidents Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieves a list of image incidents. ```APIDOC ## GET /contentsafety/image/incidents ### Description Retrieves the list of image incidents. ### Method GET ### Endpoint https:///contentsafety/image/incidents?api-version=2024-02-15-preview ### Parameters #### Query Parameters - **api-version** (string) - Required - The version of the API to use. ``` -------------------------------- ### Get the incidents list Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieve a list of all image incidents. ```Bash curl --location GET 'https:///contentsafety/image/incidents?api-version=2024-02-15-preview' \ --header 'Ocp-Apim-Subscription-Key: ' ``` ```Python import requests url = "https:///contentsafety/image/incidents?api-version=2024-02-15-preview" payload = {} headers = { 'Ocp-Apim-Subscription-Key': '' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### GET /contentsafety/image/incidents/{image-incident-name} Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieves the details of a specific image incident. ```APIDOC ## GET /contentsafety/image/incidents/{image-incident-name} ### Description Retrieves the details of a specific image incident. ### Method GET ### Endpoint https:///contentsafety/image/incidents/?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **image-incident-name** (string) - Required - The name of the image incident. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. ``` -------------------------------- ### Create source directory Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Create the standard Java source directory structure. ```bash mkdir -p src/main/java ``` -------------------------------- ### GET /contentsafety/text/incidents/ Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieves the details of a specific text incident. ```APIDOC ## GET /contentsafety/text/incidents/ ### Description Retrieves the details of a specific text incident. ### Method GET ### Endpoint https:///contentsafety/text/incidents/?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **text-incident-name** (string) - Required - The name of the incident to retrieve. ``` -------------------------------- ### GET /contentsafety/text/categories/operations/{id} Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories Retrieves the status of a category build operation. ```APIDOC ## GET /contentsafety/text/categories/operations/{id} ### Description Retrieves the current status of a category build operation using the operation ID. ### Method GET ### Endpoint /contentsafety/text/categories/operations/{id}?api-version=2024-09-15-preview ### Parameters #### Path Parameters - **id** (string) - Required - The operation ID returned from the build trigger. ``` -------------------------------- ### Create a new .NET console application Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Initializes a new C# console project using the .NET CLI. ```bash dotnet new console -n content-safety-quickstart ``` -------------------------------- ### Initialize Gradle project Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Generate essential build files for the Gradle project. ```bash gradle init --type basic ``` -------------------------------- ### POST /contentsafety/text/incidents/:addIncidentSamples Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Adds text examples to an existing incident. ```APIDOC ## POST /contentsafety/text/incidents/:addIncidentSamples ### Description Adds text examples to the specified incident. ### Method POST ### Endpoint https:///contentsafety/text/incidents/:addIncidentSamples?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **text-incident-name** (string) - Required - The name of the incident. #### Request Body - **IncidentSamples** (array) - Required - A list of objects containing the text samples. ``` -------------------------------- ### GET /text/blocklists/{blocklistName} Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/use-blocklist Retrieves the details of a specific text blocklist by its name. ```APIDOC ## GET /text/blocklists/{blocklistName} ### Description Retrieves the details of a specific text blocklist by its name. ### Method GET ### Endpoint /text/blocklists/{blocklistName}?api-version=2024-09-01 ### Parameters #### Path Parameters - **blocklistName** (string) - Required - The name of the blocklist to retrieve. ### Response #### Success Response (200) - **blocklistName** (string) - The name of the blocklist. - **description** (string) - The description of the blocklist. ### Response Example { "blocklistName": "string", "description": "string" } ``` -------------------------------- ### Run the Content Safety container Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/containers/image-container Execute the container with required billing and authentication parameters. Ensure GPU resources are configured if using hardware acceleration. ```bash docker run --rm -it -p 5000:5000 --gpus all \ mcr.microsoft.com/azure-cognitive-services/contentsafety/image-analyze:latest \ Eula=accept \ Billing={ENDPOINT_URI} \ ApiKey={API_KEY} ``` -------------------------------- ### Build and run the application Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Commands to compile and execute the Java application using Gradle. ```console gradle build ``` ```console gradle run ``` -------------------------------- ### GET /contentsafety/image/incidents/{image-incident-name}/incidentsamples Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Lists all samples associated with a given incident. ```APIDOC ## GET /contentsafety/image/incidents/{image-incident-name}/incidentsamples ### Description Retrieves the unique IDs of all the samples associated with a given incident object. ### Method GET ### Endpoint https:///contentsafety/image/incidents//incidentsamples?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **image-incident-name** (string) - Required - The name of the image incident. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. ``` -------------------------------- ### Create and use a blocklist in C# Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-blocklist This code initializes the client, creates a blocklist, adds items, and performs text analysis. Ensure the CONTENT_SAFETY_ENDPOINT and CONTENT_SAFETY_KEY environment variables are set before execution. ```csharp using System; using Azure.AI.ContentSafety; using Azure; using Azure.Core; class ContentSafetyBlocklist { public static void UseBlocklist() { string endpoint = Environment.GetEnvironmentVariable("CONTENT_SAFETY_ENDPOINT"); string key = Environment.GetEnvironmentVariable("CONTENT_SAFETY_KEY"); Console.WriteLine("Endpoint: "+ endpoint); Console.WriteLine("Key: "+ key); BlocklistClient blocklistClient = new BlocklistClient(new Uri(endpoint), new AzureKeyCredential(key)); var blocklistName = "ProductSaleBlocklist"; var blocklistDescription = "Contains terms related to the sale of a product."; var data = new { description = blocklistDescription, }; // create blocklist var createResponse = blocklistClient.CreateOrUpdateTextBlocklist(blocklistName, RequestContent.Create(data)); if (createResponse.Status == 201) { Console.WriteLine("\nBlocklist {0} created.", blocklistName); } // Add blocklistItems string blocklistItemText1 = "price"; string blocklistItemText2 = "offer"; var blocklistItems = new TextBlocklistItem[] { new TextBlocklistItem(blocklistItemText1), new TextBlocklistItem(blocklistItemText2) }; var addedBlocklistItems = blocklistClient.AddOrUpdateBlocklistItems(blocklistName, new AddOrUpdateTextBlocklistItemsOptions(blocklistItems)); if (addedBlocklistItems != null && addedBlocklistItems.Value != null) { Console.WriteLine("\nBlocklistItems added:"); foreach (var addedBlocklistItem in addedBlocklistItems.Value.BlocklistItems) { Console.WriteLine("BlocklistItemId: {0}, Text: {1}, Description: {2}", addedBlocklistItem.BlocklistItemId, addedBlocklistItem.Text, addedBlocklistItem.Description); } } // Analyze text ContentSafetyClient client = new ContentSafetyClient(new Uri(endpoint), new AzureKeyCredential(key)); // After you edit your blocklist, it usually takes effect in 5 minutes, please wait some time before analyzing with blocklist after editing. var request = new AnalyzeTextOptions("You can order a copy now for the low price of $19.99."); request.BlocklistNames.Add(blocklistName); request.HaltOnBlocklistHit = true; Response response; try { response = client.AnalyzeText(request); } catch (RequestFailedException ex) { Console.WriteLine("Analyze text failed.\nStatus code: {0}, Error code: {1}, Error message: {2}", ex.Status, ex.ErrorCode, ex.Message); throw; } if (response.Value.BlocklistsMatch != null) { Console.WriteLine("\nBlocklist match result:"); foreach (var matchResult in response.Value.BlocklistsMatch) { Console.WriteLine("BlocklistName: {0}, BlocklistItemId: {1}, BlocklistText: {2}, ", matchResult.BlocklistName, matchResult.BlocklistItemId, matchResult.BlocklistItemText); } } } static void Main() { UseBlocklist(); } } ``` -------------------------------- ### Get the incident details Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieve details for a specific image incident by name. ```Bash curl --location GET 'https:///contentsafety/image/incidents/?api-version=2024-02-15-preview' \ --header 'Ocp-Apim-Subscription-Key: ' ``` ```Python import requests url = "https:///contentsafety/image/incidents/?api-version=2024-02-15-preview" payload = {} headers = { 'Ocp-Apim-Subscription-Key': '' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### GET /contentsafety/text/incidents//incidentsamples Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Lists all samples associated with a specific incident. ```APIDOC ## GET /contentsafety/text/incidents//incidentsamples ### Description Retrieves the unique IDs of all the samples associated with a given incident object. ### Method GET ### Endpoint https:///contentsafety/text/incidents//incidentsamples?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **text-incident-name** (string) - Required - The name of the incident. ``` -------------------------------- ### Run the application Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Execute the script using the Node.js runtime. ```bash node index.js ``` -------------------------------- ### GET /contentsafety/image/incidents/{image-incident-name}/incidentsamples/{your-incident-sample-id} Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieves details about a specific incident sample. ```APIDOC ## GET /contentsafety/image/incidents/{image-incident-name}/incidentsamples/{your-incident-sample-id} ### Description Use an incident sample ID to look up details about the sample. ### Method GET ### Endpoint https:///contentsafety/image/incidents//incidentsamples/?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **image-incident-name** (string) - Required - The name of the image incident. - **your-incident-sample-id** (string) - Required - The ID of the incident sample. #### Query Parameters - **api-version** (string) - Required - The version of the API to use. ``` -------------------------------- ### Build the .NET application Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Compiles the project to ensure all dependencies are resolved and the code is valid. ```bash dotnet build ``` -------------------------------- ### GET /contentsafety/text/incidents//incidentsamples/ Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieves details for a specific incident sample. ```APIDOC ## GET /contentsafety/text/incidents//incidentsamples/ ### Description Use an incident sample ID to look up details about the sample. ### Method GET ### Endpoint https:///contentsafety/text/incidents//incidentsamples/?api-version=2024-02-15-preview ### Parameters #### Path Parameters - **text-incident-name** (string) - Required - The name of the incident. - **your-incident-sample-id** (string) - Required - The ID of the sample. ``` -------------------------------- ### Configure build.gradle.kts Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image Define the application entry point and add the Azure AI Content Safety dependency. ```kotlin plugins { java application } application { mainClass.set("ContentSafetyQuickstart") } repositories { mavenCentral() } dependencies { implementation(group = "com.azure", name = "azure-ai-contentsafety", version = "1.0.0") } ``` -------------------------------- ### Get text incident details Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieve details for a specific text incident by its name. ```bash curl --location GET 'https:///contentsafety/text/incidents/?api-version=2024-02-15-preview' \ --header 'Ocp-Apim-Subscription-Key: ' ``` ```python import requests url = "https:///contentsafety/text/incidents/?api-version=2024-02-15-preview" payload = {} headers = { 'Ocp-Apim-Subscription-Key': '' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Add samples to the incident Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Add text examples to an existing incident to train or define the category. ```bash curl --location 'https:///contentsafety/text/incidents/:addIncidentSamples?api-version=2024-02-15-preview' \ --header 'Ocp-Apim-Subscription-Key: ' \ --header 'Content-Type: application/json' \ --data-raw '{ "IncidentSamples": [ { "text": ""}, { "text": ""}, ... ] }' ``` ```python import requests import json url = "https:///contentsafety/text/incidents/:addIncidentSamples?api-version=2024-02-15-preview" payload = json.dumps({ "IncidentSamples": [ { "text": "" }, { "text": "" }, ... ] }) headers = { 'Ocp-Apim-Subscription-Key': '', 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Run the container with a blocklist Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/containers/text-container Mount a local directory containing CSV blocklist files to the container to enable custom term filtering. ```bash docker run -e BLOCKLIST_DIR=/tmp/blocklist -v {/path/on/host}:/tmp/blocklist ``` -------------------------------- ### Get incident sample details Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories-rapid Retrieve details for a specific incident sample using its ID. ```bash curl --location GET 'https:///contentsafety/text/incidents//incidentsamples/?api-version=2024-02-15-preview' \ --header 'Ocp-Apim-Subscription-Key: ' ``` ```python import requests url = "https:///contentsafety/text/incidents//incidentsamples/?api-version=2024-02-15-preview" payload = {} headers = { 'Ocp-Apim-Subscription-Key': '' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text) ``` -------------------------------- ### Get a customized category in Python Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories Retrieves category information using the Python requests library. ```python def get_customized_category(category_name, version=None): url = f"{ENDPOINT}/contentsafety/text/categories/{category_name}?api-version=2024-09-15-preview" if version: url += f"&version={version}" response = requests.get(url, headers=headers) return response.json() # Replace the parameters with your own values category_name = "DrugAbuse" version = 1 result = get_customized_category(category_name, version) print(result) ``` -------------------------------- ### GET /contentsafety/text/categories/operations/ Source: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/how-to/custom-categories Retrieves the status of a category build operation using its unique ID. ```APIDOC ## GET /contentsafety/text/categories/operations/ ### Description Checks the status of a previously initiated build operation. ### Method GET ### Endpoint /contentsafety/text/categories/operations/?api-version=2024-09-15-preview ### Parameters #### Path Parameters - **id** (string) - Required - The operation ID obtained from the build request. #### Query Parameters - **api-version** (string) - Required - The API version. ### Response #### Success Response (200) - **operation id** (string) - Unique identifier for the build operation. - **status** (string) - Current status of the request. ```