b. Search for role ‘Cognitive Services User', click, and select ‘Next'.
c. Choose ‘Managed Identity' for ‘assign access to' option, and choose the Azure Content Safety resource that you've created in ‘Members'.
d. Finally select ‘Review + assign'. After it is completed, your Azure Content Safety resource has been assigned permission to use your Azure OpenAI resource for review task.
Get your Azure OpenAI resource endpoint
Go to your Azure OpenAI resource and open ‘Keys and endpoint' to copy the endpoint.
Get your GPT-4 deployment name
Go to your Azure OpenAI resource and open ‘Model deployments'. Select ‘Manage Deployments', and get the deployment name of GPT-4 that you'd like to use for review task.
Modify content filtering setting to enable ‘annotation' mode
The Auto Reviewer API needs to leverage the extended language understanding capability of GPT-4 for content annotation task, which may contain harmful content. To complete the task and not get the input/output filtered, the content filtering configuration in your GPT-4 deployment needs to be updated to ‘annotation' mode. You may need to apply for modifying content filtering by filling this form. After the application is approved, you can update the content filtering configuration in your GPT-4 deployment to ‘annotation' mode by unchecking the boxes at each harmful category.
[Note] After completing the above steps, please send the following information to contentsafetysupport@microsoft.com:
The Auto Reviewer API needs to create a copy of your example blob file as snapshot first, then fetch your example blob for later review stage. For this, go to Access Control in your Azure Storage Account, select +Add Role Assignment and Assign the role of Storage Blob Data Contributor/Owner to the Azure Content Safety resource.
Now that you have a resource available in Azure for Content Safety and you have a subscription key for that resource, let's run some tests by using the Auto Reviewer API!
The initial step is to convert your customized community guideline/content policy to one or multiple auto reviewers in Azure AI Content Safety. Then get it ready to be used for the following review task.
There's the version of the auto reviewer to be responded in the response body. Use it to get auto reviewer status, perform review task or delete. The create API is an async API, "operation-id" and "operation-location" will be returned in the response header, use them to get the operation status in the next step.
Name | Description | Type |
---|---|---|
AutoReviewerName | (Required) Auto reviewer name, valid character set is "0-9A-Za-z._~-" | String |
Labels | (Required) An array to define the labels within each auto reviewer as the minimum review unit. The max label count is 10, min label count is 2. Within each label, you need to specify a name(string) and a description(string) to better describe the scope of the label. When performing review, if your input does not belong to any defined labels, we will output a predefined label with name="Others". | List |
ExampleBlobUrl | (Optional) The file should be ".jsonl" format, where each line is an example in json format, the maximum file size is 1MB in priviate preview. | String |
BlobDelimiter | (Optional) Delimiter of blob url. If not provided, ‘/' will be used as the delimiter to parse the exampleBlobUrl. | String |
Request payload reference
{
"AutoReviewerName": "ReviewerName1",//required, Auto reviewer name, valid character set is "0-9A-Za-z._~-". The maximum length is 64 Unicode characters.
"Labels": [//required, the max label count is 10, min label count is 2.
{
"labelname": "name_0" //required, label name
"description": "string" //required, to enumerate the detailed definitions of the label here.
},
{
"labelname": "name_1" //required, label name
"description": "string" //required, to enumerate the detailed definitions of the label here.
},
],
"exampleBlobUrl": "string",//optional, the file should be ".jsonl" format, where each line is an example in json format, the maximum file size is 1MB in gated preview.
"blobDelimiter": "string" //optional
}
Format requirement for examples
The examples that are provided for each label in the Blob URL need to follow below format requirements:
{
"text": "The text of the example 1", //required,
"LabelName": "The name of the label", //required, the label that the example describes,
"reasoning": "The reason for the review result" //optional
}
{
"text": "The text of the example 2", //required,
"LabelName": "The name of the label", //required, the label that the example describes,
"reasoning": "The reason for the review result" //optional
}
Sample Code
curl --location --request PUT '<endpoint>/contentsafety/text/autoReviewers/AnimalAbuse?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <api_key>' \
--header 'Content-Type: application/json' \
--data '{
"autoReviewerName": "AnimalAbuse",
"labels": [
{
"labelName": "Other",
"description": "all cases that do not fall into sub-category 1"
},
{
"labelName": "AnimalAbuse",
"description": "Animal abuse, or animal cruelty is the crime of inflicting physical pain, suffering or death on an animal, usually a tame one, beyond necessity for normal discipline. It can include neglect that is so monstrous (withholding food and water) that the animal has suffered, died or been put in imminent danger of death."
}
],
"exampleBlobUrl": "",
"blobDelimiter": ""
}'
import requests
import json
endpoint = "<endpoint>"
url = endpoint+"/contentsafety/text/autoReviewers/AnimalAbuse?api-version=2024-02-15-preview"
headers = {
"Ocp-Apim-Subscription-Key": '<api_key>',
"Content-Type": "application/json"
}
payload = json.dumps({
"autoReviewerName": "AnimalAbuse",
"labels": [
{
"labelName": "Other",
"description": "all cases that do not fall into sub-category 1"
},
{
"labelName": "AnimalAbuse",
"description": "Animal abuse, or animal cruelty is the crime of inflicting physical pain, suffering or death on an animal, usually a tame one, beyond necessity for normal discipline. It can include neglect that is so monstrous (withholding food and water) that the animal has suffered, died or been put in imminent danger of death."
}
],
"exampleBlobUrl": "",
"blobDelimiter": ""
})
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
Sample Code
-Curl
curl --location '<endpoint>/contentsafety/text/autoReviewers/operations/<operation-id>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <api_key>'
-Python
import requests
import json
endpoint = "<endpoint>"
url = endpoint+"/contentsafety/text/autoReviewers/operations/<operation-id>?api-version=2024-02-15-preview"
headers = {
"Ocp-Apim-Subscription-Key": '<api_key>',
"Content-Type": "application/json"
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
After the auto reviewer is created successfully, you can provide the labeled text to be further reviewed by the newly created auto reviewer. The input is very simple of ‘text', ‘autoReviewerName' and "autoReviewerVersion".
Name | Description | Type |
---|---|---|
AutoReviewerName | (Required) Name of the newly created auto reviewer. | String |
Text | (Required) String of the text to be reviewed. The maximum length is 1000 Unicode characters. | String |
AutoReviewerVersion | The version of the auto reviewer. If not assigned we will use the latest version. | String |
AoaiEndpoint | The Azure OpenAI endpoint used for review task | String |
AoaiDeployment | The deployment name of GPT-4 that you'd like to use for review task | String |
Request payload reference
{
"text": "string",
"autoReviewerName": "string",
"autoReviewerVersion": 0,
"aoaiEndpoint": "<aoai_endpoint>",
"aoaiDeployment": "<aoai_deployment_name>"
}
Sample Code
curl --location '<endpoint>/contentsafety/text:autoReview?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <api_key>' \
--header 'Content-Type: application/json' \
--data '{
"text": "I want to kill a cat",
"autoReviewerName": "AnimalAbuse",
"autoReviewerVersion": 1,
"aoaiEndpoint": "<aoai_endpoint>",
"aoaiDeployment": "<aoai_deployment_name>"
}'
import requests
import json
endpoint = "<endpoint>"
url = endpoint+"/contentsafety/text:autoReview?api-version=2024-02-15-preview"
headers = {
"Ocp-Apim-Subscription-Key": '<api_key>',
"Content-Type": "application/json"
}
payload = json.dumps({
"text": "I want to kill a cat",
"autoReviewerName": "AnimalAbuse",
"autoReviewerVersion": 1,
"aoaiEndpoint": "<aoai_endpoint>",
"aoaiDeployment": "<aoai_deployment_name>"
})
response = requests.request("POST", url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
Sample Code
-Curl
curl --location '<endpoint>/contentsafety/text/autoReviewers/AnimalAbuse?api-version=2024-02-15-preview&version=1' \
--header 'Ocp-Apim-Subscription-Key: <api_key>'
-Python
import requests
import json
endpoint = "<endpoint>"
url = endpoint+"/contentsafety/text/autoReviewers/AnimalAbuse?api-version=2024-02-15-preview&version=1"
headers = {
"Ocp-Apim-Subscription-Key": '<api_key>',
"Content-Type": "application/json"
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
Sample Code
-Curl
curl --location '<endpoint>/contentsafety/text/autoReviewers?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <api_key>'
-Python
import requests
import json
endpoint = "<endpoint>"
url = endpoint+"/contentsafety/text/autoReviewers?api-version=2024-02-15-preview"
headers = {
"Ocp-Apim-Subscription-Key": '<api_key>',
"Content-Type": "application/json"
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
Sample Code
-Curl
curl --location --request DELETE '<endpoint>/contentsafety/text/autoReviewers/AnimalAbuse?api-version=2024-02-15-preview&version=2' \
--header 'Ocp-Apim-Subscription-Key: <api_key>'
-Python
import requests
import json
endpoint = "<endpoint>"
url = endpoint+"/contentsafety/text/autoReviewers/AnimalAbuse?api-version=2024-02-15-preview&version=1"
headers = {
"Ocp-Apim-Subscription-Key": '<api_key>',
"Content-Type": "application/json"
}
response = requests.request("DELETE", url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
If you get stuck, shoot us an email or use the feedback widget on the upper right of any page.
We're excited you're here!