Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(azure): remove unnecessary model parameter and require azure deployment #2123

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
24 changes: 12 additions & 12 deletions src/openai/lib/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ def __init__(
raise ValueError(
"Must provide one of the `base_url` or `azure_endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable"
)

if azure_deployment is not None:
base_url = f"{azure_endpoint.rstrip('/')}/openai/deployments/{azure_deployment}"
else:
base_url = f"{azure_endpoint.rstrip('/')}/openai"
base_url = f"{azure_endpoint.rstrip('/')}/openai"
else:
if azure_endpoint is not None:
raise ValueError("base_url and azure_endpoint are mutually exclusive")
Expand All @@ -208,6 +204,7 @@ def __init__(
# define a sentinel value to avoid any typing issues
api_key = API_KEY_SENTINEL

self._azure_deployment = azure_deployment
super().__init__(
api_key=api_key,
organization=organization,
Expand Down Expand Up @@ -312,12 +309,15 @@ def _configure_realtime(self, model: str, extra_query: Query) -> tuple[Query, di
query = {
**extra_query,
"api-version": self._api_version,
"deployment": model,
}
if self._azure_deployment:
query["deployment"] = self._azure_deployment
else:
query["deployment"] = model
if self.api_key != "<missing API key>":
auth_headers = {"api-key": self.api_key}
else:
token = self._get_azure_ad_token()
token = await self._get_azure_ad_token()
if token:
auth_headers = {"Authorization": f"Bearer {token}"}
return query, auth_headers
Expand Down Expand Up @@ -458,10 +458,7 @@ def __init__(
"Must provide one of the `base_url` or `azure_endpoint` arguments, or the `AZURE_OPENAI_ENDPOINT` environment variable"
)

if azure_deployment is not None:
base_url = f"{azure_endpoint.rstrip('/')}/openai/deployments/{azure_deployment}"
else:
base_url = f"{azure_endpoint.rstrip('/')}/openai"
base_url = f"{azure_endpoint.rstrip('/')}/openai"
else:
if azure_endpoint is not None:
raise ValueError("base_url and azure_endpoint are mutually exclusive")
Expand Down Expand Up @@ -576,8 +573,11 @@ async def _configure_realtime(self, model: str, extra_query: Query) -> tuple[Que
query = {
**extra_query,
"api-version": self._api_version,
"deployment": model,
}
if self._azure_deployment:
query["deployment"] = self._azure_deployment
else:
query["deployment"] = model
if self.api_key != "<missing API key>":
auth_headers = {"api-key": self.api_key}
else:
Expand Down
2 changes: 0 additions & 2 deletions src/openai/resources/beta/realtime/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ async def __aenter__(self) -> AsyncRealtimeConnection:

url = self._prepare_url().copy_with(
params={
**self.__client.base_url.params,
"model": self.__model,
**extra_query,
},
Expand Down Expand Up @@ -510,7 +509,6 @@ def __enter__(self) -> RealtimeConnection:

url = self._prepare_url().copy_with(
params={
**self.__client.base_url.params,
"model": self.__model,
**extra_query,
},
Expand Down