@@ -31,11 +31,21 @@ class AzureAuth(Authenticator):
3131 _token_scope : str
3232
3333 def __init__ (self , token_scope : str , tenant_id : str = "" ):
34+ """
35+ Initialize Azure authentication.
36+
37+ Args:
38+ token_scope (str): The token scope for authentication.
39+ tenant_id (str, optional): The tenant ID. Defaults to "".
40+ """
3441 self ._tenant_id = tenant_id
3542 self ._token_scope = token_scope
3643 self ._set_default_token ()
3744
3845 def _set_default_token (self ) -> None :
46+ """
47+ Set up default Azure credentials and retrieve access token.
48+ """
3949 self .azure_creds = DefaultAzureCredential ()
4050 self .access_token = self .azure_creds .get_token (self ._token_scope )
4151 self .token = self .access_token .token
@@ -45,8 +55,7 @@ def refresh_token(self) -> str:
4555 Refresh the access token if it is expired.
4656
4757 Returns:
48- A token
49-
58+ str: A token
5059 """
5160 curr_epoch_time_in_ms = int (time .time ()) * 1_000
5261 access_token_epoch_expiration_time_in_ms = int (self .access_token .expires_on ) * 1_000
@@ -63,13 +72,23 @@ def get_token(self) -> str:
6372 """
6473 Get the current token.
6574
66- Returns: The current token
67-
75+ Returns:
76+ str: current token
6877 """
6978 return self .token
7079
7180
7281def get_access_token_from_azure_cli (* , scope : str , tenant_id : str = "" ):
82+ """
83+ Get access token from Azure CLI.
84+
85+ Args:
86+ scope (str): The scope to request.
87+ tenant_id (str, optional): The tenant ID. Defaults to "".
88+
89+ Returns:
90+ str: The access token.
91+ """
7392 try :
7493 credential = AzureCliCredential (tenant_id = tenant_id )
7594 token = credential .get_token (scope )
@@ -90,7 +109,7 @@ def get_access_token_from_azure_msi(*, client_id: str, scope: str):
90109 scope (str): The scope to request
91110
92111 Returns:
93- Authentication token
112+ str: Authentication token
94113 """
95114 try :
96115 credential = ManagedIdentityCredential (client_id = client_id )
@@ -103,15 +122,15 @@ def get_access_token_from_azure_msi(*, client_id: str, scope: str):
103122
104123def get_access_token_from_msa_public_client (* , client_id : str , scope : str ):
105124 """
106- Uses MSA account to connect to an AOAI endpoint via interactive login. A browser window
125+ Use MSA account to connect to an AOAI endpoint via interactive login. A browser window
107126 will open and ask for login credentials.
108127
109128 Args:
110129 client_id (str): The client ID of the service
111130 scope (str): The scope to request
112131
113132 Returns:
114- Authentication token
133+ str: Authentication token
115134 """
116135 try :
117136 app = msal .PublicClientApplication (client_id )
@@ -124,11 +143,14 @@ def get_access_token_from_msa_public_client(*, client_id: str, scope: str):
124143
125144def get_access_token_from_interactive_login (scope : str ) -> str :
126145 """
127- Connects to an OpenAI endpoint with an interactive login from Azure. A browser window will
146+ Connect to an OpenAI endpoint with an interactive login from Azure. A browser window will
128147 open and ask for login credentials. The token will be scoped for Azure Cognitive services.
129148
149+ Args:
150+ scope (str): The scope to request
151+
130152 Returns:
131- Authentication token
153+ str: Authentication token
132154 """
133155 try :
134156 token_provider = get_bearer_token_provider (InteractiveBrowserCredential (), scope )
@@ -143,7 +165,7 @@ def get_token_provider_from_default_azure_credential(scope: str) -> Callable[[],
143165 Connect to an AOAI endpoint via default Azure credential.
144166
145167 Returns:
146- Authentication token provider
168+ Callable[[], str]: Authentication token provider
147169 """
148170 try :
149171 token_provider = get_bearer_token_provider (DefaultAzureCredential (), scope )
@@ -161,7 +183,7 @@ def get_default_scope(endpoint: str) -> str:
161183 endpoint (str): The endpoint to get the scope for.
162184
163185 Returns:
164- The default scope for the given endpoint.
186+ str: The default scope for the given endpoint.
165187 """
166188 try :
167189 parsed_uri = urlparse (endpoint )
@@ -184,7 +206,7 @@ def get_speech_config(resource_id: Union[str, None], key: Union[str, None], regi
184206 region (str): The region to get the token for.
185207
186208 Returns:
187- The speech config based on passed in args
209+ speechsdk.SpeechConfig: The speech config based on passed in args
188210
189211 Raises:
190212 ModuleNotFoundError: If azure.cognitiveservices.speech is not installed.
@@ -223,6 +245,9 @@ def get_speech_config_from_default_azure_credential(resource_id: str, region: st
223245
224246 Returns:
225247 The speech config for the given resource ID and region.
248+
249+ Raises:
250+ ModuleNotFoundError: If azure.cognitiveservices.speech is not installed.
226251 """
227252 try :
228253 import azure .cognitiveservices .speech as speechsdk # noqa: F811
0 commit comments