Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5947e8b
get other conn types in list op
MilesHolland Jan 12, 2024
4f006da
accept empty connections in rest-local conversion
MilesHolland Jan 25, 2024
e319d40
Merge branch 'main' of https://github.com/azure/azure-sdk-for-python
MilesHolland Jan 25, 2024
e5af527
Merge branch 'main' into connections-jan-asks
MilesHolland Jan 25, 2024
9318317
azure blob base changes
MilesHolland Jan 31, 2024
d986da9
Merge branch 'main' into connections-jan-asks
MilesHolland Jan 31, 2024
1b6d921
partial replacement of if-else with maps in wc
MilesHolland Feb 2, 2024
6263dc6
more if-else removal refactors
MilesHolland Feb 5, 2024
4b6f2dc
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 5, 2024
5882887
solidify connection changes
MilesHolland Feb 6, 2024
47c9b51
run black on v2
MilesHolland Feb 6, 2024
de24812
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 6, 2024
5c8930f
initial self review
MilesHolland Feb 6, 2024
4b4c988
spelling
MilesHolland Feb 6, 2024
6f539fd
rerun black and ai nit
MilesHolland Feb 6, 2024
ea5b62f
more nits, and push flag to v2
MilesHolland Feb 7, 2024
7d4ca46
e2e test
MilesHolland Feb 7, 2024
d87bba7
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 7, 2024
663ea4c
e2e test recordings and use 2024 restclient
MilesHolland Feb 7, 2024
a3907f9
analyze ci issues
MilesHolland Feb 7, 2024
2e85ab2
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 7, 2024
5aa8207
mypy fixes
MilesHolland Feb 8, 2024
7795de7
more mypy
MilesHolland Feb 8, 2024
ec10c08
Merge branch 'connections-jan-asks' of github.com:MilesHolland/azure-…
MilesHolland Feb 8, 2024
0e2d312
remove 2024 conn dep until CI wakes up
MilesHolland Feb 8, 2024
31939b5
skip problematic test
MilesHolland Feb 8, 2024
e3be48b
try bumping mindep
MilesHolland Feb 8, 2024
710b06a
remove skip
MilesHolland Feb 8, 2024
b922eec
undo 1.14.0 dep
MilesHolland Feb 8, 2024
9d800cb
add back in 1.14 dep
MilesHolland Feb 8, 2024
a408731
comments
MilesHolland Feb 12, 2024
10922a1
linting
MilesHolland Feb 12, 2024
d2c66ed
remove extra line
MilesHolland Feb 12, 2024
dba0cbd
more linting
MilesHolland Feb 13, 2024
66e202c
run black
MilesHolland Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def test_invalid_num_questions(self, num_questions):
qa_generator.generate("", QAType.SHORT_ANSWER, num_questions)
assert str(excinfo.value) == "num_questions must be an integer greater than zero"


@pytest.mark.skipif(condition=True, reason="""Fails on CI due to permissions issues.""")
@pytest.mark.parametrize("qa_type", [QAType.CONVERSATION, QAType.SHORT_ANSWER])
@pytest.mark.parametrize("structure", [OutputStructure.CHAT_PROTOCOL, OutputStructure.PROMPTFLOW])
def test_export_format(self, qa_type, structure):
Expand Down
3 changes: 3 additions & 0 deletions sdk/ai/azure-ai-resources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
## 1.0.0b7 (Unreleased)

### Features Added
- Connections LIST operation now supports returning data connections via new optional flag: include_data_connections.
- Connections have read-only support for 3 new connection types: gen 2, data lake, and azure blob.

### Breaking Changes

### Bugs Fixed
- Connections docstrings now discuss scope field.

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
AzureAIServiceConnection,
GitHubConnection,
CustomConnection,
AzureBlobStoreConnection,
)
from .mlindex import Index
from .project import Project
from .data import Data
from .configs import AzureOpenAIModelConfiguration
from azure.ai.ml.entities import ApiKeyConfiguration

__all__ = [
"BaseConnection",
Expand All @@ -31,5 +33,7 @@
"AzureOpenAIModelConfiguration",
"GitHubConnection",
"CustomConnection",
"AzureBlobStoreConnection",
"ApiKeyConfiguration"
]

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@

from typing import Any, Dict, Optional

from azure.ai.ml._utils.utils import camel_to_snake
from azure.ai.ml._utils.utils import camel_to_snake, _snake_to_camel
from azure.ai.ml.entities import WorkspaceConnection
from azure.ai.ml.entities._credentials import ApiKeyConfiguration
from azure.core.credentials import TokenCredential
from azure.ai.ml._restclient.v2023_06_01_preview.models import ConnectionCategory

from azure.ai.ml._restclient.v2023_08_01_preview.models import ConnectionCategory
from azure.ai.ml.constants._common import (
WorkspaceConnectionTypes,
)

class BaseConnection:
"""A connection to a specific external AI system. This is a base class and should not be
instantiated directly. Use the child classes that are specialized for connections to different services.
"""A connection to a another system or service. This is a base class and should only be directly
used to cover the simplest of connection types that don't merit their own subclass.

:param name: The name of the connection
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param type: The type of connection this represents. Acceptable values include:
"azure_open_ai", "cognitive_service", and "cognitive_search".
"azure_open_ai", "cognitive_service", "cognitive_search",
"git", "azure_blob", and "custom".
:type type: str
:param credentials: The credentials for authenticating to the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
Expand All @@ -46,10 +49,13 @@ def __init__(
**kwargs,
):
# Sneaky short-circuit to allow direct v2 WS conn injection without any
# polymorphic required argument hassles.
# polymorphic-argument hassles.
# See _from_v2_workspace_connection for usage.
if kwargs.pop("make_empty", False):
return

# Dev note: this is an important line, as is quietly changes the internal object from
# A WorkspaceConnection to the relevant subclass if needed.
conn_class = WorkspaceConnection._get_entity_class_from_type(type)
self._workspace_connection = conn_class(
target=target,
Expand All @@ -69,10 +75,23 @@ def _from_v2_workspace_connection(cls, workspace_connection: WorkspaceConnection
:return: The converted connection.
:rtype: ~azure.ai.resources.entities.Connection
"""
# It's simpler to create a placeholder connection, then overwrite the internal WC.
# We don't need to worry about the potentially changing WC fields this way.
conn_class = cls._get_ai_connection_class_from_type(workspace_connection.type)
conn = conn_class(type="a", target="a", credentials=None, name="a", make_empty=True, api_version=None, api_type=None, kind=None)
# This slightly-cheeky init is just a placeholder that is immediately replaced
# with a directly-injected v2 connection object.
# Since all connection class initializers have kwargs, we can just throw a kitchen sink's
# worth of inputs to satisfy all possible subclass input requirements.
conn = conn_class(
type="a",
target="a",
credentials=None,
name="a",
make_empty=True,
api_version=None,
api_type=None,
kind=None,
account_name="a",
container_name="a",
)
conn._workspace_connection = workspace_connection
return conn

Expand All @@ -81,21 +100,38 @@ def _get_ai_connection_class_from_type(cls, conn_type: str):
"""Given a connection type string, get the corresponding AI SDK object via class
comparisons. Accounts for any potential camel/snake/capitalization issues. Returns
the BaseConnection class if no match is found.

:param conn_type: The type of the connection as a string. Should match one of the
supported connection category values.
:type conn_type: str
"""
#import here to avoid circular import
from .connection_subtypes import (
AzureOpenAIConnection,
AzureAISearchConnection,
AzureAIServiceConnection,
GitHubConnection,
CustomConnection,
AzureBlobStoreConnection
)

cat = camel_to_snake(conn_type).lower()
if cat == camel_to_snake(ConnectionCategory.AZURE_OPEN_AI).lower():
return AzureOpenAIConnection
elif cat == camel_to_snake(ConnectionCategory.COGNITIVE_SEARCH).lower():
return AzureAISearchConnection
elif cat == camel_to_snake(ConnectionCategory.COGNITIVE_SERVICE).lower():
return AzureAIServiceConnection
# Custom accounts for both "custom_keys" and "custom" as conversion types in case of
# improper input.
# All values are lower-cased to normalize input.
# TODO replace azure blob with conn category when available.
CONNECTION_CATEGORY_TO_SUBCLASS_MAP = {
ConnectionCategory.AZURE_OPEN_AI.lower(): AzureOpenAIConnection,
ConnectionCategory.COGNITIVE_SEARCH.lower(): AzureAISearchConnection,
ConnectionCategory.COGNITIVE_SERVICE.lower(): AzureAIServiceConnection,
ConnectionCategory.GIT.lower(): GitHubConnection,
"azureblob": AzureBlobStoreConnection, # TODO replace with conn category when available
ConnectionCategory.CUSTOM_KEYS.lower(): CustomConnection,
WorkspaceConnectionTypes.CUSTOM.lower(): CustomConnection
}
# snake and lower-case inputted type to match the map.
cat = _snake_to_camel(conn_type).lower()
if cat in CONNECTION_CATEGORY_TO_SUBCLASS_MAP:
return CONNECTION_CATEGORY_TO_SUBCLASS_MAP[cat]
return BaseConnection


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
CONNECTION_API_VERSION_KEY,
CONNECTION_API_TYPE_KEY,
CONNECTION_KIND_KEY,
CONNECTION_ACCOUNT_NAME_KEY,
CONNECTION_CONTAINER_NAME_KEY,
)

from .base_connection import BaseConnection
Expand All @@ -25,8 +27,6 @@ class AzureOpenAIConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param api_version: The api version that this connection was created for.
Expand All @@ -36,6 +36,8 @@ class AzureOpenAIConnection(BaseConnection):
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand Down Expand Up @@ -66,8 +68,8 @@ def api_version(self) -> Optional[str]:
def api_version(self, value: str) -> None:
"""Set the API version of the connection.

:return: the API version of the connection.
:rtype: str
:param value: the API version of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_VERSION_KEY] = value

Expand All @@ -86,8 +88,8 @@ def api_type(self) -> Optional[str]:
def api_type(self, value: str) -> None:
"""Set the API type of the connection.

:return: the API type of the connection.
:rtype: str
:param value: the API type of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_TYPE_KEY] = value

Expand Down Expand Up @@ -154,15 +156,15 @@ class AzureAISearchConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param api_version: The api version that this connection was created for. Only applies to certain connection types.
:type api_version: Optional[str]
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand Down Expand Up @@ -192,8 +194,8 @@ def api_version(self) -> Optional[str]:
def api_version(self, value: str) -> None:
"""Set the API version of the connection.

:return: the API version of the connection.
:rtype: str
:param value: the API version of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_VERSION_KEY] = value

Expand Down Expand Up @@ -224,8 +226,6 @@ class AzureAIServiceConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param api_version: The api version that this connection was created for.
Expand All @@ -236,6 +236,8 @@ class AzureAIServiceConnection(BaseConnection):
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand Down Expand Up @@ -265,8 +267,8 @@ def api_version(self) -> Optional[str]:
def api_version(self, value: str) -> None:
"""Set the API version of the connection.

:return: the API version of the connection.
:rtype: str
:param value: the API version of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_VERSION_KEY] = value

Expand All @@ -285,8 +287,8 @@ def kind(self) -> Optional[str]:
def kind(self, value: str) -> None:
"""Set the kind of the connection.

:return: the kind of the connection.
:rtype: str
:param value: the kind of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_KIND_KEY] = value

Expand All @@ -297,13 +299,13 @@ class GitHubConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand All @@ -316,20 +318,92 @@ def __init__(
kwargs.pop("type", None) # make sure we never somehow use wrong type
super().__init__(target=target, type="git", credentials=credentials, **kwargs)

class AzureBlobStoreConnection(BaseConnection):
"""A Connection to an Azure Blob Datastore. Unlike other connection objects, this subclass has no credentials.
NOTE: This connection type is currently READ-ONLY via the LIST operation. Attempts to create or update
a connection of this type will result in an error.

:param name: Name of the connection.
:type name: str
:param target: The URL or ARM resource ID of the resource.
:type target: str
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
self,
*,
target: str,
container_name: str,
account_name: str,
**kwargs,
) -> None:
kwargs.pop("type", None) # make sure we never somehow use wrong type
super().__init__(
target=target,
type="azure_blob",
container_name=container_name,
account_name=account_name,
**kwargs
)

@property
def container_name(self) -> str:
"""The container name of the connection.

:return: the container name of the connection.
:rtype: str
"""
if self._workspace_connection.tags is not None and CONNECTION_CONTAINER_NAME_KEY in self._workspace_connection.tags:
return self._workspace_connection.tags[CONNECTION_CONTAINER_NAME_KEY]
return ""

@container_name.setter
def container_name(self, value: str) -> None:
"""Set the container name of the connection.

:param value: the new container name of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_CONTAINER_NAME_KEY] = value

@property
def account_name(self) -> str:
"""The account name of the connection.

:return: the account name of the connection.
:rtype: str
"""
if self._workspace_connection.tags is not None and CONNECTION_ACCOUNT_NAME_KEY in self._workspace_connection.tags:
return self._workspace_connection.tags[CONNECTION_ACCOUNT_NAME_KEY]
return ""

@account_name.setter
def account_name(self, value: str) -> None:
"""Set the account name of the connection.

:param value: the new account name of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_ACCOUNT_NAME_KEY] = value
class CustomConnection(BaseConnection):
"""A Connection to system that's not encapsulated by other connection types.

:param name: Name of the connection.
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""
def __init__(
self,
Expand Down
Loading