|
| 1 | +# ------------------------------------ |
| 2 | +# Copyright (c) Microsoft Corporation. |
| 3 | +# Licensed under the MIT License. |
| 4 | +# ------------------------------------ |
| 5 | + |
| 6 | +import pytest |
| 7 | +import openai |
| 8 | +from devtools_testutils import AzureRecordedTestCase |
| 9 | +from conftest import configure, AZURE, OPENAI, ALL |
| 10 | + |
| 11 | + |
| 12 | +class TestDallEAsync(AzureRecordedTestCase): |
| 13 | + |
| 14 | + @pytest.mark.asyncio |
| 15 | + @pytest.mark.parametrize("api_type", ALL) |
| 16 | + @configure |
| 17 | + async def test_image_create(self, azure_openai_creds, api_type): |
| 18 | + image = await openai.Image.acreate( |
| 19 | + prompt="a cute baby seal" |
| 20 | + ) |
| 21 | + assert image.created |
| 22 | + assert len(image.data) == 1 |
| 23 | + assert image.data[0].url |
| 24 | + |
| 25 | + @pytest.mark.asyncio |
| 26 | + @pytest.mark.parametrize("api_type", [AZURE, OPENAI]) |
| 27 | + @configure |
| 28 | + async def test_image_create_n(self, azure_openai_creds, api_type): |
| 29 | + image = await openai.Image.acreate( |
| 30 | + prompt="a cute baby seal", |
| 31 | + n=2 |
| 32 | + ) |
| 33 | + assert image.created |
| 34 | + assert len(image.data) == 2 |
| 35 | + for img in image.data: |
| 36 | + assert img.url |
| 37 | + |
| 38 | + @pytest.mark.asyncio |
| 39 | + @pytest.mark.parametrize("api_type", [AZURE, OPENAI]) |
| 40 | + @configure |
| 41 | + async def test_image_create_size(self, azure_openai_creds, api_type): |
| 42 | + image = await openai.Image.acreate( |
| 43 | + prompt="a cute baby seal", |
| 44 | + size="256x256" |
| 45 | + ) |
| 46 | + assert image.created |
| 47 | + assert len(image.data) == 1 |
| 48 | + assert image.data[0].url |
| 49 | + |
| 50 | + @pytest.mark.asyncio |
| 51 | + @pytest.mark.parametrize("api_type", [OPENAI]) |
| 52 | + @configure |
| 53 | + async def test_image_create_response_format(self, azure_openai_creds, api_type): |
| 54 | + image = await openai.Image.acreate( |
| 55 | + prompt="a cute baby seal", |
| 56 | + response_format="b64_json" # No Azure support yet |
| 57 | + ) |
| 58 | + assert image.created |
| 59 | + assert len(image.data) == 1 |
| 60 | + assert image.data[0].b64_json |
| 61 | + |
| 62 | + @pytest.mark.asyncio |
| 63 | + @pytest.mark.parametrize("api_type", [AZURE, OPENAI]) |
| 64 | + @configure |
| 65 | + async def test_image_create_user(self, azure_openai_creds, api_type): |
| 66 | + image = await openai.Image.acreate( |
| 67 | + prompt="a cute baby seal", |
| 68 | + user="krista" |
| 69 | + ) |
| 70 | + assert image.created |
| 71 | + assert len(image.data) == 1 |
| 72 | + assert image.data[0].url |
0 commit comments