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

Miscellaneous updates #37852

Merged
merged 12 commits into from
Oct 11, 2024
12 changes: 6 additions & 6 deletions sdk/ai/azure-ai-client/azure/ai/client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class AzureAIClient:
:type subscription_id: str
:param resource_group_name: The name of the Azure Resource Group. Required.
:type resource_group_name: str
:param workspace_name: The name of the Azure AI Studio hub. Required.
:type workspace_name: str
:param project_name: The Azure AI Studio project name. Required.
:type project_name: str
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand All @@ -56,16 +56,16 @@ def __init__(
endpoint: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
project_name: str,
credential: "TokenCredential",
**kwargs: Any
) -> None:
_endpoint = "{endpoint}/{subscriptionId}/{resourceGroupName}/{workspaceName}"
_endpoint = "{endpoint}/{subscriptionId}/{resourceGroupName}/{projectName}"
self._config = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
**kwargs
)
Expand Down Expand Up @@ -120,7 +120,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
"resourceGroupName": self._serialize.url(
"self._config.resource_group_name", self._config.resource_group_name, "str"
),
"workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
"projectName": self._serialize.url("self._config.project_name", self._config.project_name, "str"),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
Expand Down
12 changes: 6 additions & 6 deletions sdk/ai/azure-ai-client/azure/ai/client/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class AzureAIClientConfiguration: # pylint: disable=too-many-instance-attribute
:type subscription_id: str
:param resource_group_name: The name of the Azure Resource Group. Required.
:type resource_group_name: str
:param workspace_name: The name of the Azure AI Studio hub. Required.
:type workspace_name: str
:param project_name: The Azure AI Studio project name. Required.
:type project_name: str
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand All @@ -47,7 +47,7 @@ def __init__(
endpoint: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
project_name: str,
credential: "TokenCredential",
**kwargs: Any
) -> None:
Expand All @@ -59,15 +59,15 @@ def __init__(
raise ValueError("Parameter 'subscription_id' must not be None.")
if resource_group_name is None:
raise ValueError("Parameter 'resource_group_name' must not be None.")
if workspace_name is None:
raise ValueError("Parameter 'workspace_name' must not be None.")
if project_name is None:
raise ValueError("Parameter 'project_name' must not be None.")
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")

self.endpoint = endpoint
self.subscription_id = subscription_id
self.resource_group_name = resource_group_name
self.workspace_name = workspace_name
self.project_name = project_name
self.credential = credential
self.api_version = api_version
self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"])
Expand Down
33 changes: 16 additions & 17 deletions sdk/ai/azure-ai-client/azure/ai/client/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
endpoint: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
project_name: str,
credential: "TokenCredential",
**kwargs: Any,
) -> None:
Expand All @@ -36,8 +36,8 @@ def __init__(
raise ValueError("subscription_id ID is required")
if not resource_group_name:
raise ValueError("resource_group_name is required")
if not workspace_name:
raise ValueError("workspace_name is required")
if not project_name:
raise ValueError("project_name is required")
if not credential:
raise ValueError("Credential is required")
if "api_version" in kwargs:
Expand All @@ -50,12 +50,12 @@ def __init__(
kwargs3 = kwargs.copy()

# For Endpoints operations (enumerating connections, getting SAS tokens)
_endpoint1 = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}" # pylint: disable=line-too-long
_endpoint1 = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
self._config1 = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
api_version="2024-07-01-preview",
credential_scopes=["https://management.azure.com"],
Expand All @@ -81,12 +81,12 @@ def __init__(
self._client1 = PipelineClient(base_url=_endpoint1, policies=_policies1, **kwargs1)

# For Agents operations
_endpoint2 = f"{endpoint}/agents/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}" # pylint: disable=line-too-long
_endpoint2 = f"{endpoint}/agents/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
self._config2 = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
api_version="2024-07-01-preview", # TODO: Update me
credential_scopes=["https://ml.azure.com"],
Expand All @@ -112,12 +112,12 @@ def __init__(
self._client2 = PipelineClient(base_url=_endpoint2, policies=_policies2, **kwargs2)

# For Cloud Evaluations operations
_endpoint3 = f"{endpoint}/raisvc/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}" # pylint: disable=line-too-long
_endpoint3 = f"{endpoint}/raisvc/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
self._config3 = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
api_version="2024-07-01-preview", # TODO: Update me
credential_scopes=["https://ml.azure.com"], # TODO: Update once service changes are ready
Expand Down Expand Up @@ -167,24 +167,23 @@ def __exit__(self, *exc_details: Any) -> None:
self._client2.__exit__(*exc_details)
self._client3.__exit__(*exc_details)


@classmethod
def from_connection_string(cls, connection: str, credential: "TokenCredential", **kwargs) -> "AzureAIClient":
def from_connection_string(cls, conn_str: str, credential: "TokenCredential", **kwargs) -> "AzureAIClient":
"""
Create an AzureAIClient from a connection string.

:param connection: The connection string, copied from your AI Studio project.
:param conn_str: The connection string, copied from your AI Studio project.
"""
if not connection:
if not conn_str:
raise ValueError("Connection string is required")
parts = connection.split(";")
parts = conn_str.split(";")
if len(parts) != 4:
raise ValueError("Invalid connection string format")
endpoint = parts[0]
endpoint = "https://" + parts[0]
subscription_id = parts[1]
resource_group_name = parts[2]
workspace_name = parts[3]
return cls(endpoint, subscription_id, resource_group_name, workspace_name, credential, **kwargs)
project_name = parts[3]
return cls(endpoint, subscription_id, resource_group_name, project_name, credential, **kwargs)


__all__: List[str] = [
Expand Down
12 changes: 6 additions & 6 deletions sdk/ai/azure-ai-client/azure/ai/client/aio/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class AzureAIClient:
:type subscription_id: str
:param resource_group_name: The name of the Azure Resource Group. Required.
:type resource_group_name: str
:param workspace_name: The name of the Azure AI Studio hub. Required.
:type workspace_name: str
:param project_name: The Azure AI Studio project name. Required.
:type project_name: str
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand All @@ -56,16 +56,16 @@ def __init__(
endpoint: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
project_name: str,
credential: "AsyncTokenCredential",
**kwargs: Any
) -> None:
_endpoint = "{endpoint}/{subscriptionId}/{resourceGroupName}/{workspaceName}"
_endpoint = "{endpoint}/{subscriptionId}/{resourceGroupName}/{projectName}"
self._config = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
**kwargs
)
Expand Down Expand Up @@ -122,7 +122,7 @@ def send_request(
"resourceGroupName": self._serialize.url(
"self._config.resource_group_name", self._config.resource_group_name, "str"
),
"workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
"projectName": self._serialize.url("self._config.project_name", self._config.project_name, "str"),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
Expand Down
12 changes: 6 additions & 6 deletions sdk/ai/azure-ai-client/azure/ai/client/aio/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class AzureAIClientConfiguration: # pylint: disable=too-many-instance-attribute
:type subscription_id: str
:param resource_group_name: The name of the Azure Resource Group. Required.
:type resource_group_name: str
:param workspace_name: The name of the Azure AI Studio hub. Required.
:type workspace_name: str
:param project_name: The Azure AI Studio project name. Required.
:type project_name: str
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand All @@ -47,7 +47,7 @@ def __init__(
endpoint: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
project_name: str,
credential: "AsyncTokenCredential",
**kwargs: Any
) -> None:
Expand All @@ -59,15 +59,15 @@ def __init__(
raise ValueError("Parameter 'subscription_id' must not be None.")
if resource_group_name is None:
raise ValueError("Parameter 'resource_group_name' must not be None.")
if workspace_name is None:
raise ValueError("Parameter 'workspace_name' must not be None.")
if project_name is None:
raise ValueError("Parameter 'project_name' must not be None.")
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")

self.endpoint = endpoint
self.subscription_id = subscription_id
self.resource_group_name = resource_group_name
self.workspace_name = workspace_name
self.project_name = project_name
self.credential = credential
self.api_version = api_version
self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"])
Expand Down
33 changes: 17 additions & 16 deletions sdk/ai/azure-ai-client/azure/ai/client/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
endpoint: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
project_name: str,
credential: "AsyncTokenCredential",
**kwargs: Any,
) -> None:
Expand All @@ -36,8 +36,8 @@ def __init__(
raise ValueError("subscription_id ID is required")
if not resource_group_name:
raise ValueError("resource_group_name is required")
if not workspace_name:
raise ValueError("workspace_name is required")
if not project_name:
raise ValueError("project_name is required")
if not credential:
raise ValueError("Credential is required")
if "api_version" in kwargs:
Expand All @@ -50,12 +50,12 @@ def __init__(
kwargs3 = kwargs.copy()

# For Endpoints operations (enumerating connections, getting SAS tokens)
_endpoint1 = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}" # pylint: disable=line-too-long
_endpoint1 = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
self._config1 = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
api_version="2024-07-01-preview",
credential_scopes=["https://management.azure.com"],
Expand All @@ -81,12 +81,12 @@ def __init__(
self._client1 = AsyncPipelineClient(base_url=_endpoint1, policies=_policies1, **kwargs1)

# For Agents operations
_endpoint2 = f"{endpoint}/agents/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}" # pylint: disable=line-too-long
_endpoint2 = f"{endpoint}/agents/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
self._config2 = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
api_version="2024-07-01-preview", # TODO: Update me
credential_scopes=["https://ml.azure.com"],
Expand All @@ -112,12 +112,12 @@ def __init__(
self._client2 = AsyncPipelineClient(base_url=_endpoint2, policies=_policies2, **kwargs2)

# For Cloud Evaluations operations
_endpoint3 = f"{endpoint}/raisvc/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}" # pylint: disable=line-too-long
_endpoint3 = f"{endpoint}/raisvc/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
self._config3 = AzureAIClientConfiguration(
endpoint=endpoint,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
project_name=project_name,
credential=credential,
api_version="2024-07-01-preview", # TODO: Update me
credential_scopes=["https://management.azure.com"], # TODO: Update once service changes are ready
Expand Down Expand Up @@ -168,22 +168,23 @@ async def __aexit__(self, *exc_details: Any) -> None:
await self._client3.__aexit__(*exc_details)

@classmethod
def from_connection_string(cls, connection: str, credential: "AzureTokenCredential", **kwargs) -> "AzureAIClient":
def from_connection_string(cls, conn_str: str, credential: "AsyncTokenCredential", **kwargs) -> "AzureAIClient":
"""
Create an asynchronous AzureAIClient from a connection string.

:param connection: The connection string, copied from your AI Studio project.
:param conn_str: The connection string, copied from your AI Studio project.
"""
if not connection:
if not conn_str:
raise ValueError("Connection string is required")
parts = connection.split(";")
parts = conn_str.split(";")
if len(parts) != 4:
raise ValueError("Invalid connection string format")
endpoint = parts[0]
endpoint = "https://" + parts[0]
subscription_id = parts[1]
resource_group_name = parts[2]
workspace_name = parts[3]
return cls(endpoint, subscription_id, resource_group_name, workspace_name, credential, **kwargs)
project_name = parts[3]
return cls(endpoint, subscription_id, resource_group_name, project_name, credential, **kwargs)


__all__: List[str] = [
"AzureAIClient",
Expand Down
Loading