Skip to content

Commit f8e4e43

Browse files
authored
add ValidationException for incorrect model id, default auth_model always to key, and add docstrings for serverless, aoai, and marketplace (#35471)
1 parent b6fcdaa commit f8e4e43

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_autogen_entities/models/_patch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def _to_rest_object(self) -> RestServerlessEndpoint:
136136
properties=RestServerlessEndpointProperties(
137137
model_settings=RestModelSettings(model_id=self.model_id),
138138
),
139+
auth_mode="key", # only key is supported for now
139140
tags=self.tags,
140141
sku=RestSku(name="Consumption"),
141142
location=self.location,

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_azure_openai_deployment_operations.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818

1919
class AzureOpenAIDeploymentOperations(_ScopeDependentOperations):
20+
"""AzureOpenAIDeploymentOperations.
21+
22+
You should not instantiate this class directly. Instead, you should
23+
create an MLClient instance that instantiates it for you and
24+
attaches it as an attribute.
25+
"""
26+
2027
def __init__(
2128
self,
2229
operation_scope: OperationScope,
@@ -29,6 +36,13 @@ def __init__(
2936
self._connections_operations = connections_operations
3037

3138
def list(self, connection_name: str, **kwargs) -> Iterable[AzureOpenAIDeployment]:
39+
"""List Azure OpenAI deployments of the workspace.
40+
41+
:param connection_name: Name of the connection from which to list deployments
42+
:type connection_name: str
43+
:return: A list of Azure OpenAI deployments
44+
:rtype: ~typing.Iterable[~azure.ai.ml.entities.AzureOpenAIDeployment]
45+
"""
3246
connection = self._connections_operations.get(connection_name)
3347

3448
def _from_rest_add_connection_name(obj):

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_marketplace_subscription_operations.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424

2525

2626
class MarketplaceSubscriptionOperations(_ScopeDependentOperations):
27+
"""MarketplaceSubscriptionOperations.
28+
29+
You should not instantiate this class directly. Instead, you should
30+
create an MLClient instance that instantiates it for you and
31+
attaches it as an attribute.
32+
"""
33+
2734
def __init__(
2835
self,
2936
operation_scope: OperationScope,
@@ -38,6 +45,13 @@ def __init__(
3845
def begin_create_or_update(
3946
self, marketplace_subscription: MarketplaceSubscription, **kwargs
4047
) -> LROPoller[MarketplaceSubscription]:
48+
"""Create or update a Marketplace Subscription.
49+
50+
:param marketplace_subscription: The marketplace subscription entity.
51+
:type marketplace_subscription: ~azure.ai.ml.entities.MarketplaceSubscription
52+
:return: A poller to track the operation status
53+
:rtype: ~azure.core.polling.LROPoller[~azure.ai.ml.entities.MarketplaceSubscription]
54+
"""
4155
return self._service_client.begin_create_or_update(
4256
self._resource_group_name,
4357
self._workspace_name,
@@ -50,6 +64,13 @@ def begin_create_or_update(
5064
@experimental
5165
@monitor_with_activity(ops_logger, "MarketplaceSubscription.Get", ActivityType.PUBLICAPI)
5266
def get(self, name: str, **kwargs) -> MarketplaceSubscription:
67+
"""Get a Marketplace Subscription resource.
68+
69+
:param name: Name of the marketplace subscription.
70+
:type name: str
71+
:return: Marketplace subscription object retrieved from the service.
72+
:rtype: ~azure.ai.ml.entities.MarketplaceSubscription
73+
"""
5374
return self._service_client.get(
5475
self._resource_group_name,
5576
self._workspace_name,
@@ -61,6 +82,11 @@ def get(self, name: str, **kwargs) -> MarketplaceSubscription:
6182
@experimental
6283
@monitor_with_activity(ops_logger, "MarketplaceSubscription.List", ActivityType.PUBLICAPI)
6384
def list(self, **kwargs) -> Iterable[MarketplaceSubscription]:
85+
"""List marketplace subscriptions of the workspace.
86+
87+
:return: A list of marketplace subscriptions
88+
:rtype: ~typing.Iterable[~azure.ai.ml.entities.MarketplaceSubscription]
89+
"""
6490
return self._service_client.list(
6591
self._resource_group_name,
6692
self._workspace_name,
@@ -71,6 +97,13 @@ def list(self, **kwargs) -> Iterable[MarketplaceSubscription]:
7197
@experimental
7298
@monitor_with_activity(ops_logger, "MarketplaceSubscription.BeginDelete", ActivityType.PUBLICAPI)
7399
def begin_delete(self, name: str, **kwargs) -> LROPoller[None]:
100+
"""Delete a Marketplace Subscription.
101+
102+
:param name: Name of the marketplace subscription.
103+
:type name: str
104+
:return: A poller to track the operation status.
105+
:rtype: ~azure.core.polling.LROPoller[None]
106+
"""
74107
return self._service_client.begin_delete(
75108
self._resource_group_name,
76109
self._workspace_name,

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_serverless_endpoint_operations.py

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# pylint: disable=protected-access
66

77
from typing import Iterable
8+
import re
89

910
from azure.ai.ml.exceptions import ValidationException, ErrorTarget, ErrorCategory, ValidationErrorType
10-
from azure.ai.ml.constants._common import AzureMLResourceType
11+
from azure.ai.ml.constants._common import AzureMLResourceType, REGISTRY_VERSION_PATTERN
1112
from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
1213
from azure.ai.ml._restclient.v2024_01_01_preview import AzureMachineLearningWorkspaces as ServiceClient202401Preview
1314
from azure.ai.ml._restclient.v2024_01_01_preview.models import RegenerateEndpointKeysRequest, KeyType
@@ -30,6 +31,13 @@
3031

3132

3233
class ServerlessEndpointOperations(_ScopeDependentOperations):
34+
"""ServerlessEndpointOperations.
35+
36+
You should not instantiate this class directly. Instead, you should
37+
create an MLClient instance that instantiates it for you and
38+
attaches it as an attribute.
39+
"""
40+
3341
def __init__(
3442
self,
3543
operation_scope: OperationScope,
@@ -50,8 +58,29 @@ def _get_workspace_location(self) -> str:
5058
@experimental
5159
@monitor_with_activity(ops_logger, "ServerlessEndpoint.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
5260
def begin_create_or_update(self, endpoint: ServerlessEndpoint, **kwargs) -> LROPoller[ServerlessEndpoint]:
61+
"""Create or update a serverless endpoint.
62+
63+
:param endpoint: The serverless endpoint entity.
64+
:type endpoint: ~azure.ai.ml.entities.ServerlessEndpoint
65+
:raises ~azure.ai.ml.exceptions.ValidationException: Raised if ServerlessEndpoint cannot be
66+
successfully validated. Details will be provided in the error message.
67+
:return: A poller to track the operation status
68+
:rtype: ~azure.core.polling.LROPoller[~azure.ai.ml.entities.ServerlessEndpoint]
69+
"""
5370
if not endpoint.location:
5471
endpoint.location = self._get_workspace_location()
72+
if re.match(REGISTRY_VERSION_PATTERN, endpoint.model_id):
73+
msg = (
74+
"The given model_id {} points to a specific model version, which is not supported. "
75+
"Please provide a model_id without the version information."
76+
)
77+
raise ValidationException(
78+
message=msg.format(endpoint.model_id),
79+
no_personal_data_message="Invalid model_id given for serverless endpoint",
80+
target=ErrorTarget.SERVERLESS_ENDPOINT,
81+
error_category=ErrorCategory.USER_ERROR,
82+
error_type=ValidationErrorType.INVALID_VALUE,
83+
)
5584
return self._service_client.begin_create_or_update(
5685
self._resource_group_name,
5786
self._workspace_name,
@@ -64,6 +93,13 @@ def begin_create_or_update(self, endpoint: ServerlessEndpoint, **kwargs) -> LROP
6493
@experimental
6594
@monitor_with_activity(ops_logger, "ServerlessEndpoint.Get", ActivityType.PUBLICAPI)
6695
def get(self, name: str, **kwargs) -> ServerlessEndpoint:
96+
"""Get a Serverless Endpoint resource.
97+
98+
:param name: Name of the serverless endpoint.
99+
:type name: str
100+
:return: Serverless endpoint object retrieved from the service.
101+
:rtype: ~azure.ai.ml.entities.ServerlessEndpoint
102+
"""
67103
return self._service_client.get(
68104
self._resource_group_name,
69105
self._workspace_name,
@@ -75,6 +111,11 @@ def get(self, name: str, **kwargs) -> ServerlessEndpoint:
75111
@experimental
76112
@monitor_with_activity(ops_logger, "ServerlessEndpoint.list", ActivityType.PUBLICAPI)
77113
def list(self, **kwargs) -> Iterable[ServerlessEndpoint]:
114+
"""List serverless endpoints of the workspace.
115+
116+
:return: A list of serverless endpoints
117+
:rtype: ~typing.Iterable[~azure.ai.ml.entities.ServerlessEndpoint]
118+
"""
78119
return self._service_client.list(
79120
self._resource_group_name,
80121
self._workspace_name,
@@ -85,6 +126,13 @@ def list(self, **kwargs) -> Iterable[ServerlessEndpoint]:
85126
@experimental
86127
@monitor_with_activity(ops_logger, "ServerlessEndpoint.BeginDelete", ActivityType.PUBLICAPI)
87128
def begin_delete(self, name: str, **kwargs) -> LROPoller[None]:
129+
"""Delete a Serverless Endpoint.
130+
131+
:param name: Name of the serverless endpoint.
132+
:type name: str
133+
:return: A poller to track the operation status.
134+
:rtype: ~azure.core.polling.LROPoller[None]
135+
"""
88136
return self._service_client.begin_delete(
89137
self._resource_group_name,
90138
self._workspace_name,
@@ -95,6 +143,13 @@ def begin_delete(self, name: str, **kwargs) -> LROPoller[None]:
95143
@experimental
96144
@monitor_with_activity(ops_logger, "ServerlessEndpoint.GetKeys", ActivityType.PUBLICAPI)
97145
def get_keys(self, name: str, **kwargs) -> EndpointAuthKeys:
146+
"""Get serveless endpoint auth keys.
147+
148+
:param name: The serverless endpoint name
149+
:type name: str
150+
:return: Returns the keys of the serverless endpoint
151+
:rtype: ~azure.ai.ml.entities.EndpointAuthKeys
152+
"""
98153
return self._service_client.list_keys(
99154
self._resource_group_name,
100155
self._workspace_name,
@@ -111,7 +166,18 @@ def begin_regenerate_keys(
111166
*,
112167
key_type: str = EndpointKeyType.PRIMARY_KEY_TYPE,
113168
**kwargs,
114-
) -> LROPoller[None]:
169+
) -> LROPoller[EndpointAuthKeys]:
170+
"""Regenerate keys for a serverless endpoint.
171+
172+
:param name: The endpoint name.
173+
:type name: str
174+
:keyword key_type: One of "primary", "secondary". Defaults to "primary".
175+
:paramtype key_type: str
176+
:raises ~azure.ai.ml.exceptions.ValidationException: Raised if key_type is not "primary"
177+
or "secondary"
178+
:return: A poller to track the operation status.
179+
:rtype: ~azure.core.polling.LROPoller[EndpointAuthKeys]
180+
"""
115181
keys = self.get_keys(
116182
name=name,
117183
)

0 commit comments

Comments
 (0)