Skip to content

Commit 687e5ba

Browse files
Merge pull request #268041 from PatrickFarley/openai-updates-2
dalle how-to guide + Risks monitor how-to guide
2 parents f3bc9b3 + 47f5c8a commit 687e5ba

File tree

10 files changed

+445
-6
lines changed

10 files changed

+445
-6
lines changed

articles/ai-services/content-safety/quickstart-text.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Quickstart: Analyze image and text content"
2+
title: "Quickstart: Analyze text content"
33
titleSuffix: Azure AI services
4-
description: Get started using Azure AI Content Safety to analyze image and text content for objectionable material.
4+
description: Get started using Azure AI Content Safety to analyze text content for objectionable material.
55
#services: cognitive-services
66
author: PatrickFarley
77
manager: nitinme
Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
1+
---
2+
title: How to work with DALL-E models
3+
titleSuffix: Azure OpenAI Service
4+
description: Learn about the options for how to use the DALL-E image generation models.
5+
author: PatrickFarley
6+
ms.author: pafarley
7+
ms.service: azure-ai-openai
8+
ms.custom:
9+
ms.topic: how-to
10+
ms.date: 03/04/2024
11+
manager: nitinme
12+
keywords:
13+
zone_pivot_groups:
14+
# Customer intent: as an engineer or hobbyist, I want to know how to use DALL-E image generation models to their full capability.
15+
---
16+
17+
# Learn how to work with the DALL-E models
18+
19+
OpenAI's DALL-E models generate images based on user-provided text prompts. This guide demonstrates how to use the DALL-E models and configure their options through REST API calls.
20+
21+
22+
## Prerequisites
23+
24+
#### [DALL-E 3](#tab/dalle3)
25+
26+
- An Azure subscription. <a href="https://azure.microsoft.com/free/ai-services" target="_blank">Create one for free</a>.
27+
- Access granted to DALL-E in the desired Azure subscription.
28+
- An Azure OpenAI resource created in the `SwedenCentral` region.
29+
- 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).
30+
31+
#### [DALL-E 2 (preview)](#tab/dalle2)
32+
33+
- An Azure subscription. <a href="https://azure.microsoft.com/free/ai-services" target="_blank">Create one for free</a>.
34+
- Access granted to DALL-E in the desired Azure subscription.
35+
- An Azure OpenAI resource created in the East US region. For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
36+
37+
---
38+
39+
## Call the Image Generation APIs
40+
41+
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).
42+
43+
44+
#### [DALL-E 3](#tab/dalle3)
45+
46+
47+
Send a POST request to:
48+
49+
```
50+
https://<your_resource_name>.deployments/<your_deployment_name>/images/generations?api-version=<api_version>
51+
```
52+
53+
where:
54+
- `<your_resource_name>` is the name of your Azure OpenAI resource.
55+
- `<your_deployment_name>` is the name of your DALL-E 3 model deployment.
56+
- `<api_version>` is the version of the API you want to use. For example, `2024-02-01`.
57+
58+
**Required headers**:
59+
- `Content-Type`: `application/json`
60+
- `api-key`: `<your_API_key>`
61+
62+
**Body**:
63+
64+
The following is a sample request body. You specify a number of options, defined in later sections.
65+
66+
```json
67+
{
68+
"prompt": "A multi-colored umbrella on the beach, disposable camera",
69+
"size": "1024x1024",
70+
"n": 1,
71+
"quality": "hd",
72+
"style": "vivid"
73+
}
74+
```
75+
76+
77+
#### [DALL-E 2 (preview)](#tab/dalle2)
78+
79+
Image generation with DALL-E 2 is asynchronous and requires two API calls.
80+
81+
First, send a POST request to:
82+
83+
```
84+
https://<your_resource_name>.openai.azure.com/openai/images/generations:submit?api-version=<api_version>
85+
```
86+
87+
where:
88+
- `<your_resource_name>` is the name of your Azure OpenAI resource.
89+
- `<api_version>` is the version of the API you want to use. For example, `2023-06-01-preview`.
90+
91+
**Required headers**:
92+
- `Content-Type`: `application/json`
93+
- `api-key`: `<your_API_key>`
94+
95+
**Body**:
96+
97+
The following is a sample request body. You specify a number of options, defined in later sections.
98+
99+
```json
100+
{
101+
"prompt": "a multi-colored umbrella on the beach, disposable camera",
102+
"size": "1024x1024",
103+
"n": 1
104+
}
105+
```
106+
107+
The operation returns a `202` status code and a JSON object containing the ID and status of the operation
108+
109+
```json
110+
{
111+
"id": "f508bcf2-e651-4b4b-85a7-58ad77981ffa",
112+
"status": "notRunning"
113+
}
114+
```
115+
116+
To retrieve the image generation results, make a GET request to:
117+
118+
```
119+
GET https://<your_resource_name>.openai.azure.com/openai/operations/images/<operation_id>?api-version=<api_version>
120+
```
121+
122+
where:
123+
- `<your_resource_name>` is the name of your Azure OpenAI resource.
124+
- `<operation_id>` is the ID of the operation returned in the previous step.
125+
- `<api_version>` is the version of the API you want to use. For example, `2023-06-01-preview`.
126+
127+
**Required headers**:
128+
- `Content-Type`: `application/json`
129+
- `api-key`: `<your_API_key>`
130+
131+
The response from this API call contains your generated image.
132+
133+
---
134+
135+
136+
## Output
137+
138+
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.
139+
140+
141+
#### [DALL-E 3](#tab/dalle3)
142+
143+
```json
144+
{
145+
"created": 1698116662,
146+
"data": [
147+
{
148+
"url": "<URL_to_generated_image>",
149+
"revised_prompt": "<prompt_that_was_used>"
150+
}
151+
]
152+
}
153+
```
154+
155+
#### [DALL-E 2 (preview)](#tab/dalle2)
156+
157+
```json
158+
{
159+
"created": 1685130482,
160+
"expires": 1685216887,
161+
"id": "<operation_id>",
162+
"result":
163+
{
164+
"data":
165+
[
166+
{
167+
"url": "<URL_to_generated_image>"
168+
}
169+
]
170+
},
171+
"status": "succeeded"
172+
}
173+
```
174+
175+
---
176+
177+
178+
179+
### API call rejection
180+
181+
Prompts and images are filtered based on our content policy, returning an error when a prompt or image is flagged.
182+
183+
If your prompt is flagged, the `error.code` value in the message is set to `contentFilter`. Here's an example:
184+
185+
#### [DALL-E 3](#tab/dalle3)
186+
187+
```json
188+
{
189+
"created": 1698435368,
190+
"error":
191+
{
192+
"code": "contentFilter",
193+
"message": "Your task failed as a result of our safety system."
194+
}
195+
}
196+
```
197+
198+
#### [DALL-E 2 (preview)](#tab/dalle2)
199+
200+
```json
201+
{
202+
"created": 1589478378,
203+
"error": {
204+
"code": "contentFilter",
205+
"message": "Your task failed as a result of our safety system."
206+
},
207+
"id": "9484f239-9a05-41ba-997b-78252fec4b34",
208+
"status": "failed"
209+
}
210+
```
211+
212+
---
213+
214+
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:
215+
216+
#### [DALL-E 3](#tab/dalle3)
217+
218+
```json
219+
{
220+
"created": 1698435368,
221+
"error":
222+
{
223+
"code": "contentFilter",
224+
"message": "Generated image was filtered as a result of our safety system."
225+
}
226+
}
227+
```
228+
229+
#### [DALL-E 2 (preview)](#tab/dalle2)
230+
231+
```json
232+
{
233+
"created": 1589478378,
234+
"expires": 1589478399,
235+
"id": "9484f239-9a05-41ba-997b-78252fec4b34",
236+
"lastActionDateTime": 1589478378,
237+
"data": [
238+
{
239+
"url": "<URL_TO_IMAGE>"
240+
},
241+
{
242+
"error": {
243+
"code": "contentFilter",
244+
"message": "Generated image was filtered as a result of our safety system."
245+
}
246+
}
247+
],
248+
"status": "succeeded"
249+
}
250+
```
251+
252+
---
253+
254+
## Writing image prompts
255+
256+
Your image prompts should describe the content you want to see in the image, as well as the visual style of image.
257+
258+
> [!TIP]
259+
> For a thorough look at how you can tweak your text prompts to generate different kinds of images, see the [Dallery DALL-E 2 prompt book](https://dallery.gallery/wp-content/uploads/2022/07/The-DALL%C2%B7E-2-prompt-book-v1.02.pdf).
260+
261+
#### [DALL-E 3](#tab/dalle3)
262+
263+
When writing prompts, consider that the image generation APIs come with a content moderation filter. If the service recognizes your prompt as harmful content, it doesn't generate an image. For more information, see [Content filtering](../concepts/content-filter.md).
264+
265+
### Prompt transformation
266+
267+
DALL-E 3 includes built-in prompt rewriting to enhance images, reduce bias, and increase natural variation of images.
268+
269+
| **Example text prompt** | **Example generated image without prompt transformation** | **Example generated image with prompt transformation** |
270+
|---|---|---|
271+
|"Watercolor painting of the Seattle skyline" | ![Watercolor painting of the Seattle skyline (simple).](../media/how-to/generated-seattle.png) | ![Watercolor painting of the Seattle skyline, with more detail and structure.](../media/how-to/generated-seattle-prompt-transformed.png) |
272+
273+
The updated prompt is visible in the `revised_prompt` field of the data response object.
274+
275+
While it is not currently possible to disable this feature, you can use special prompting to get outputs closer to your original prompt by adding the following to it: `I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:`.
276+
277+
#### [DALL-E 2 (preview)](#tab/dalle2)
278+
279+
When writing prompts, consider that the image generation APIs come with a content moderation filter. If the service recognizes your prompt as harmful content, it doesn't generate an image. For more information, see [Content filtering](../concepts/content-filter.md).
280+
281+
---
282+
283+
284+
## Specify API options
285+
286+
The following API body parameters are available for DALL-E image generation.
287+
288+
#### [DALL-E 3](#tab/dalle3)
289+
290+
### Size
291+
292+
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.
293+
294+
295+
### Style
296+
297+
DALL-E 3 introduces two style options: `natural` and `vivid`. The `natural` style is more similar to the DALL-E 2 default style, while the `vivid` style generates more hyper-real and cinematic images.
298+
299+
The `natural` style is useful in cases where DALL-E 3 over-exaggerates or confuses a subject that's meant to be more simple, subdued, or realistic.
300+
301+
The default value is `vivid`.
302+
303+
### Quality
304+
305+
There are two options for image quality: `hd` and `standard`. `hd` creates images with finer details and greater consistency across the image. `standard` images can be generated faster.
306+
307+
The default value is `standard`.
308+
309+
### Number
310+
311+
With DALL-E 3, you cannot generate more than one image in a single API call: the _n_ parameter must be set to `1`. If you need to generate multiple images at once, make parallel requests.
312+
313+
### Response format
314+
315+
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`.
316+
317+
#### [DALL-E 2 (preview)](#tab/dalle2)
318+
319+
### Size
320+
321+
Specify the size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` for DALL-E 2 models.
322+
323+
### Number
324+
325+
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 will share an operation ID; you receive them all with the same retrieval API call.
326+
327+
---
328+
329+
## Next steps
330+
331+
* [Learn more about Azure OpenAI](../overview.md).
332+
* [DALL-E quickstart](../dall-e-quickstart.md)
333+
* [Image generation API reference](/azure/ai-services/openai/reference#image-generation)
334+
335+
336+
<!-- OAI HT guide https://platform.openai.com/docs/guides/images/usage
337+
dall-e 3 features here: https://cookbook.openai.com/articles/what_is_new_with_dalle_3 -->
338+
339+

0 commit comments

Comments
 (0)