Skip to content

Commit 42f0cca

Browse files
Fix mypy error: add null check for Optional[list[Image]] before indexing
Co-authored-by: kristapratico <[email protected]>
1 parent 7b215dc commit 42f0cca

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sdk/openai/azure-openai/samples/images_aoai_quickstart.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ def images_aoai_quickstart() -> None:
6262
image_path = os.path.join(image_dir, 'generated_image.png')
6363

6464
# Retrieve the generated image
65-
image_url = result.data[0].url # extract image URL from response
66-
if image_url:
67-
generated_image = httpx.get(image_url).content # download the image
65+
if result.data and len(result.data) > 0:
66+
image_url = result.data[0].url # extract image URL from response
67+
if image_url:
68+
generated_image = httpx.get(image_url).content # download the image
6869

69-
with open(image_path, "wb") as image_file:
70-
image_file.write(generated_image)
70+
with open(image_path, "wb") as image_file:
71+
image_file.write(generated_image)
7172

72-
# Display the image in the default image viewer
73-
image = Image.open(image_path)
74-
image.show()
73+
# Display the image in the default image viewer
74+
image = Image.open(image_path)
75+
image.show()
7576

7677
if __name__ == "__main__":
7778
images_aoai_quickstart()

0 commit comments

Comments
 (0)