Skip to content

Commit 7b1cf2b

Browse files
Merge pull request #259803 from mgreenegit/powershell-contentfiltering-0
content filter - powershell example request and output
2 parents ae0980c + e9582b1 commit 7b1cf2b

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

articles/ai-services/openai/concepts/content-filter.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ Annotations are currently in preview for Completions and Chat Completions (GPT m
363363

364364
# [OpenAI Python 0.28.1](#tab/python)
365365

366-
367366
```python
368367
# os.getenv() for the endpoint and key assumes that you are using environment variables.
369368

@@ -591,6 +590,49 @@ main().catch((err) => {
591590
console.error("The sample encountered an error:", err);
592591
});
593592
```
593+
594+
# [PowerShell](#tab/powershell)
595+
596+
```powershell-interactive
597+
# Env: for the endpoint and key assumes that you are using environment variables.
598+
$openai = @{
599+
api_key = $Env:AZURE_OPENAI_KEY
600+
api_base = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
601+
api_version = '2023-10-01-preview' # this may change in the future
602+
name = 'YOUR-DEPLOYMENT-NAME-HERE' #This will correspond to the custom name you chose for your deployment when you deployed a model.
603+
}
604+
605+
$prompt = 'Example prompt where a severity level of low is detected'
606+
# Content that is detected at severity level medium or high is filtered,
607+
# while content detected at severity level low isn't filtered by the content filters.
608+
609+
$headers = [ordered]@{
610+
'api-key' = $openai.api_key
611+
}
612+
613+
$body = [ordered]@{
614+
prompt = $prompt
615+
model = $openai.name
616+
} | ConvertTo-Json
617+
618+
# Send a completion call to generate an answer
619+
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/completions?api-version=$($openai.api_version)"
620+
621+
$response = Invoke-RestMethod -Uri $url -Headers $headers -Body $body -Method Post -ContentType 'application/json'
622+
return $response.prompt_filter_results.content_filter_results | format-list
623+
```
624+
625+
The `$response` object contains a property named `prompt_filter_results` that contains annotations
626+
about the filter results. If you prefer JSON to a .NET object, pipe the output to `ConvertTo-JSON`
627+
instead of `Format-List`.
628+
629+
```output
630+
hate : @{filtered=False; severity=safe}
631+
self_harm : @{filtered=False; severity=safe}
632+
sexual : @{filtered=False; severity=safe}
633+
violence : @{filtered=False; severity=safe}
634+
```
635+
594636
---
595637
596638
For details on the inference REST API endpoints for Azure OpenAI and how to create Chat and Completions please follow [Azure OpenAI Service REST API reference guidance](../reference.md). Annotations are returned for all scenarios when using `2023-06-01-preview`.
@@ -648,5 +690,3 @@ As part of your application design, consider the following best practices to del
648690
- Azure OpenAI content filtering is powered by [Azure AI Content Safety](https://azure.microsoft.com/products/cognitive-services/ai-content-safety).
649691
- Learn more about understanding and mitigating risks associated with your application: [Overview of Responsible AI practices for Azure OpenAI models](/legal/cognitive-services/openai/overview?context=/azure/ai-services/openai/context/context).
650692
- Learn more about how data is processed in connection with content filtering and abuse monitoring: [Data, privacy, and security for Azure OpenAI Service](/legal/cognitive-services/openai/data-privacy?context=/azure/ai-services/openai/context/context#preventing-abuse-and-harmful-content-generation).
651-
652-

0 commit comments

Comments
 (0)