事件
使用自訂類別 (快速) API (預覽)
自訂類別 (快速) API 可讓您快速回應新興有害內容事件。 您可以使用特定主題中的幾個範例來定義事件,而服務會開始偵測類似的內容。
請遵循下列步驟,以一些文字內容範例來定義事件,然後分析新的文字內容,以查看它是否符合事件。
重要
這項新功能僅適用於選取的 Azure 區域。 請參閱區域可用性 (英文)。
警告
本指南中的範例資料可能包含冒犯性內容。 建議使用者斟酌使用。
- Azure 訂用帳戶 - 建立免費帳戶
- 擁有 Azure 訂用帳戶之後,在 Azure 入口網站中建立 Content Safety 資源,以取得您的金鑰和端點。 輸入您資源的唯一名稱,選取您的訂用帳戶,然後選取資源群組、支援的區域 (參閱區域可用性) 以及支援的定價層。 然後選取建立。
- 部署資源需要幾分鐘的時間。 完成後,選取 [移至資源]。 在左側窗格中,於 [資源管理] 下選取 [訂用帳戶金鑰和端點]。 端點和其中一個金鑰是用以呼叫 API。
- 如果您想要上傳影像,也建立 Blob 記憶體容器。 或者,您可以將影像編碼為 Base64 字串,並直接在 API 呼叫中使用它們。
- 已安裝下列其中一項:
- 適用於 REST API 呼叫的 cURL。
- 已安裝 Python 3.8.x
使用本節中的範例程式代碼來建立文字事件、將範例新增至事件、部署事件,然後偵測文字事件。
在下列命令中,以您自己的值取代 <your_api_key>
、<your_endpoint>
和其他必要參數。
下列命令會建立具有名稱和定義的事件。
curl --location --request PATCH 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{ \"incidentName\": \"<test-incident>\", \"incidentDefinition\": \"<string>\"}'
使用下列命令,將文字範例新增至事件。
curl --location 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>:addIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
\"IncidentSamples\": [
{ \"text\": \"<text-example-1>\"},
{ \"text\": \"<text-example-2>\"},
...
]
}'
使用下列命令來部署事件,使其可供分析新內容。
curl --location 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>:deploy?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json'
執行下列命令來分析您剛部署的事件所出現的範例文字內容。
curl --location 'https://<endpoint>/contentsafety/text:detectIncidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"text\": \"<test-text>\",
\"incidentNames\": [
\"<text-incident-name>\"
]
}'
使用本節中的範例程式代碼來建立影像事件、將範例新增至事件、部署事件,然後偵測影像事件。
在下列命令中,以您自己的值取代 <your_api_key>
、<your_endpoint>
和其他必要參數。
下列命令會在建立影像事件:
curl --location --request PATCH 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"incidentName\": \"<image-incident-name>\"
}'
使用下列命令,將範例影像新增至您的事件。 映像範例可以是指向 AzureBlob 記憶體容器中影像的 URL,也可以是 Base64 字串。
curl --location 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>:addIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"IncidentSamples\": [
{
\"image\": {
\"content\": \"<base64-data>\",
\"bloburl\": \"<your-blob-storage-url>.png\"
}
}
]
}'
使用下列命令來部署事件,使其可供分析新內容。
curl --location 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>:deploy?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json'
使用下列命令來上傳範例影像,並針對您所部署的事件進行測試。 您可以使用指向 AzureBlob 記憶體容器中映像的 URL,或將映像資料新增為 Base64 字串。
curl --location 'https://<endpoint>/contentsafety/image:detectIncidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"image\": {
\"url\": \"<your-blob-storage-url>/image.png\",
"content": "<base64-data>"
},
\"incidentNames\": [
\"<image-incident-name>\"
]
}
}'
下列作業適用於管理事件和事件範例。
curl --location GET 'https://<endpoint>/contentsafety/text/incidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location GET 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location --request DELETE 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
此命令會擷取與指定事件對象相關聯的全部範例所用的唯一識別碼。
curl --location GET 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>/incidentsamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
使用事件範例識別碼來查閱範例的詳細資料。
curl --location GET 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>/incidentsamples/<your-incident-sample-id>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
使用事件範例識別碼來擷取和刪除該範例。
curl --location 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>:removeIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"IncidentSampleIds\": [
\"<your-incident-sample-id>\"
]
}'
curl --location GET 'https://<endpoint>/contentsafety/image/incidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location GET 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location --request DELETE 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
此命令會擷取與指定事件對象相關聯的全部範例所用的唯一識別碼。
curl --location GET 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>/incidentsamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
使用事件範例識別碼來查閱範例的詳細資料。
curl --location GET 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>/incidentsamples/<your-incident-sample-id>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
使用事件範例識別碼來擷取和刪除該範例。
curl --location 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>:removeIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"IncidentSampleIds\": [
\"<your-incident-sample-id>\"
]
}'
其他資源
訓練
模組
搭配 Azure AI 內容安全負責任地使用 AI - Training
隨著使用者產生的線上內容數量增加,因此需要確保有害材料受到有效仲裁。 Azure AI 內容安全資源包含的功能,可協助組織仲裁及管理使用者產生和 AI 產生的內容。
認證
Microsoft Certified: Security Operations Analyst Associate - Certifications
使用 Microsoft Sentinel、適用於雲端的 Microsoft Defender 和 Microsoft 365 Defender 調查、搜尋及降低威脅。
文件
-
快速入門:自訂類別 (預覽) - Azure AI services
使用自訂類別 API 建立您自己的有害內容類別,並針對您的使用案例定型內容安全模型。
-
Azure AI 內容安全中的自訂類別 (預覽) - Azure AI services
瞭解自訂內容類別,以及您可以使用 Azure AI 內容安全在平台上處理它們的不同方式。
-
降低 Azure AI 內容安全中的錯誤結果風險 - Azure AI services
了解透過處理誤判 (false positive) 和漏報 (false negative) 來提高 Azure AI 內容安全模型效能的技術。