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
Copy file name to clipboardExpand all lines: articles/ai-services/openai/how-to/dall-e.md
-158Lines changed: 0 additions & 158 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,26 +21,14 @@ OpenAI's DALL-E models generate images based on user-provided text prompts. This
21
21
22
22
## Prerequisites
23
23
24
-
#### [DALL-E 3](#tab/dalle3)
25
-
26
24
- An Azure subscription. You can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?icid=ai-services).
27
25
- An Azure OpenAI resource created in a supported region. See [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability).
28
26
-- Deploy a *dall-e-3* model with your Azure OpenAI resource.
29
27
30
-
#### [DALL-E 2 (preview)](#tab/dalle2)
31
-
32
-
- An Azure subscription. You can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?icid=ai-services).
33
-
- An Azure OpenAI resource created in a supported region. See [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability). For more information, see [Create and deploy an Azure OpenAI Service resource](../how-to/create-resource.md).
34
-
35
-
---
36
-
37
28
## Call the Image Generation APIs
38
29
39
30
The following command shows the most basic way to use DALL-E with code. If this is your first time using these models programmatically, we recommend starting with the [DALL-E quickstart](/azure/ai-services/openai/dall-e-quickstart).
40
31
41
-
42
-
#### [DALL-E 3](#tab/dalle3)
43
-
44
32
Send a POST request to:
45
33
46
34
```
@@ -70,72 +58,10 @@ The following is a sample request body. You specify a number of options, defined
70
58
}
71
59
```
72
60
73
-
74
-
#### [DALL-E 2 (preview)](#tab/dalle2)
75
-
76
-
Image generation with DALL-E 2 is asynchronous and requires two API calls.
-`<your_resource_name>` is the name of your Azure OpenAI resource.
86
-
-`<api_version>` is the version of the API you want to use. For example, `2023-06-01-preview`.
87
-
88
-
**Required headers**:
89
-
-`Content-Type`: `application/json`
90
-
-`api-key`: `<your_API_key>`
91
-
92
-
**Body**:
93
-
94
-
The following is a sample request body. You specify a number of options, defined in later sections.
95
-
96
-
```json
97
-
{
98
-
"prompt": "a multi-colored umbrella on the beach, disposable camera",
99
-
"size": "1024x1024",
100
-
"n": 1
101
-
}
102
-
```
103
-
104
-
The operation returns a `202` status code and a JSON object containing the ID and status of the operation
105
-
106
-
```json
107
-
{
108
-
"id": "3d3d3d3d-4444-eeee-5555-6f6f6f6f6f6f",
109
-
"status": "notRunning"
110
-
}
111
-
```
112
-
113
-
To retrieve the image generation results, make a GET request to:
114
-
115
-
```
116
-
GET https://<your_resource_name>.openai.azure.com/openai/operations/images/<operation_id>?api-version=<api_version>
117
-
```
118
-
119
-
**Replace the following placeholders**:
120
-
-`<your_resource_name>` is the name of your Azure OpenAI resource.
121
-
-`<operation_id>` is the ID of the operation returned in the previous step.
122
-
-`<api_version>` is the version of the API you want to use. For example, `2023-06-01-preview`.
123
-
124
-
**Required headers**:
125
-
-`Content-Type`: `application/json`
126
-
-`api-key`: `<your_API_key>`
127
-
128
-
The response from this API call contains your generated image.
129
-
130
-
---
131
-
132
-
133
61
## Output
134
62
135
63
The output from a successful image generation API call looks like the following example. The `url` field contains a URL where you can download the generated image. The URL stays active for 24 hours.
136
64
137
-
#### [DALL-E 3](#tab/dalle3)
138
-
139
65
```json
140
66
{
141
67
"created": 1698116662,
@@ -148,37 +74,12 @@ The output from a successful image generation API call looks like the following
148
74
}
149
75
```
150
76
151
-
#### [DALL-E 2 (preview)](#tab/dalle2)
152
-
153
-
```json
154
-
{
155
-
"created": 1685130482,
156
-
"expires": 1685216887,
157
-
"id": "<operation_id>",
158
-
"result":
159
-
{
160
-
"data":
161
-
[
162
-
{
163
-
"url": "<URL_to_generated_image>"
164
-
}
165
-
]
166
-
},
167
-
"status": "succeeded"
168
-
}
169
-
```
170
-
171
-
---
172
-
173
-
174
77
### API call rejection
175
78
176
79
Prompts and images are filtered based on our content policy, returning an error when a prompt or image is flagged.
177
80
178
81
If your prompt is flagged, the `error.code` value in the message is set to `contentFilter`. Here's an example:
179
82
180
-
#### [DALL-E 3](#tab/dalle3)
181
-
182
83
```json
183
84
{
184
85
"created": 1698435368,
@@ -190,26 +91,6 @@ If your prompt is flagged, the `error.code` value in the message is set to `cont
190
91
}
191
92
```
192
93
193
-
#### [DALL-E 2 (preview)](#tab/dalle2)
194
-
195
-
```json
196
-
{
197
-
"created": 1589478378,
198
-
"error": {
199
-
"code": "contentFilter",
200
-
"message": "Your task failed as a result of our safety system."
201
-
},
202
-
"id": "4e4e4e4e-5555-ffff-6666-7a7a7a7a7a7a",
203
-
"status": "failed"
204
-
}
205
-
```
206
-
207
-
---
208
-
209
-
It's also possible that the generated image itself is filtered. In this case, the error message is set to *Generated image was filtered as a result of our safety system*. Here's an example:
210
-
211
-
#### [DALL-E 3](#tab/dalle3)
212
-
213
94
```json
214
95
{
215
96
"created": 1698435368,
@@ -221,31 +102,6 @@ It's also possible that the generated image itself is filtered. In this case, th
221
102
}
222
103
```
223
104
224
-
#### [DALL-E 2 (preview)](#tab/dalle2)
225
-
226
-
```json
227
-
{
228
-
"created": 1589478378,
229
-
"expires": 1589478399,
230
-
"id": "4e4e4e4e-5555-ffff-6666-7a7a7a7a7a7a",
231
-
"lastActionDateTime": 1589478378,
232
-
"data": [
233
-
{
234
-
"url": "<URL_TO_IMAGE>"
235
-
},
236
-
{
237
-
"error": {
238
-
"code": "contentFilter",
239
-
"message": "Generated image was filtered as a result of our safety system."
240
-
}
241
-
}
242
-
],
243
-
"status": "succeeded"
244
-
}
245
-
```
246
-
247
-
---
248
-
249
105
## Writing image prompts
250
106
251
107
Your image prompts should describe the content you want to see in the image, and the visual style of image.
@@ -260,8 +116,6 @@ When writing prompts, consider that the image generation APIs come with a conten
260
116
261
117
The following API body parameters are available for DALL-E image generation.
262
118
263
-
#### [DALL-E 3](#tab/dalle3)
264
-
265
119
### Size
266
120
267
121
Specify the size of the generated images. Must be one of `1024x1024`, `1792x1024`, or `1024x1792` for DALL-E 3 models. Square images are faster to generate.
@@ -288,18 +142,6 @@ With DALL-E 3, you can't generate more than one image in a single API call: the
288
142
289
143
The format in which the generated images are returned. Must be one of `url` (a URL pointing to the image) or `b64_json` (the base 64-byte code in JSON format). The default is `url`.
290
144
291
-
#### [DALL-E 2 (preview)](#tab/dalle2)
292
-
293
-
### Size
294
-
295
-
Specify the size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` for DALL-E 2 models.
296
-
297
-
### Number
298
-
299
-
Set the `n` parameter to an integer between 1 and 10 to generate multiple images at the same time using DALL-E 2. The images share an operation ID; you receive them all with the same retrieval API call.
Copy file name to clipboardExpand all lines: articles/ai-services/openai/includes/dall-e-python.md
-75Lines changed: 0 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,22 +17,11 @@ Use this guide to get started generating images with the Azure OpenAI SDK for Py
17
17
18
18
## Prerequisites
19
19
20
-
#### [DALL-E 3](#tab/dalle3)
21
-
22
20
- An Azure subscription. <ahref="https://azure.microsoft.com/free/ai-services"target="_blank">Create one for free</a>.
23
21
- <ahref="https://www.python.org/"target="_blank">Python 3.8 or later version</a>.
24
22
- An Azure OpenAI resource created in a compatible region. See [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability).
25
23
- Then, you need to deploy a `dalle3` model with your Azure resource. For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
26
24
27
-
#### [DALL-E 2 (preview)](#tab/dalle2)
28
-
29
-
- An Azure subscription. <ahref="https://azure.microsoft.com/free/ai-services"target="_blank">Create one for free</a>.
30
-
- <ahref="https://www.python.org/"target="_blank">Python 3.8 or later version</a>.
31
-
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
32
-
33
-
---
34
-
35
-
36
25
## Setup
37
26
38
27
### Retrieve key and endpoint
@@ -55,38 +44,22 @@ Go to your resource in the Azure portal. On the navigation pane, select **Keys a
55
44
56
45
Open a command prompt and browse to your project folder. Install the OpenAI Python SDK by using the following command:
57
46
58
-
#### [DALL-E 3](#tab/dalle3)
59
-
60
47
```bash
61
48
pip install openai
62
49
```
63
50
64
-
#### [DALL-E 2 (preview)](#tab/dalle2)
65
-
66
-
> [!IMPORTANT]
67
-
> The latest release of the [OpenAI Python library](https://pypi.org/project/openai/) does not currently support DALL-E 2 when used with Azure OpenAI. To access DALL-E 2 with Azure OpenAI use version `0.28.1`. Or, follow the [migration guide](/azure/ai-services/openai/how-to/migration?tabs=python%2Cdalle-fix) to use DALL-E 2 with OpenAI 1.x.
68
-
69
-
```bash
70
-
pip install openai==0.28.1
71
-
```
72
-
---
73
-
74
51
Install the following libraries as well:
75
-
76
52
```bash
77
53
pip install requests
78
54
pip install pillow
79
55
```
80
56
81
-
82
57
## Generate images with DALL-E
83
58
84
59
Create a new python file, _quickstart.py_. Open it in your preferred editor or IDE.
85
60
86
61
Replace the contents of _quickstart.py_ with the following code.
87
62
88
-
#### [DALL-E 3](#tab/dalle3)
89
-
90
63
```python
91
64
from openai import AzureOpenAI
92
65
import os
@@ -133,54 +106,6 @@ image.show()
133
106
1. Change the value of `prompt` to your preferred text.
134
107
1. Change the value of `model` to the name of your deployed DALL-E 3 model.
image_url = generation_response["data"][0]["url"] # extract image URL from response
171
-
generated_image = requests.get(image_url).content # download the image
172
-
withopen(image_path, "wb") as image_file:
173
-
image_file.write(generated_image)
174
-
175
-
# Display the image in the default image viewer
176
-
image = Image.open(image_path)
177
-
image.show()
178
-
```
179
-
1. Enter your endpoint URL and key in the appropriate fields.
180
-
1. Change the value of `prompt` to your preferred text.
181
-
182
-
---
183
-
184
109
> [!IMPORTANT]
185
110
> Remember to remove the key from your code when you're done, and never post your key publicly. For production, use a secure way of storing and accessing your credentials. For more information, see [Azure Key Vault](/azure/key-vault/general/overview).
0 commit comments