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: Add default version to azure url #148

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ai21/clients/azure/ai21_azure_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ai21.clients.studio.resources.studio_chat import StudioChat, AsyncStudioChat

AzureADTokenProvider = Callable[[], str]
_DEFAULT_AZURE_VERSION = "v1"


class BaseAzureClient(ABC):
Expand Down Expand Up @@ -42,11 +43,18 @@ def _get_azure_ad_token(self) -> Optional[str]:

return None

def _add_version_to_url(self, base_url: str, api_version: str) -> str:
if api_version:
return f"{base_url}/{api_version}"

return f"{base_url}/{_DEFAULT_AZURE_VERSION}"


class AsyncAI21AzureClient(BaseAzureClient, AsyncAI21HTTPClient):
def __init__(
self,
base_url: str,
api_version: str = _DEFAULT_AZURE_VERSION,
api_key: Optional[str] = None,
azure_ad_token: str | None = None,
azure_ad_token_provider: AzureADTokenProvider | None = None,
Expand All @@ -62,6 +70,7 @@ def __init__(
raise ValueError("Must provide either api_key or azure_ad_token_provider or azure_ad_token")

headers = self._prepare_headers(headers=default_headers or {})
base_url = self._add_version_to_url(base_url=base_url, api_version=api_version)

super().__init__(
api_key=api_key,
Expand All @@ -81,6 +90,7 @@ class AI21AzureClient(BaseAzureClient, AI21HTTPClient):
def __init__(
self,
base_url: str,
api_version: str = _DEFAULT_AZURE_VERSION,
api_key: Optional[str] = None,
azure_ad_token: str | None = None,
azure_ad_token_provider: AzureADTokenProvider | None = None,
Expand All @@ -96,6 +106,7 @@ def __init__(
raise ValueError("Must provide either api_key or azure_ad_token_provider or azure_ad_token")

headers = self._prepare_headers(headers=default_headers or {})
base_url = self._add_version_to_url(base_url=base_url, api_version=api_version)

super().__init__(
api_key=api_key,
Expand Down
Loading