You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/content-safety/how-to/use-blocklist.md
+263-7Lines changed: 263 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,16 +27,20 @@ The default AI classifiers are sufficient for most content moderation needs. How
27
27
* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services/)
28
28
* Once you have your Azure subscription, <ahref="https://aka.ms/acs-create"title="Create a Content Safety resource"target="_blank">create a Content Safety resource </a> in the Azure portal to get your key and endpoint. Enter a unique name for your resource, select the subscription you entered on the application form, select a resource group, supported region, and supported pricing tier. Then select **Create**.
29
29
* The resource takes a few minutes to deploy. After it finishes, Select **go to resource**. In the left pane, under **Resource Management**, select **Subscription Key and Endpoint**. The endpoint and either of the keys are used to call APIs.
30
-
*[cURL](https://curl.haxx.se/) or * [Python 3.x](https://www.python.org/) installed
31
-
* Your Python installation should include [pip](https://pip.pypa.io/en/stable/). You can check if you have pip installed by running `pip --version` on the command line. Get pip by installing the latest version of Python.
32
-
* If you're using the Python SDK, you'll need to install the Azure AI Content Safety client library for Python. Run the command `pip install azure-ai-contentsafety` in your project directory.
30
+
* One of the following installed:
31
+
*[cURL](https://curl.haxx.se/) for REST API calls.
32
+
*[Python 3.x](https://www.python.org/) installed
33
+
* Your Python installation should include [pip](https://pip.pypa.io/en/stable/). You can check if you have pip installed by running `pip --version` on the command line. Get pip by installing the latest version of Python.
34
+
* If you're using Python, you'll need to install the Azure AI Content Safety client library for Python. Run the command `pip install azure-ai-contentsafety` in your project directory.
*[.NET 6.0](https://dotnet.microsoft.com/download/dotnet-core) SDK or above installed.
37
+
* If you're using .NET, you'll need to install the Azure AI Content Safety client library for .NET. Run the command `dotnet add package Azure.AI.ContentSafety --prerelease` in your project directory.
38
+
33
39
34
40
## Analyze text with a blocklist
35
41
36
42
You can create blocklists to use with the Text API. The following steps help you get started.
1. Replace `<your_list_id>` with a custom name for your list. Also replace the last term of the REST URL with the same name. Allowed characters: 0-9, A-Z, a-z, `- . _ ~`.
98
+
1. Optionally replace `<description>` with a custom description.
99
+
1. Run the script.
100
+
63
101
#### [Python](#tab/python)
64
102
65
103
Create a new Python script and open it in your preferred editor or IDE. Paste in the following code.
@@ -160,6 +198,40 @@ The response code should be `200`.
160
198
}
161
199
```
162
200
201
+
#### [C#](#tab/csharp)
202
+
203
+
Create a new C# console app and open it in your preferred editor or IDE. Paste in the following code.
1. Replace `<your_list_id>` with the ID value you used in the list creation step.
231
+
1. Replace the value of the `block_item_text_1` field with the item you'd like to add to your blocklist. The maximum length of a blockItem is 128 characters.
232
+
1. Optionally add more blockItem strings to the `blockItems` parameter.
233
+
1. Run the script.
234
+
163
235
#### [Python](#tab/python)
164
236
165
237
Create a new Python script and open it in your preferred editor or IDE. Paste in the following code.
@@ -172,7 +244,6 @@ from azure.ai.contentsafety.models import TextBlockItemInfo, AddBlockItemsOption
172
244
from azure.core.exceptions import HttpResponseError
173
245
import time
174
246
175
-
176
247
endpoint ="<endpoint>"
177
248
key ="<enter_your_key_here>"
178
249
@@ -268,6 +339,50 @@ The JSON response will contain a `"blocklistMatchResults"` that indicates any ma
268
339
}
269
340
```
270
341
342
+
#### [C#](#tab/csharp)
343
+
344
+
Create a new C# console app and open it in your preferred editor or IDE. Paste in the following code.
0 commit comments