Skip to content

Commit a431493

Browse files
authored
Apiview fixes may 2024 (#35469)
* re-add load_workspace_connection * ai services create arg * pylint and such * apiview adjustments * run black again * change connection kind name * use new assets for connections * fix project arm template * comments * remove ai_serives from workspace create * run-black
1 parent 2b43110 commit a431493

File tree

7 files changed

+57
-8
lines changed

7 files changed

+57
-8
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
load_registry,
3939
load_serverless_endpoint,
4040
load_workspace,
41+
load_workspace_connection,
4142
)
4243

4344
module_logger = logging.getLogger(__name__)
@@ -72,6 +73,7 @@
7273
"load_workspace",
7374
"load_registry",
7475
"load_connection",
76+
"load_workspace_connection",
7577
"load_model_package",
7678
"load_marketplace_subscription",
7779
"load_serverless_endpoint",

sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ def feature_store_entities(self) -> FeatureStoreEntityOperations:
933933
return self._featurestoreentities
934934

935935
@property
936+
@experimental
936937
def connections(self) -> ConnectionsOperations:
937938
"""A collection of connection related operations.
938939

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_load_functions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ def load_batch_endpoint(
803803
return cast(BatchEndpoint, load_common(BatchEndpoint, source, relative_origin, params_override, **kwargs))
804804

805805

806+
@experimental
806807
def load_connection(
807808
source: Union[str, PathLike, IO[AnyStr]],
808809
*,
@@ -842,7 +843,7 @@ def load_workspace_connection(
842843
relative_origin: Optional[str] = None,
843844
**kwargs: Any,
844845
) -> Connection:
845-
"""Construct a connection object from yaml file.
846+
"""Deprecated - use 'load_connection' instead. Construct a connection object from yaml file.
846847
847848
:param source: The local yaml source of a connection object. Must be either a
848849
path to a local file, or an already-open file.
@@ -861,7 +862,10 @@ def load_workspace_connection(
861862
:rtype: Connection
862863
863864
"""
864-
return load_workspace_connection(source, relative_origin=relative_origin, **kwargs)
865+
warnings.warn(
866+
"the 'load_workspace_connection' function is deprecated. Use 'load_connection' instead.", DeprecationWarning
867+
)
868+
return load_connection(source, relative_origin=relative_origin, **kwargs)
865869

866870

867871
def load_schedule(

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_workspace/connections/connection_subtypes.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ class AzureOpenAIConnection(ApiOrAadConnection):
327327
def __init__(
328328
self,
329329
*,
330+
azure_endpoint: str,
331+
api_key: Optional[str] = None,
330332
api_version: Optional[str] = None,
331333
api_type: str = "Azure", # Required API input, hidden to allow for rare overrides
332334
open_ai_resource_id: Optional[str] = None,
@@ -338,6 +340,8 @@ def __init__(
338340
if open_ai_resource_id is None and from_rest_resource_id is not None:
339341
open_ai_resource_id = from_rest_resource_id
340342
super().__init__(
343+
azure_endpoint=azure_endpoint,
344+
api_key=api_key,
341345
type=camel_to_snake(ConnectionCategory.AZURE_OPEN_AI),
342346
from_child=True,
343347
**kwargs,
@@ -407,6 +411,7 @@ def open_ai_resource_id(self, value: Optional[str]) -> None:
407411
self.tags[CONNECTION_RESOURCE_ID_KEY] = value
408412

409413

414+
@experimental
410415
class AzureAIServicesConnection(ApiOrAadConnection):
411416
"""A Connection geared towards Azure AI services.
412417
@@ -426,11 +431,15 @@ class AzureAIServicesConnection(ApiOrAadConnection):
426431
def __init__(
427432
self,
428433
*,
434+
endpoint: str,
435+
api_key: Optional[str] = None,
429436
ai_services_resource_id: str,
430437
**kwargs: Any,
431438
):
432439
kwargs.pop("type", None) # make sure we never somehow use wrong type
433440
super().__init__(
441+
endpoint=endpoint,
442+
api_key=api_key,
434443
type=ConnectionTypes.AZURE_AI_SERVICES,
435444
from_child=True,
436445
**kwargs,
@@ -488,11 +497,16 @@ class AzureAISearchConnection(ApiOrAadConnection):
488497

489498
def __init__(
490499
self,
500+
*,
501+
endpoint: str,
502+
api_key: Optional[str] = None,
491503
**kwargs: Any,
492504
):
493505
kwargs.pop("type", None) # make sure we never somehow use wrong type
494506

495507
super().__init__(
508+
endpoint=endpoint,
509+
api_key=api_key,
496510
type=ConnectionTypes.AZURE_SEARCH,
497511
from_child=True,
498512
**kwargs,
@@ -520,10 +534,15 @@ class AzureContentSafetyConnection(ApiOrAadConnection):
520534

521535
def __init__(
522536
self,
537+
*,
538+
endpoint: str,
539+
api_key: Optional[str] = None,
523540
**kwargs: Any,
524541
):
525542
kwargs.pop("type", None) # make sure we never somehow use wrong type
526543
super().__init__(
544+
endpoint=endpoint,
545+
api_key=api_key,
527546
type=ConnectionTypes.AZURE_CONTENT_SAFETY,
528547
from_child=True,
529548
**kwargs,
@@ -548,7 +567,7 @@ class AzureSpeechServicesConnection(ApiOrAadConnection):
548567
:type endpoint: str
549568
:param api_key: The api key to connect to the azure endpoint.
550569
If unset, tries to use the user's Entra ID as credentials instead.
551-
:type api_key: str
570+
:type api_key: Optional[str]
552571
:param tags: Tag dictionary. Tags can be added, removed, and updated.
553572
:type tags: dict
554573
"""
@@ -559,11 +578,13 @@ def __init__(
559578
self,
560579
*,
561580
endpoint: str,
581+
api_key: Optional[str] = None,
562582
**kwargs: Any,
563583
):
564584
kwargs.pop("type", None) # make sure we never somehow use wrong type
565585
super().__init__(
566586
endpoint=endpoint,
587+
api_key=api_key,
567588
type=ConnectionTypes.AZURE_SPEECH_SERVICES,
568589
from_child=True,
569590
**kwargs,
@@ -587,7 +608,7 @@ class APIKeyConnection(ApiOrAadConnection):
587608
:param api_base: The URL to target with this connection.
588609
:type api_base: str
589610
:param api_key: The API key needed to connect to the api_base.
590-
:type api_key: str
611+
:type api_key: Optional[str]
591612
:param tags: Tag dictionary. Tags can be added, removed, and updated.
592613
:type tags: dict
593614
"""
@@ -596,11 +617,13 @@ def __init__(
596617
self,
597618
*,
598619
api_base: str,
620+
api_key: Optional[str] = None,
599621
**kwargs,
600622
):
601623
kwargs.pop("type", None) # make sure we never somehow use wrong type
602624
super().__init__(
603625
api_base=api_base,
626+
api_key=api_key,
604627
type=camel_to_snake(ConnectionCategory.API_KEY),
605628
allow_entra=False,
606629
from_child=True,
@@ -620,18 +643,21 @@ class OpenAIConnection(ApiOrAadConnection):
620643
:param name: Name of the connection.
621644
:type name: str
622645
:param api_key: The API key needed to connect to the Open AI.
623-
:type api_key: str
646+
:type api_key: Optional[str]
624647
:param tags: Tag dictionary. Tags can be added, removed, and updated.
625648
:type tags: dict
626649
"""
627650

628651
def __init__(
629652
self,
653+
*,
654+
api_key: Optional[str] = None,
630655
**kwargs,
631656
):
632657
kwargs.pop("type", None) # make sure we never somehow use wrong type
633658
super().__init__(
634659
type=ConnectionCategory.Open_AI,
660+
api_key=api_key,
635661
allow_entra=False,
636662
from_child=True,
637663
**kwargs,
@@ -649,18 +675,21 @@ class SerpConnection(ApiOrAadConnection):
649675
:param name: Name of the connection.
650676
:type name: str
651677
:param api_key: The API key needed to connect to the Open AI.
652-
:type api_key: str
678+
:type api_key: Optional[str]
653679
:param tags: Tag dictionary. Tags can be added, removed, and updated.
654680
:type tags: dict
655681
"""
656682

657683
def __init__(
658684
self,
685+
*,
686+
api_key: Optional[str] = None,
659687
**kwargs,
660688
):
661689
kwargs.pop("type", None) # make sure we never somehow use wrong type
662690
super().__init__(
663691
type=ConnectionCategory.SERP,
692+
api_key=api_key,
664693
allow_entra=False,
665694
from_child=True,
666695
**kwargs,
@@ -680,18 +709,23 @@ class ServerlessConnection(ApiOrAadConnection):
680709
:param endpoint: The serverless endpoint.
681710
:type endpoint: str
682711
:param api_key: The API key needed to connect to the endpoint.
683-
:type api_key: str
712+
:type api_key: Optional[str]
684713
:param tags: Tag dictionary. Tags can be added, removed, and updated.
685714
:type tags: dict
686715
"""
687716

688717
def __init__(
689718
self,
719+
*,
720+
endpoint: str,
721+
api_key: Optional[str] = None,
690722
**kwargs,
691723
):
692724
kwargs.pop("type", None) # make sure we never somehow use wrong type
693725
super().__init__(
694726
type=ConnectionCategory.SERVERLESS,
727+
endpoint=endpoint,
728+
api_key=api_key,
695729
allow_entra=False,
696730
from_child=True,
697731
**kwargs,

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_workspace/connections/one_lake_artifacts.py

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

77
from typing import Any
8+
from azure.ai.ml._utils._experimental import experimental
89

910
# Dev note: Supposedly there's going to be more artifact subclasses at some point.
1011
# If/when that comes to pass, we can worry about adding polymorphism to these classes.
@@ -13,6 +14,7 @@
1314

1415
# Why is this not called a "LakeHouseArtifact"? Because despite the under-the-hood type,
1516
# users expect this variety to be called "OneLake".
17+
@experimental
1618
class OneLakeConnectionArtifact:
1719
"""Artifact class used by the Connection subclass known
1820
as a MicrosoftOneLakeConnection. Supplying this class further

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_workspace/workspace.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class Workspace(Resource):
8686
:type enable_data_isolation: bool
8787
:param serverless_compute: The serverless compute settings for the workspace.
8888
:type: ~azure.ai.ml.entities.ServerlessComputeSettings
89+
:param workspace_hub: Deprecated resource ID of an existing workspace hub to help create project workspace.
90+
Use the Project class instead now.
91+
:type workspace_hub: Optional[str]
8992
:param kwargs: A dictionary of additional configuration parameters.
9093
:type kwargs: dict
9194
@@ -119,6 +122,7 @@ def __init__(
119122
managed_network: Optional[ManagedNetwork] = None,
120123
enable_data_isolation: bool = False,
121124
hub_id: Optional[str] = None, # Hidden input, surfaced by Project
125+
workspace_hub: Optional[str] = None, # Deprecated input maintained for backwards compat.
122126
serverless_compute: Optional[ServerlessComputeSettings] = None,
123127
**kwargs: Any,
124128
):
@@ -156,6 +160,8 @@ def __init__(
156160
self.primary_user_assigned_identity = primary_user_assigned_identity
157161
self.managed_network = managed_network
158162
self.enable_data_isolation = enable_data_isolation
163+
if workspace_hub and not hub_id:
164+
hub_id = workspace_hub
159165
self.__hub_id = hub_id
160166
# Overwrite kind if hub_id is provided. Technically not needed anymore,
161167
# but kept for backwards if people try to just use a normal workspace like

sdk/ml/azure-ai-ml/tests/connection/unittests/test_connection_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def test_ws_conn_subtype_restriction(self):
481481
credentials=None,
482482
)
483483
_ = AzureOpenAIConnection(
484-
target="dummy_target",
484+
azure_endpoint="dummy_target",
485485
name="dummy_connection",
486486
strict_typing=True,
487487
credentials=None,

0 commit comments

Comments
 (0)