Skip to content

Commit caf2f97

Browse files
authored
December Connections changes to AI SDK (#33486)
* ai changes * follow ups * rename ai reosurce field * remove api key conn * disabled connection tests * assets for ai resoruce test * regen assets * undo assets change * change custom_keys to custom * re-add skips
1 parent 8acb041 commit caf2f97

File tree

11 files changed

+330
-43
lines changed

11 files changed

+330
-43
lines changed

sdk/ai/azure-ai-resources/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ml/azure-ai-ml",
5-
"Tag": "python/ml/azure-ai-ml_f032d7288a"
5+
"Tag": "python/ml/azure-ai-ml_77079b021d"
66
}

sdk/ai/azure-ai-resources/azure/ai/resources/client/_ai_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(
118118
# TODO add scoping to allow connections to:
119119
# - Create project-scoped connections
120120
# For now, connections are AI resource-scoped.
121-
self._connections = ConnectionOperations(self._ai_resource_ml_client, **app_insights_handler_kwargs)
121+
self._connections = ConnectionOperations(resource_ml_client=self._ai_resource_ml_client, project_ml_client=self._ml_client, **app_insights_handler_kwargs)
122122
self._mlindexes = MLIndexOperations(self._ml_client, **app_insights_handler_kwargs)
123123
self._ai_resources = AIResourceOperations(self._ml_client, **app_insights_handler_kwargs)
124124
self._deployments = DeploymentOperations(self._ml_client, self._connections, **app_insights_handler_kwargs)

sdk/ai/azure-ai-resources/azure/ai/resources/constants/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
66

7-
from ._common import AssetTypes, IndexInputType, IndexType
7+
from ._common import AssetTypes, IndexInputType, IndexType, OperationScope
88

99
__all__ = [
1010
"AssetTypes",
1111
"IndexInputType",
1212
"IndexType",
13+
"OperationScope",
1314
]

sdk/ai/azure-ai-resources/azure/ai/resources/constants/_common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ class IndexInputType(object):
2828
class IndexType(object):
2929
ACS = "acs"
3030
FAISS = "faiss"
31+
32+
class OperationScope:
33+
"""
34+
Some AI Client Operations can be applied to either the client's AI resource,
35+
or its project. For such operations, this is used to determine that scope.
36+
"""
37+
AI_RESOURCE = "ai_resource"
38+
PROJECT = "project"

sdk/ai/azure-ai-resources/azure/ai/resources/entities/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
AzureOpenAIConnection,
1212
AzureAISearchConnection,
1313
AzureAIServiceConnection,
14+
GitHubConnection,
15+
CustomConnection,
1416
)
1517
from .mlindex import Index
1618
from .project import Project
@@ -27,5 +29,7 @@
2729
"AIResource",
2830
"Data",
2931
"AzureOpenAIModelConfiguration",
32+
"GitHubConnection",
33+
"CustomConnection",
3034
]
3135

sdk/ai/azure-ai-resources/azure/ai/resources/entities/ai_resource.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(
3131
public_network_access: Optional[str] = None,
3232
identity: Optional[IdentityConfiguration] = None,
3333
primary_user_assigned_identity: Optional[str] = None,
34-
default_workspace_resource_group: Optional[str] = None, # Unpacked WorkspaceHubConfig field
34+
default_project_resource_group: Optional[str] = None, # Unpacked WorkspaceHubConfig field
3535
**kwargs,
3636
):
3737
self._workspace_hub = WorkspaceHub(
@@ -49,7 +49,7 @@ def __init__(
4949
primary_user_assigned_identity=primary_user_assigned_identity,
5050
workspace_hub_config=WorkspaceHubConfig(
5151
additional_workspace_storage_accounts=[],
52-
default_workspace_resource_group=default_workspace_resource_group,
52+
default_workspace_resource_group=default_project_resource_group,
5353
),
5454
**kwargs,
5555
)
@@ -70,7 +70,15 @@ def _from_v2_workspace_hub(cls, workspace_hub: WorkspaceHub) -> "AIResource":
7070
resource._workspace_hub = workspace_hub
7171
return resource
7272

73-
# TODO test all accessors/setters
73+
@property
74+
def id(self) -> str:
75+
"""The read-only id of the resource. Set by the backend.
76+
77+
:return: ID of the resource.
78+
:rtype: str
79+
"""
80+
return self._workspace_hub.id
81+
7482
@property
7583
def name(self) -> str:
7684
"""The name of the resource.
@@ -332,17 +340,17 @@ def enable_data_isolation(self) -> str:
332340
return self._workspace_hub.enable_data_isolation
333341

334342
@property
335-
def default_workspace_resource_group(self) -> str:
336-
"""The default_workspace_resource_group of the resource.
343+
def default_project_resource_group(self) -> str:
344+
"""The default_project_resource_group of the resource.
337345
338346
:return: Name of the resource.
339347
:rtype: str
340348
"""
341349
return self._workspace_hub.workspace_hub_config.default_workspace_resource_group
342350

343-
@default_workspace_resource_group.setter
344-
def default_workspace_resource_group(self, value: str):
345-
"""Set the default_workspace_resource_group of the resource.
351+
@default_project_resource_group.setter
352+
def default_project_resource_group(self, value: str):
353+
"""Set the default_project_resource_group of the resource.
346354
347355
:param value: The new type to assign to the resource.
348356
:type value: str

sdk/ai/azure-ai-resources/azure/ai/resources/entities/base_connection.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class BaseConnection:
3131
:type tags: dict
3232
:param id: The connection's resource id.
3333
:type id: str
34+
:param is_shared: For connections created for a project, this determines if the connection
35+
is shared amongst other connections with that project's parent AI resource.
36+
Defaults to true.
37+
:type is_shared: bool
3438
"""
3539

3640
def __init__(
@@ -39,6 +43,7 @@ def __init__(
3943
target: str,
4044
type: str, # pylint: disable=redefined-builtin
4145
credentials: ApiKeyConfiguration,
46+
is_shared: bool=True,
4247
**kwargs,
4348
):
4449
# Sneaky short-circuit to allow direct v2 WS conn injection without any
@@ -51,6 +56,7 @@ def __init__(
5156
target=target,
5257
type=type,
5358
credentials=credentials,
59+
is_shared=is_shared,
5460
**kwargs,
5561
)
5662

@@ -228,6 +234,26 @@ def metadata(self, value: Dict[str, Any]):
228234
return
229235
self._workspace_connection.tags = value
230236

237+
@property
238+
def is_shared(self) -> bool:
239+
"""Get the Boolean describing if this connection is shared
240+
amongst its cohort within a workspace hub. Only applicable for connections
241+
that are project-scoped on creation.
242+
:rtype: bool
243+
"""
244+
return self._workspace_connection.is_shared
245+
246+
@is_shared.setter
247+
def is_shared(self, value: bool):
248+
"""The is_shared determines if this connection is shared amongst other
249+
lean workspaces within its parent workspace hub. Only applicable for connections
250+
that are project-scoped on creation.
251+
:type value: bool
252+
"""
253+
if not value:
254+
return
255+
self._workspace_connection.is_shared = value
256+
231257
def set_current_environment(self, credential: Optional[TokenCredential] = None):
232258
"""Sets the current environment to use the connection. To use AAD auth for AzureOpenAI connetion, pass in a credential object.
233259
Only certain types of connections make use of this function. Those that don't will raise an error if this is called.

sdk/ai/azure-ai-resources/azure/ai/resources/entities/connection_subtypes.py

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ class AzureOpenAIConnection(BaseConnection):
2626
:type target: str
2727
:param tags: Tag dictionary. Tags can be added, removed, and updated.
2828
:type tags: dict
29-
:param credentials: The credentials for authenticating to the external resource.
29+
:param credentials: The credentials for authenticating the external resource.
3030
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
3131
:param api_version: The api version that this connection was created for.
3232
:type api_version: Optional[str]
3333
:param api_type: The api type that this connection was created for. Defaults to "Azure" and currently rarely changes.
3434
:type api_type: str
35+
:param is_shared: For connections created for a project, this determines if the connection
36+
is shared amongst other connections with that project's parent AI resource.
37+
Defaults to true.
38+
:type is_shared: bool
3539
"""
3640

3741
def __init__(
@@ -136,10 +140,14 @@ class AzureAISearchConnection(BaseConnection):
136140
:type target: str
137141
:param tags: Tag dictionary. Tags can be added, removed, and updated.
138142
:type tags: dict
139-
:param credentials: The credentials for authenticating to the external resource.
143+
:param credentials: The credentials for authenticating the external resource.
140144
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
141145
:param api_version: The api version that this connection was created for. Only applies to certain connection types.
142146
:type api_version: Optional[str]
147+
:param is_shared: For connections created for a project, this determines if the connection
148+
is shared amongst other connections with that project's parent AI resource.
149+
Defaults to true.
150+
:type is_shared: bool
143151
"""
144152

145153
def __init__(
@@ -195,21 +203,25 @@ def set_current_environment(self, credential: Optional[TokenCredential] = None):
195203
class AzureAIServiceConnection(BaseConnection):
196204
"""A Connection for an Azure Cognitive Service. Note: This object usually shouldn't be created manually by users.
197205
To get the default AzureOpenAIConnection for an AI Resource, use an AIClient object to call the
198-
'get_default_aoai_connection' function.
206+
'get_default_content_safety_connection' function.
199207
200208
:param name: Name of the connection.
201209
:type name: str
202210
:param target: The URL or ARM resource ID of the external resource.
203211
:type target: str
204212
:param tags: Tag dictionary. Tags can be added, removed, and updated.
205213
:type tags: dict
206-
:param credentials: The credentials for authenticating to the external resource.
214+
:param credentials: The credentials for authenticating the external resource.
207215
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
208216
:param api_version: The api version that this connection was created for.
209217
:type api_version: Optional[str]
210218
:param kind: The kind of ai service that this connection points to. Valid inputs include:
211219
"AzureOpenAI", "ContentSafety", and "Speech"
212220
:type kind: str
221+
:param is_shared: For connections created for a project, this determines if the connection
222+
is shared amongst other connections with that project's parent AI resource.
223+
Defaults to true.
224+
:type is_shared: bool
213225
"""
214226

215227
def __init__(
@@ -263,3 +275,56 @@ def kind(self, value: str) -> str:
263275
:rtype: str
264276
"""
265277
self._workspace_connection.tags[CONNECTION_KIND_KEY] = value
278+
279+
class GitHubConnection(BaseConnection):
280+
"""A Connection to GitHub.
281+
282+
:param name: Name of the connection.
283+
:type name: str
284+
:param target: The URL or ARM resource ID of the external resource.
285+
:type target: str
286+
:param tags: Tag dictionary. Tags can be added, removed, and updated.
287+
:type tags: dict
288+
:param credentials: The credentials for authenticating the external resource.
289+
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
290+
:param is_shared: For connections created for a project, this determines if the connection
291+
is shared amongst other connections with that project's parent AI resource.
292+
Defaults to true.
293+
:type is_shared: bool
294+
"""
295+
296+
def __init__(
297+
self,
298+
*,
299+
target: str,
300+
credentials: ApiKeyConfiguration,
301+
**kwargs,
302+
):
303+
kwargs.pop("type", None) # make sure we never somehow use wrong type
304+
super().__init__(target=target, type="git", credentials=credentials, **kwargs)
305+
306+
class CustomConnection(BaseConnection):
307+
"""A Connection to system that's not encapsulated by other connection types.
308+
309+
:param name: Name of the connection.
310+
:type name: str
311+
:param target: The URL or ARM resource ID of the external resource.
312+
:type target: str
313+
:param tags: Tag dictionary. Tags can be added, removed, and updated.
314+
:type tags: dict
315+
:param credentials: The credentials for authenticating the external resource.
316+
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
317+
:param is_shared: For connections created for a project, this determines if the connection
318+
is shared amongst other connections with that project's parent AI resource.
319+
Defaults to true.
320+
:type is_shared: bool
321+
"""
322+
def __init__(
323+
self,
324+
*,
325+
target: str,
326+
credentials: ApiKeyConfiguration,
327+
**kwargs,
328+
):
329+
kwargs.pop("type", None) # make sure we never somehow use wrong type
330+
super().__init__(target=target, type="custom", credentials=credentials, **kwargs)

0 commit comments

Comments
 (0)