You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -19,13 +19,13 @@ Azure OpenAI Service is powered by a diverse set of models with different capabi
19
19
20
20
| Models | Description |
21
21
|--|--|
22
-
|[GPT-4](#gpt-4)| A set of models that improve on GPT-3.5 and can understand and generate natural language and code. |
22
+
|[GPT-4](#gpt-4-and-gpt-4-turbo-preview)| A set of models that improve on GPT-3.5 and can understand and generate natural language and code. |
23
23
|[GPT-3.5](#gpt-35)| A set of models that improve on GPT-3 and can understand and generate natural language and code. |
24
24
|[Embeddings](#embeddings-models)| A set of models that can convert text into numerical vector form to facilitate text similarity. |
25
25
|[DALL-E](#dall-e-models-preview) (Preview) | A series of models in preview that can generate original images from natural language. |
26
26
|[Whisper](#whisper-models-preview) (Preview) | A series of models in preview that can transcribe and translate speech to text. |
27
27
28
-
## GPT-4
28
+
## GPT-4 and GPT-4 Turbo Preview
29
29
30
30
GPT-4 can solve difficult problems with greater accuracy than any of OpenAI's previous models. Like GPT-3.5 Turbo, GPT-4 is optimized for chat and works well for traditional completions tasks. Use the Chat Completions API to use GPT-4. To learn more about how to interact with GPT-4 and the Chat Completions API check out our [in-depth how-to](../how-to/chatgpt.md).
31
31
@@ -72,7 +72,7 @@ You can also use the Whisper model via Azure AI Speech [batch transcription](../
72
72
>
73
73
> - South Central US is temporarily unavailable for creating new resources and deployments.
74
74
75
-
### GPT-4 models
75
+
### GPT-4 and GPT-4 Turbo Preview models
76
76
77
77
GPT-4 and GPT-4-32k models are now available to all Azure OpenAI Service customers. Availability varies by region. If you don't see GPT-4 in your region, please check back later.
78
78
@@ -86,20 +86,23 @@ See [model versions](../concepts/model-versions.md) to learn about how Azure Ope
86
86
> Version `0314` of `gpt-4` and `gpt-4-32k` will be retired no earlier than July 5, 2024. See [model updates](../how-to/working-with-models.md#model-updates) for model upgrade behavior.
87
87
88
88
| Model ID | Max Request (tokens) | Training Data (up to) |
**<sup>1</sup>** We don't recommend using this model in production. We will upgrade all deployments of this model to a future stable version. Models designated preview do not follow the standard Azure OpenAI model lifecycle.
94
97
95
98
> [!NOTE]
96
-
> Regions where GPT-4 is listed as available have access to both the 8K and 32K versions of the model
99
+
> Regions where GPT-4 (0314) & (0613) are listed as available have access to both the 8K and 32K versions of the model
97
100
98
-
### GPT-4 model availability
101
+
### GPT-4 and GPT-4 Turbo Preview model availability
99
102
100
-
| Model Availability | gpt-4 (0314) | gpt-4 (0613) |
101
-
|---|:---|:---|
102
-
| Available to all subscriptions with Azure OpenAI access || Australia East <br> Canada East <br> France Central <br> Sweden Central <br> Switzerland North |
| Available to all subscriptions with Azure OpenAI access || Australia East <br> Canada East <br> France Central <br> Sweden Central <br> Switzerland North | Australia East <br> Canada East <br> East US 2 <br> France Central <br> Sweden Central <br> UK South |
103
106
| Available to subscriptions with current access to the model version in the region | East US <br> France Central <br> South Central US <br> UK South | East US <br> East US 2 <br> Japan East <br> UK South |
104
107
105
108
### GPT-3.5 models
@@ -117,12 +120,13 @@ See [model versions](../concepts/model-versions.md) to learn about how Azure Ope
117
120
118
121
| Model ID | Model Availability | Max Request (tokens) | Training Data (up to) |
|`gpt-35-turbo`<sup>1</sup> (0301) | East US <br> France Central <br> South Central US <br> UK South <br> West Europe | 4096 | Sep 2021 |
123
+
|`gpt-35-turbo`**<sup>1</sup>** (0301) | East US <br> France Central <br> South Central US <br> UK South <br> West Europe | 4096 | Sep 2021 |
121
124
|`gpt-35-turbo` (0613) | Australia East <br> Canada East <br> East US <br> East US 2 <br> France Central <br> Japan East <br> North Central US <br> Sweden Central <br> Switzerland North <br> UK South | 4096 | Sep 2021 |
122
125
|`gpt-35-turbo-16k` (0613) | Australia East <br> Canada East <br> East US <br> East US 2 <br> France Central <br> Japan East <br> North Central US <br> Sweden Central <br> Switzerland North<br> UK South | 16,384 | Sep 2021 |
123
126
|`gpt-35-turbo-instruct` (0914) | East US <br> Sweden Central | 4097 |Sep 2021 |
127
+
|`gpt-35-turbo` (1106) | Australia East <br> Canada East <br> France Central <br> Sweden Central<br> UK South | Input: 16,385<br> Output: 4,096 | Sep 2021|
124
128
125
-
<sup>1</sup> This model will accept requests > 4096 tokens. It is not recommended to exceed the 4096 input token limit as the newer version of the model are capped at 4096 tokens. If you encounter issues when exceeding 4096 input tokens with this model this configuration is not officially supported.
129
+
**<sup>1</sup>** This model will accept requests > 4096 tokens. It is not recommended to exceed the 4096 input token limit as the newer version of the model are capped at 4096 tokens. If you encounter issues when exceeding 4096 input tokens with this model this configuration is not officially supported.
title: 'How to use JSON mode with Azure OpenAI Service'
3
+
titleSuffix: Azure OpenAI
4
+
description: Learn how to improve your chat completions with Azure OpenAI JSON mode
5
+
services: cognitive-services
6
+
manager: nitinme
7
+
ms.service: azure-ai-openai
8
+
ms.topic: how-to
9
+
ms.date: 11/17/2023
10
+
author: mrbullwinkle
11
+
ms.author: mbullwin
12
+
recommendations: false
13
+
keywords:
14
+
15
+
---
16
+
17
+
# Learn how to use JSON mode
18
+
19
+
JSON mode allows you to set the models response format to return a valid JSON object as part of a chat completion. While generating valid JSON was possible previously, there could be issues with response consistency that would lead to invalid JSON objects being generated.
20
+
21
+
## JSON mode support
22
+
23
+
JSON mode is only currently supported with the following:
model="gpt-4-1106-preview", # Model = should match the deployment name you chose for your 1106-preview model deployment
48
+
response_format={ "type": "json_object" },
49
+
messages=[
50
+
{"role": "system", "content": "You are a helpful assistant designed to output JSON."},
51
+
{"role": "user", "content": "Who won the world series in 2020?"}
52
+
]
53
+
)
54
+
print(response.choices[0].message.content)
55
+
```
56
+
57
+
### Output
58
+
59
+
```output
60
+
{
61
+
"winner": "Los Angeles Dodgers",
62
+
"event": "World Series",
63
+
"year": 2020
64
+
}
65
+
```
66
+
67
+
There are two key factors that need to be present to successfully use JSON mode:
68
+
69
+
-`response_format={ "type": "json_object" }`
70
+
- We have told the model to output JSON as part of the system message.
71
+
72
+
Including guidance to the model that it should produce JSON as part of the messages conversation is **required**. We recommend adding this instruction as part of the system message. According to OpenAI failure to add this instruction can cause the model to *"generate an unending stream of whitespace and the request may run continually until it reaches the token limit."*
73
+
74
+
When using the [OpenAI Python API library](https://github.com/openai/openai-python) failure to include "JSON" within the messages will return:
75
+
76
+
### Output
77
+
78
+
```output
79
+
BadRequestError: Error code: 400 - {'error': {'message': "'messages' must contain the word 'json' in some form, to use 'response_format' of type 'json_object'.", 'type': 'invalid_request_error', 'param': 'messages', 'code': None}}
80
+
```
81
+
82
+
## Additional considerations
83
+
84
+
You should check `finish_reason` for the value `length` before parsing the response. When this is present, you might have generated partial JSON. This means that output from the model was larger than the available max_tokens that were set as part of the request, or the conversation itself exceeded the token limit.
85
+
86
+
JSON mode will produce JSON that is valid and will parse without errors. However, this doesn't mean that output will match a specific schema.
0 commit comments