Skip to content

Commit 6546405

Browse files
Merge pull request #269525 from mrbullwinkle/mrb_03_19_2024_content_filter
[Azure OpenAI] update
2 parents 8c15b5d + 01faf46 commit 6546405

File tree

1 file changed

+99
-12
lines changed

1 file changed

+99
-12
lines changed

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

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ import os
325325
from openai import AzureOpenAI
326326
client = AzureOpenAI(
327327
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
328-
api_version="2023-10-01-preview",
328+
api_version="2024-03-01-preview",
329329
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
330330
)
331331

@@ -339,6 +339,93 @@ response = client.completions.create(
339339
print(response.model_dump_json(indent=2))
340340
```
341341

342+
### Output
343+
344+
```json
345+
{
346+
"choices": [
347+
{
348+
"content_filter_results": {
349+
"hate": {
350+
"filtered": false,
351+
"severity": "safe"
352+
},
353+
"protected_material_code": {
354+
"citation": {
355+
"URL": " https://github.com/username/repository-name/path/to/file-example.txt",
356+
"license": "EXAMPLE-LICENSE"
357+
},
358+
"detected": true,
359+
"filtered": false
360+
},
361+
"protected_material_text": {
362+
"detected": false,
363+
"filtered": false
364+
},
365+
"self_harm": {
366+
"filtered": false,
367+
"severity": "safe"
368+
},
369+
"sexual": {
370+
"filtered": false,
371+
"severity": "safe"
372+
},
373+
"violence": {
374+
"filtered": false,
375+
"severity": "safe"
376+
}
377+
},
378+
"finish_reason": "stop",
379+
"index": 0,
380+
"message": {
381+
"content": "Example model response will be returned ",
382+
"role": "assistant"
383+
}
384+
}
385+
],
386+
"created": 1699386280,
387+
"id": "chatcmpl-8IMI4HzcmcK6I77vpOJCPt0Vcf8zJ",
388+
"model": "gpt-35-turbo-instruct",
389+
"object": "text.completion",
390+
"usage": {
391+
"completion_tokens": 40,
392+
"prompt_tokens": 11,
393+
"total_tokens": 417
394+
},
395+
"prompt_filter_results": [
396+
{
397+
"content_filter_results": {
398+
"hate": {
399+
"filtered": false,
400+
"severity": "safe"
401+
},
402+
"jailbreak": {
403+
"detected": false,
404+
"filtered": false
405+
},
406+
"profanity": {
407+
"detected": false,
408+
"filtered": false
409+
},
410+
"self_harm": {
411+
"filtered": false,
412+
"severity": "safe"
413+
},
414+
"sexual": {
415+
"filtered": false,
416+
"severity": "safe"
417+
},
418+
"violence": {
419+
"filtered": false,
420+
"severity": "safe"
421+
}
422+
},
423+
"prompt_index": 0
424+
}
425+
]
426+
}
427+
```
428+
342429
# [OpenAI Python 0.28.1](#tab/python)
343430

344431
```python
@@ -348,11 +435,11 @@ import os
348435
import openai
349436
openai.api_type = "azure"
350437
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
351-
openai.api_version = "2023-06-01-preview" # API version required to use Annotations
438+
openai.api_version = "2024-03-01-preview" # API version required to use Annotations
352439
openai.api_key = os.getenv("AZURE_OPENAI_API_KEY")
353440

354441
response = openai.Completion.create(
355-
engine="gpt-35-turbo", # engine = "deployment_name".
442+
engine="gpt-35-turbo-instruct", # engine = "deployment_name".
356443
messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Example prompt that leads to a protected code completion that was detected, but not filtered"}] # Content that is detected at severity level medium or high is filtered,
357444
# while content detected at severity level low isn't filtered by the content filters.
358445
)
@@ -407,8 +494,13 @@ print(response)
407494
],
408495
"created": 1699386280,
409496
"id": "chatcmpl-8IMI4HzcmcK6I77vpOJCPt0Vcf8zJ",
410-
"model": "gpt-35-turbo",
411-
"object": "chat.completion",
497+
"model": "gpt-35-turbo-instruct",
498+
"object": "text.completion",
499+
"usage": {
500+
"completion_tokens": 40,
501+
"prompt_tokens": 11,
502+
"total_tokens": 417
503+
},
412504
"prompt_filter_results": [
413505
{
414506
"content_filter_results": {
@@ -439,12 +531,7 @@ print(response)
439531
},
440532
"prompt_index": 0
441533
}
442-
],
443-
"usage": {
444-
"completion_tokens": 40,
445-
"prompt_tokens": 11,
446-
"total_tokens": 417
447-
}
534+
]
448535
}
449536
```
450537

@@ -457,7 +544,7 @@ import os
457544
import openai
458545
openai.api_type = "azure"
459546
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
460-
openai.api_version = "2023-06-01-preview" # API version required to use Annotations
547+
openai.api_version = "2024-03-01-preview" # API version required to use Annotations
461548
openai.api_key = os.getenv("AZURE_OPENAI_API_KEY")
462549

463550
try:

0 commit comments

Comments
 (0)