Skip to content

Commit cd72392

Browse files
committed
update
1 parent a5fc6cd commit cd72392

File tree

5 files changed

+3
-362
lines changed

5 files changed

+3
-362
lines changed

articles/ai-services/openai/api-version-deprecation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This version contains support for the latest Azure OpenAI features including:
3737
- [Assistants API](./assistants-reference.md). [**Added in 2024-02-15-preview**]
3838
- [Text to speech](./text-to-speech-quickstart.md). [**Added in 2024-02-15-preview**]
3939
- [DALL-E 3](./dall-e-quickstart.md). [**Added in 2023-12-01-preview**]
40-
- [Fine-tuning](./how-to/fine-tuning.md) `gpt-35-turbo`, `babbage-002`, and `davinci-002` models.[**Added in 2023-10-01-preview**]
40+
- [Fine-tuning](./how-to/fine-tuning.md). [**Added in 2023-10-01-preview**]
4141
- [Whisper](./whisper-quickstart.md). [**Added in 2023-09-01-preview**]
4242
- [Function calling](./how-to/function-calling.md) [**Added in 2023-07-01-preview**]
4343
- [Retrieval augmented generation with your data feature](./use-your-data-quickstart.md). [**Added in 2023-06-01-preview**]

articles/ai-services/openai/how-to/dall-e.md

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,14 @@ OpenAI's DALL-E models generate images based on user-provided text prompts. This
2121

2222
## Prerequisites
2323

24-
#### [DALL-E 3](#tab/dalle3)
25-
2624
- An Azure subscription. You can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?icid=ai-services).
2725
- An Azure OpenAI resource created in a supported region. See [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability).
2826
- - Deploy a *dall-e-3* model with your Azure OpenAI resource.
2927

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-
3728
## Call the Image Generation APIs
3829

3930
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).
4031

41-
42-
#### [DALL-E 3](#tab/dalle3)
43-
4432
Send a POST request to:
4533

4634
```
@@ -70,72 +58,10 @@ The following is a sample request body. You specify a number of options, defined
7058
}
7159
```
7260

73-
74-
#### [DALL-E 2 (preview)](#tab/dalle2)
75-
76-
Image generation with DALL-E 2 is asynchronous and requires two API calls.
77-
78-
First, send a POST request to:
79-
80-
```
81-
https://<your_resource_name>.openai.azure.com/openai/images/generations:submit?api-version=<api_version>
82-
```
83-
84-
**Replace the following placeholders**:
85-
- `<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-
13361
## Output
13462

13563
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.
13664

137-
#### [DALL-E 3](#tab/dalle3)
138-
13965
```json
14066
{
14167
"created": 1698116662,
@@ -148,37 +74,12 @@ The output from a successful image generation API call looks like the following
14874
}
14975
```
15076

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-
17477
### API call rejection
17578

17679
Prompts and images are filtered based on our content policy, returning an error when a prompt or image is flagged.
17780

17881
If your prompt is flagged, the `error.code` value in the message is set to `contentFilter`. Here's an example:
17982

180-
#### [DALL-E 3](#tab/dalle3)
181-
18283
```json
18384
{
18485
"created": 1698435368,
@@ -190,26 +91,6 @@ If your prompt is flagged, the `error.code` value in the message is set to `cont
19091
}
19192
```
19293

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-
21394
```json
21495
{
21596
"created": 1698435368,
@@ -221,31 +102,6 @@ It's also possible that the generated image itself is filtered. In this case, th
221102
}
222103
```
223104

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-
249105
## Writing image prompts
250106

251107
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
260116

261117
The following API body parameters are available for DALL-E image generation.
262118

263-
#### [DALL-E 3](#tab/dalle3)
264-
265119
### Size
266120

267121
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
288142

289143
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`.
290144

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.
300-
301-
---
302-
303145
## Related content
304146

305147
* [What is Azure OpenAI Service?](../overview.md)

articles/ai-services/openai/includes/dall-e-python.md

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,11 @@ Use this guide to get started generating images with the Azure OpenAI SDK for Py
1717

1818
## Prerequisites
1919

20-
#### [DALL-E 3](#tab/dalle3)
21-
2220
- An Azure subscription. <a href="https://azure.microsoft.com/free/ai-services" target="_blank">Create one for free</a>.
2321
- <a href="https://www.python.org/" target="_blank">Python 3.8 or later version</a>.
2422
- An Azure OpenAI resource created in a compatible region. See [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability).
2523
- 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).
2624

27-
#### [DALL-E 2 (preview)](#tab/dalle2)
28-
29-
- An Azure subscription. <a href="https://azure.microsoft.com/free/ai-services" target="_blank">Create one for free</a>.
30-
- <a href="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-
3625
## Setup
3726

3827
### Retrieve key and endpoint
@@ -55,38 +44,22 @@ Go to your resource in the Azure portal. On the navigation pane, select **Keys a
5544

5645
Open a command prompt and browse to your project folder. Install the OpenAI Python SDK by using the following command:
5746

58-
#### [DALL-E 3](#tab/dalle3)
59-
6047
```bash
6148
pip install openai
6249
```
6350

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-
7451
Install the following libraries as well:
75-
7652
```bash
7753
pip install requests
7854
pip install pillow
7955
```
8056

81-
8257
## Generate images with DALL-E
8358

8459
Create a new python file, _quickstart.py_. Open it in your preferred editor or IDE.
8560

8661
Replace the contents of _quickstart.py_ with the following code.
8762

88-
#### [DALL-E 3](#tab/dalle3)
89-
9063
```python
9164
from openai import AzureOpenAI
9265
import os
@@ -133,54 +106,6 @@ image.show()
133106
1. Change the value of `prompt` to your preferred text.
134107
1. Change the value of `model` to the name of your deployed DALL-E 3 model.
135108

136-
#### [DALL-E 2 (preview)](#tab/dalle2)
137-
138-
```python
139-
import openai
140-
import os
141-
import requests
142-
from PIL import Image
143-
144-
# Get endpoint and key from environment variables
145-
openai.api_base = os.environ['AZURE_OPENAI_ENDPOINT']
146-
openai.api_key = os.environ['AZURE_OPENAI_API_KEY']
147-
148-
# Assign the API version (DALL-E is currently supported for the 2023-06-01-preview API version only)
149-
openai.api_version = '2023-06-01-preview'
150-
openai.api_type = 'azure'
151-
152-
# Create an image by using the image generation API
153-
generation_response = openai.Image.create(
154-
prompt='A painting of a dog', # Enter your prompt text here
155-
size='1024x1024',
156-
n=2
157-
)
158-
159-
# Set the directory for the stored image
160-
image_dir = os.path.join(os.curdir, 'images')
161-
162-
# If the directory doesn't exist, create it
163-
if not os.path.isdir(image_dir):
164-
os.mkdir(image_dir)
165-
166-
# Initialize the image path (note the filetype should be png)
167-
image_path = os.path.join(image_dir, 'generated_image.png')
168-
169-
# Retrieve the generated image
170-
image_url = generation_response["data"][0]["url"] # extract image URL from response
171-
generated_image = requests.get(image_url).content # download the image
172-
with open(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-
184109
> [!IMPORTANT]
185110
> 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).
186111

0 commit comments

Comments
 (0)