@@ -325,7 +325,7 @@ import os
325
325
from openai import AzureOpenAI
326
326
client = AzureOpenAI(
327
327
api_key = os.getenv(" AZURE_OPENAI_API_KEY" ),
328
- api_version = " 2023-10 -01-preview" ,
328
+ api_version = " 2024-03 -01-preview" ,
329
329
azure_endpoint = os.getenv(" AZURE_OPENAI_ENDPOINT" )
330
330
)
331
331
@@ -339,6 +339,93 @@ response = client.completions.create(
339
339
print (response.model_dump_json(indent = 2 ))
340
340
```
341
341
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
+
342
429
# [ OpenAI Python 0.28.1] ( #tab/python )
343
430
344
431
``` python
@@ -348,11 +435,11 @@ import os
348
435
import openai
349
436
openai.api_type = " azure"
350
437
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
352
439
openai.api_key = os.getenv(" AZURE_OPENAI_API_KEY" )
353
440
354
441
response = openai.Completion.create(
355
- engine = " gpt-35-turbo" , # engine = "deployment_name".
442
+ engine = " gpt-35-turbo-instruct " , # engine = "deployment_name".
356
443
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,
357
444
# while content detected at severity level low isn't filtered by the content filters.
358
445
)
@@ -407,8 +494,13 @@ print(response)
407
494
],
408
495
"created" : 1699386280 ,
409
496
"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
+ },
412
504
"prompt_filter_results" : [
413
505
{
414
506
"content_filter_results" : {
@@ -439,12 +531,7 @@ print(response)
439
531
},
440
532
"prompt_index" : 0
441
533
}
442
- ],
443
- "usage" : {
444
- "completion_tokens" : 40 ,
445
- "prompt_tokens" : 11 ,
446
- "total_tokens" : 417
447
- }
534
+ ]
448
535
}
449
536
```
450
537
@@ -457,7 +544,7 @@ import os
457
544
import openai
458
545
openai.api_type = " azure"
459
546
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
461
548
openai.api_key = os.getenv(" AZURE_OPENAI_API_KEY" )
462
549
463
550
try :
0 commit comments