Skip to content

Commit 91f977a

Browse files
add additional tests for deployment fix (#39896)
* try deployment fix * additional tests * revert install
1 parent 1344888 commit 91f977a

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

sdk/openai/azure-openai/tests/test_client.py

+13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ def test_chat_completion_endpoint_deployment(self, client, api_type, api_version
7474
assert "The embeddings operation does not work with the specified model, " \
7575
f"{ENV_AZURE_OPENAI_CHAT_COMPLETIONS_NAME}. Please choose different model and try again" in e.value.message
7676

77+
@configure
78+
@pytest.mark.parametrize("api_type, api_version", [(AZURE, LATEST)])
79+
def test_deployment_with_nondeployment_api(self, client, api_type, api_version, **kwargs):
80+
81+
client = openai.AzureOpenAI(
82+
azure_endpoint=os.getenv(ENV_AZURE_OPENAI_ENDPOINT),
83+
azure_deployment=ENV_AZURE_OPENAI_CHAT_COMPLETIONS_NAME,
84+
azure_ad_token_provider=get_bearer_token_provider(get_credential(), "https://cognitiveservices.azure.com/.default"),
85+
api_version=LATEST,
86+
)
87+
model = client.models.retrieve(**kwargs)
88+
assert model
89+
7790
@configure
7891
@pytest.mark.parametrize("api_type, api_version", [(AZURE, LATEST)])
7992
def test_chat_completion_base_url(self, client, api_type, api_version, **kwargs):

sdk/openai/azure-openai/tests/test_client_async.py

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ async def test_chat_completion_endpoint_deployment(self, client_async, api_type,
7676
assert "The embeddings operation does not work with the specified model, " \
7777
f"{ENV_AZURE_OPENAI_CHAT_COMPLETIONS_NAME}. Please choose different model and try again" in e.value.message
7878

79+
@configure_async
80+
@pytest.mark.asyncio
81+
@pytest.mark.parametrize("api_type, api_version", [(AZURE, LATEST)])
82+
async def test_deployment_with_nondeployment_api(self, client_async, api_type, api_version, **kwargs):
83+
84+
client_async = openai.AsyncAzureOpenAI(
85+
azure_endpoint=os.getenv(ENV_AZURE_OPENAI_ENDPOINT),
86+
azure_deployment=ENV_AZURE_OPENAI_CHAT_COMPLETIONS_NAME,
87+
azure_ad_token_provider=get_bearer_token_provider(get_credential(), "https://cognitiveservices.azure.com/.default"),
88+
api_version=LATEST,
89+
)
90+
model = await client_async.models.retrieve(**kwargs)
91+
assert model
92+
7993
@configure_async
8094
@pytest.mark.asyncio
8195
@pytest.mark.parametrize("api_type, api_version", [(AZURE, LATEST)])

sdk/openai/azure-openai/tests/test_realtime.py

+67
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import pytest
88
import openai
9+
import httpx
910
from devtools_testutils import AzureRecordedTestCase, get_credential
1011
from conftest import (
1112
ENV_AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT,
@@ -106,3 +107,69 @@ def test_realtime_text_ad_token(self, client, api_type, api_version, **kwargs):
106107
assert event.text
107108
elif event.type == "response.done":
108109
break
110+
111+
@configure
112+
@pytest.mark.parametrize(
113+
"api_type, api_version",
114+
[(GPT_4_AZURE, "2024-10-01-preview")],
115+
)
116+
def test_realtime_text_deployment_name(self, client, api_type, api_version, **kwargs):
117+
client = openai.AzureOpenAI(
118+
azure_endpoint=os.getenv(ENV_AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT),
119+
api_key=os.getenv(ENV_AZURE_OPENAI_SWEDENCENTRAL_KEY),
120+
api_version=api_version,
121+
azure_deployment="gpt-4o-realtime-preview-1001"
122+
)
123+
124+
with client.beta.realtime.connect(
125+
model="invalid"
126+
) as connection:
127+
connection.session.update(session={"modalities": ["text"]})
128+
connection.conversation.item.create(
129+
item={
130+
"type": "message",
131+
"role": "user",
132+
"content": [{"type": "input_text", "text": "Say hello!"}],
133+
}
134+
)
135+
connection.response.create()
136+
for event in connection:
137+
if event.type == "response.text.delta":
138+
assert event.delta
139+
elif event.type == "response.text.done":
140+
assert event.text
141+
elif event.type == "response.done":
142+
break
143+
144+
@configure
145+
@pytest.mark.parametrize(
146+
"api_type, api_version",
147+
[(GPT_4_AZURE, "2024-10-01-preview")],
148+
)
149+
def test_realtime_text_websocket_base_url(self, client, api_type, api_version, **kwargs):
150+
client = openai.AzureOpenAI(
151+
base_url="fakebaseurl",
152+
websocket_base_url=httpx.URL(os.getenv(ENV_AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT) + "/openai/").copy_with(scheme="wss"),
153+
api_key=os.getenv(ENV_AZURE_OPENAI_SWEDENCENTRAL_KEY),
154+
api_version=api_version,
155+
)
156+
157+
with client.beta.realtime.connect(
158+
**kwargs
159+
) as connection:
160+
connection.session.update(session={"modalities": ["text"]})
161+
connection.conversation.item.create(
162+
item={
163+
"type": "message",
164+
"role": "user",
165+
"content": [{"type": "input_text", "text": "Say hello!"}],
166+
}
167+
)
168+
connection.response.create()
169+
for event in connection:
170+
if event.type == "response.text.delta":
171+
assert event.delta
172+
elif event.type == "response.text.done":
173+
assert event.text
174+
elif event.type == "response.done":
175+
break

sdk/openai/azure-openai/tests/test_realtime_async.py

+68
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import pytest
88
import openai
9+
import httpx
910
from devtools_testutils import AzureRecordedTestCase, get_credential
1011
from conftest import (
1112
ENV_AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT,
@@ -111,3 +112,70 @@ async def test_realtime_text_ad_token(self, client_async, api_type, api_version,
111112
assert event.text
112113
elif event.type == "response.done":
113114
break
115+
116+
@configure_async
117+
@pytest.mark.asyncio
118+
@pytest.mark.parametrize(
119+
"api_type, api_version",
120+
[(GPT_4_AZURE, "2024-10-01-preview")],
121+
)
122+
async def test_realtime_text_deployment_name(self, client_async, api_type, api_version, **kwargs):
123+
client_async = openai.AsyncAzureOpenAI(
124+
azure_endpoint=os.environ[ENV_AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT],
125+
api_key=os.environ[ENV_AZURE_OPENAI_SWEDENCENTRAL_KEY],
126+
api_version=api_version,
127+
azure_deployment="gpt-4o-realtime-preview-1001",
128+
)
129+
async with client_async.beta.realtime.connect(
130+
model="invalid"
131+
) as connection:
132+
await connection.session.update(session={"modalities": ["text"]})
133+
await connection.conversation.item.create(
134+
item={
135+
"type": "message",
136+
"role": "user",
137+
"content": [{"type": "input_text", "text": "Say hello!"}],
138+
}
139+
)
140+
await connection.response.create()
141+
async for event in connection:
142+
if event.type == "response.text.delta":
143+
assert event.delta
144+
elif event.type == "response.text.done":
145+
assert event.text
146+
elif event.type == "response.done":
147+
break
148+
149+
@configure_async
150+
@pytest.mark.asyncio
151+
@pytest.mark.parametrize(
152+
"api_type, api_version",
153+
[(GPT_4_AZURE, "2024-10-01-preview")],
154+
)
155+
async def test_realtime_text_websocket_base_url(self, client_async, api_type, api_version, **kwargs):
156+
client_async = openai.AsyncAzureOpenAI(
157+
base_url="fakebaseurl",
158+
websocket_base_url=httpx.URL(os.getenv(ENV_AZURE_OPENAI_SWEDENCENTRAL_ENDPOINT) + "/openai/").copy_with(scheme="wss"),
159+
api_key=os.getenv(ENV_AZURE_OPENAI_SWEDENCENTRAL_KEY),
160+
api_version=api_version,
161+
)
162+
163+
async with client_async.beta.realtime.connect(
164+
**kwargs
165+
) as connection:
166+
await connection.session.update(session={"modalities": ["text"]})
167+
await connection.conversation.item.create(
168+
item={
169+
"type": "message",
170+
"role": "user",
171+
"content": [{"type": "input_text", "text": "Say hello!"}],
172+
}
173+
)
174+
await connection.response.create()
175+
async for event in connection:
176+
if event.type == "response.text.delta":
177+
assert event.delta
178+
elif event.type == "response.text.done":
179+
assert event.text
180+
elif event.type == "response.done":
181+
break

0 commit comments

Comments
 (0)