Skip to content

Commit bc3b212

Browse files
committed
update
1 parent 8115f3e commit bc3b212

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

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

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,43 +71,6 @@ The following is a sample request body. You specify a number of options, defined
7171
}
7272
```
7373

74-
### Streaming
75-
76-
You can stream image generation requests by setting the `stream` parameter to `true`, and setting the `partial_images` parameter to a value between 0 and 3.
77-
78-
```python
79-
from openai import OpenAI
80-
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
81-
82-
token_provider = get_bearer_token_provider(
83-
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
84-
)
85-
86-
client = OpenAI(
87-
base_url = "https://RESOURCE-NAME-HERE/openai/v1/",
88-
api_key=token_provider,
89-
default_headers={"x-ms-oai-image-generation-deployment":"gpt-image-1", "api_version":"preview"}
90-
)
91-
92-
stream = client.images.generate(
93-
model="gpt-image-1",
94-
prompt="A cute baby sea otter",
95-
n=1,
96-
size="1024x1024",
97-
stream=True,
98-
partial_images = 2
99-
)
100-
101-
for event in stream:
102-
if event.type == "image_generation.partial_image":
103-
idx = event.partial_image_index
104-
image_base64 = event.b64_json
105-
image_bytes = base64.b64decode(image_base64)
106-
with open(f"river{idx}.png", "wb") as f:
107-
f.write(image_bytes)
108-
109-
```
110-
11174
#### [DALL-E 3](#tab/dalle-3)
11275

11376
Send a POST request to:
@@ -182,8 +145,46 @@ The response from a successful image generation API call looks like the followin
182145
]
183146
}
184147
```
148+
185149
---
186150

151+
### Streaming
152+
153+
You can stream image generation requests to `gpt-image-1` by setting the `stream` parameter to `true`, and setting the `partial_images` parameter to a value between 0 and 3.
154+
155+
```python
156+
from openai import OpenAI
157+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
158+
159+
token_provider = get_bearer_token_provider(
160+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
161+
)
162+
163+
client = OpenAI(
164+
base_url = "https://RESOURCE-NAME-HERE/openai/v1/",
165+
api_key=token_provider,
166+
default_headers={"x-ms-oai-image-generation-deployment":"gpt-image-1", "api_version":"preview"}
167+
)
168+
169+
stream = client.images.generate(
170+
model="gpt-image-1",
171+
prompt="A cute baby sea otter",
172+
n=1,
173+
size="1024x1024",
174+
stream=True,
175+
partial_images = 2
176+
)
177+
178+
for event in stream:
179+
if event.type == "image_generation.partial_image":
180+
idx = event.partial_image_index
181+
image_base64 = event.b64_json
182+
image_bytes = base64.b64decode(image_base64)
183+
with open(f"river{idx}.png", "wb") as f:
184+
f.write(image_bytes)
185+
186+
```
187+
187188

188189
### API call rejection
189190

0 commit comments

Comments
 (0)