Skip to content

Commit bd614ac

Browse files
authored
[Cognitive Services] az cognitiveservices account [project|connection]: Add support for AI Foundry project and connection management (#32336)
1 parent 8463be3 commit bd614ac

78 files changed

Lines changed: 6293 additions & 3845 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/azure-cli/azure/cli/command_modules/cognitiveservices/_client_factory.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,23 @@ def cf_models(cli_ctx, *_):
4040

4141
def cf_usages(cli_ctx, *_):
4242
return get_cognitiveservices_management_client(cli_ctx).usages
43+
44+
45+
def cf_projects(cli_ctx, *_):
46+
return get_cognitiveservices_management_client(cli_ctx).projects
47+
48+
49+
def cf_account_connections(cli_ctx, *_):
50+
return get_cognitiveservices_management_client(cli_ctx).account_connections
51+
52+
53+
def cf_account_capability_hosts(cli_ctx, *_):
54+
return get_cognitiveservices_management_client(cli_ctx).account_capability_hosts
55+
56+
57+
def cf_project_capability_hosts(cli_ctx, *_):
58+
return get_cognitiveservices_management_client(cli_ctx).project_capability_hosts
59+
60+
61+
def cf_project_connections(cli_ctx, *_):
62+
return get_cognitiveservices_management_client(cli_ctx).project_connections

src/azure-cli/azure/cli/command_modules/cognitiveservices/_help.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,75 @@
392392
- name: Show all usages for Azure Cognitive Services.
393393
text: az cognitiveservices usage list -l centraluseuap
394394
"""
395+
396+
helps['cognitiveservices account connection'] = """
397+
type: group
398+
short-summary: Manage Azure Cognitive Services connection and its more specific derivatives.
399+
long-summary: >
400+
Azure Cognitive Services connection provides a secure way to store authentication and configuration information needed to connect and
401+
interact with the external resources.
402+
"""
403+
404+
helps['cognitiveservices account connection list'] = """
405+
type: command
406+
short-summary: List all connections.
407+
long-summary: >
408+
The list of connections in an Azure AI Foundry account.
409+
examples:
410+
- name: List all connections in an Azure AI Foundry account
411+
text: az cognitiveservices account connection list --resource-group my-resource-group --name my-cogsvc-account
412+
- name: List all the connections in an Azure AI Foundry account using --query argument to execute a JMESPath query on the results of commands.
413+
text: az cognitiveservices account connection list --query \"[].{Name:name}\" --output table --resource-group my-resource-group --name my-cogsvc-account
414+
"""
415+
416+
helps['cognitiveservices account connection show'] = """
417+
type: command
418+
short-summary: Show details of a connection.
419+
examples:
420+
- name: Show details of a connection.
421+
text: az cognitiveservices account connection show --resource-group my-resource-group --connection-name my-connection-name --name my-cogsvc-account
422+
"""
423+
helps['cognitiveservices account connection delete'] = """
424+
type: command
425+
short-summary: Delete a connection.
426+
examples:
427+
- name: Delete a connection.
428+
text: az cognitiveservices account connection delete --resource-group my-resource-group --connection-name my-connection-name --name my-cogsvc-account
429+
"""
430+
431+
helps['cognitiveservices account connection create'] = """
432+
type: command
433+
short-summary: Create a connection.
434+
examples:
435+
- name: Create a connection from a YAML specification file.
436+
text: az cognitiveservices account connection create --file connection.yml --connection-name my-connection-name --resource-group my-resource-group --name my-cogsvc-account
437+
"""
438+
439+
helps['cognitiveservices account connection update'] = """
440+
type: command
441+
short-summary: Update a connection.
442+
examples:
443+
- name: Update a connection API Key.
444+
text: az cognitiveservices account connection update --resource-group my-resource-group --connection-name my-connection-name --name my-cogsvc-account --set properties.credentials.key=<new-key>
445+
"""
446+
helps['cognitiveservices account project'] = """
447+
type: group
448+
short-summary: Manage Azure Cognitive Services account projects.
449+
long-summary: >
450+
Projects let you organize your work, such as agents, evaluations, and files, as you build stateful apps and explore new ideas. It is a container for access management,
451+
data upload and integration, and monitoring
452+
"""
453+
helps['cognitiveservices account project connection'] = """
454+
type: group
455+
short-summary: Manage Azure Cognitive Services connection associated with a project.
456+
long-summary: >
457+
Azure Cognitive Services connection provides a secure way to store authentication and configuration information needed to connect and
458+
interact with the external resources.
459+
"""
460+
helps['cognitiveservices account project connection update'] = """
461+
type: command
462+
short-summary: Update a project connection.
463+
examples:
464+
- name: Update a connection API Key.
465+
text: az cognitiveservices account project connection update --resource-group my-resource-group --connection-name my-connection-name --name my-cogsvc-account --project-name my-project --set properties.credentials.key=<new-key>
466+
"""
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
from azure.mgmt.cognitiveservices.models import ConnectionCategory
7+
8+
_ML_CONNECTION_TYPE_TO_COGNITIVE_SERVICES_CONNECTION_TYPE = {
9+
"PythonFeed": ConnectionCategory.PYTHON_FEED,
10+
"ContainerRegistry": ConnectionCategory.CONTAINER_REGISTRY,
11+
"Git": ConnectionCategory.GIT,
12+
"S3": ConnectionCategory.S3,
13+
"Snowflake": ConnectionCategory.SNOWFLAKE,
14+
"AzureSqlDb": ConnectionCategory.AZURE_SQL_DB,
15+
"AzureSynapseAnalytics": ConnectionCategory.AZURE_SYNAPSE_ANALYTICS,
16+
"AzureMySqlDb": ConnectionCategory.AZURE_MY_SQL_DB,
17+
"AzurePostgresDb": ConnectionCategory.AZURE_POSTGRES_DB,
18+
"ADLSGen2": ConnectionCategory.ADLS_GEN2,
19+
"Redis": ConnectionCategory.REDIS,
20+
"ApiKey": ConnectionCategory.API_KEY,
21+
"AzureOpenAI": ConnectionCategory.AZURE_OPEN_AI,
22+
"AzureOpenAi": ConnectionCategory.AZURE_OPEN_AI,
23+
"AIServices": ConnectionCategory.AI_SERVICES,
24+
"AiServices": ConnectionCategory.AI_SERVICES,
25+
"CognitiveSearch": ConnectionCategory.COGNITIVE_SEARCH,
26+
"CognitiveService": ConnectionCategory.COGNITIVE_SERVICE,
27+
"CustomKeys": ConnectionCategory.CUSTOM_KEYS,
28+
"AzureBlob": ConnectionCategory.AZURE_BLOB,
29+
"AzureOneLake": ConnectionCategory.AZURE_ONE_LAKE,
30+
"CosmosDb": ConnectionCategory.COSMOS_DB,
31+
"CosmosDbMongoDbApi": ConnectionCategory.COSMOS_DB_MONGO_DB_API,
32+
"AzureDataExplorer": ConnectionCategory.AZURE_DATA_EXPLORER,
33+
"AzureMariaDb": ConnectionCategory.AZURE_MARIA_DB,
34+
"AzureDatabricksDeltaLake": ConnectionCategory.AZURE_DATABRICKS_DELTA_LAKE,
35+
"AzureSqlMi": ConnectionCategory.AZURE_SQL_MI,
36+
"AzureTableStorage": ConnectionCategory.AZURE_TABLE_STORAGE,
37+
"AmazonRdsForOracle": ConnectionCategory.AMAZON_RDS_FOR_ORACLE,
38+
"AmazonRdsForSqlServer": ConnectionCategory.AMAZON_RDS_FOR_SQL_SERVER,
39+
"AmazonRedshift": ConnectionCategory.AMAZON_REDSHIFT,
40+
"Db2": ConnectionCategory.DB2,
41+
"Drill": ConnectionCategory.DRILL,
42+
"GoogleBigQuery": ConnectionCategory.GOOGLE_BIG_QUERY,
43+
"Greenplum": ConnectionCategory.GREENPLUM,
44+
"Hbase": ConnectionCategory.HBASE,
45+
"Hive": ConnectionCategory.HIVE,
46+
"Impala": ConnectionCategory.IMPALA,
47+
"Informix": ConnectionCategory.INFORMIX,
48+
"MariaDb": ConnectionCategory.MARIA_DB,
49+
"MicrosoftAccess": ConnectionCategory.MICROSOFT_ACCESS,
50+
"MySql": ConnectionCategory.MY_SQL,
51+
"Netezza": ConnectionCategory.NETEZZA,
52+
"Oracle": ConnectionCategory.ORACLE,
53+
"Phoenix": ConnectionCategory.PHOENIX,
54+
"PostgreSql": ConnectionCategory.POSTGRE_SQL,
55+
"Presto": ConnectionCategory.PRESTO,
56+
"SapOpenHub": ConnectionCategory.SAP_OPEN_HUB,
57+
"SapBw": ConnectionCategory.SAP_BW,
58+
"SapHana": ConnectionCategory.SAP_HANA,
59+
"SapTable": ConnectionCategory.SAP_TABLE,
60+
"Spark": ConnectionCategory.SPARK,
61+
"SqlServer": ConnectionCategory.SQL_SERVER,
62+
"Sybase": ConnectionCategory.SYBASE,
63+
"Teradata": ConnectionCategory.TERADATA,
64+
"Vertica": ConnectionCategory.VERTICA,
65+
"Pinecone": ConnectionCategory.PINECONE,
66+
"Cassandra": ConnectionCategory.CASSANDRA,
67+
"Couchbase": ConnectionCategory.COUCHBASE,
68+
"MongoDbV2": ConnectionCategory.MONGO_DB_V2,
69+
"MongoDbAtlas": ConnectionCategory.MONGO_DB_ATLAS,
70+
"AmazonS3Compatible": ConnectionCategory.AMAZON_S3_COMPATIBLE,
71+
"FileServer": ConnectionCategory.FILE_SERVER,
72+
"FtpServer": ConnectionCategory.FTP_SERVER,
73+
"GoogleCloudStorage": ConnectionCategory.GOOGLE_CLOUD_STORAGE,
74+
"Hdfs": ConnectionCategory.HDFS,
75+
"OracleCloudStorage": ConnectionCategory.ORACLE_CLOUD_STORAGE,
76+
"Sftp": ConnectionCategory.SFTP,
77+
"GenericHttp": ConnectionCategory.GENERIC_HTTP,
78+
"ODataRest": ConnectionCategory.O_DATA_REST,
79+
"Odbc": ConnectionCategory.ODBC,
80+
"GenericRest": ConnectionCategory.GENERIC_REST,
81+
"AmazonMws": ConnectionCategory.AMAZON_MWS,
82+
"Concur": ConnectionCategory.CONCUR,
83+
"Dynamics": ConnectionCategory.DYNAMICS,
84+
"DynamicsAx": ConnectionCategory.DYNAMICS_AX,
85+
"DynamicsCrm": ConnectionCategory.DYNAMICS_CRM,
86+
"GoogleAdWords": ConnectionCategory.GOOGLE_AD_WORDS,
87+
"Hubspot": ConnectionCategory.HUBSPOT,
88+
"Jira": ConnectionCategory.JIRA,
89+
"Magento": ConnectionCategory.MAGENTO,
90+
"Marketo": ConnectionCategory.MARKETO,
91+
"Office365": ConnectionCategory.OFFICE365,
92+
"Eloqua": ConnectionCategory.ELOQUA,
93+
"Responsys": ConnectionCategory.RESPONSYS,
94+
"OracleServiceCloud": ConnectionCategory.ORACLE_SERVICE_CLOUD,
95+
"PayPal": ConnectionCategory.PAY_PAL,
96+
"QuickBooks": ConnectionCategory.QUICK_BOOKS,
97+
"Salesforce": ConnectionCategory.SALESFORCE,
98+
"SalesforceServiceCloud": ConnectionCategory.SALESFORCE_SERVICE_CLOUD,
99+
"SalesforceMarketingCloud": ConnectionCategory.SALESFORCE_MARKETING_CLOUD,
100+
"SapCloudForCustomer": ConnectionCategory.SAP_CLOUD_FOR_CUSTOMER,
101+
"SapEcc": ConnectionCategory.SAP_ECC,
102+
"ServiceNow": ConnectionCategory.SERVICE_NOW,
103+
"SharePointOnlineList": ConnectionCategory.SHARE_POINT_ONLINE_LIST,
104+
"Shopify": ConnectionCategory.SHOPIFY,
105+
"Square": ConnectionCategory.SQUARE,
106+
"WebTable": ConnectionCategory.WEB_TABLE,
107+
"Xero": ConnectionCategory.XERO,
108+
"Zoho": ConnectionCategory.ZOHO,
109+
"GenericContainerRegistry": ConnectionCategory.GENERIC_CONTAINER_REGISTRY,
110+
"Elasticsearch": ConnectionCategory.ELASTICSEARCH,
111+
"OpenAI": ConnectionCategory.OPEN_AI,
112+
"OpenAi": ConnectionCategory.OPEN_AI,
113+
"Serp": ConnectionCategory.SERP,
114+
"BingLLMSearch": ConnectionCategory.BING_LLM_SEARCH,
115+
"Serverless": ConnectionCategory.SERVERLESS,
116+
"ManagedOnlineEndpoint": ConnectionCategory.MANAGED_ONLINE_ENDPOINT,
117+
# The following are from azure.ai.ml.constants._common.ConnectionTypes
118+
"Custom": ConnectionCategory.CUSTOM_KEYS,
119+
"AzureDataLakeGen2": ConnectionCategory.ADLS_GEN2,
120+
"AzureContentSafety": ConnectionCategory.COGNITIVE_SERVICE,
121+
"AzureSpeechServices": ConnectionCategory.COGNITIVE_SERVICE,
122+
"AzureAiSearch": ConnectionCategory.COGNITIVE_SEARCH,
123+
"AzureAiServices": ConnectionCategory.AI_SERVICES,
124+
}
125+
126+
127+
def get_valid_mlconn_types():
128+
return list(_ML_CONNECTION_TYPE_TO_COGNITIVE_SERVICES_CONNECTION_TYPE.keys())
129+
130+
131+
def get_mapped_mlconn_type(ml_connection_type: str):
132+
from . _utils import snake_to_camel
133+
normalized_name = snake_to_camel(ml_connection_type)
134+
return _ML_CONNECTION_TYPE_TO_COGNITIVE_SERVICES_CONNECTION_TYPE.get(normalized_name)

src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ def _validate_subnet(cmd, namespace):
121121
child_name_1=subnet)
122122

123123

124+
def _validate_user_assigned_identity(cmd, namespace):
125+
from azure.mgmt.core.tools import resource_id, is_valid_resource_id
126+
from azure.cli.core.commands.client_factory import get_subscription_id
127+
if namespace.user_assigned_identity:
128+
identity = namespace.user_assigned_identity
129+
if not is_valid_resource_id(identity):
130+
namespace.user_assigned_identity = resource_id(
131+
subscription=get_subscription_id(cmd.cli_ctx),
132+
resource_group=namespace.resource_group_name,
133+
namespace='Microsoft.ManagedIdentity',
134+
type='userAssignedIdentities',
135+
name=identity)
136+
137+
124138
@Completer
125139
def sku_name_completer(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument
126140
names = {x.name for x in _sku_filter(cmd, namespace)}
@@ -183,6 +197,9 @@ def load_arguments(self, _):
183197

184198
with self.argument_context('cognitiveservices account deployment') as c:
185199
c.argument('deployment_name', help='Cognitive Services account deployment name')
200+
c.argument('spillover_deployment_name',
201+
options_list=['--spillover-deployment-name', '--spillover-name'],
202+
help='The name of the standard deployment to use as a spillover when at capacity.')
186203

187204
with self.argument_context('cognitiveservices account deployment', arg_group='DeploymentModel') as c:
188205
c.argument('model_name', help='Cognitive Services account deployment model name.')
@@ -214,3 +231,32 @@ def load_arguments(self, _):
214231
with self.argument_context('cognitiveservices account commitment-plan', arg_group='Next CommitmentPeriod') as c:
215232
c.argument('next_count', help='Cognitive Services account commitment plan next commitment period count.')
216233
c.argument('next_tier', help='Cognitive Services account commitment plan next commitment period tier.')
234+
235+
with self.argument_context('cognitiveservices account project') as c:
236+
c.argument('project_name', help='Cognitive Services account project name')
237+
c.argument('location', arg_type=get_location_type(self.cli_ctx),
238+
completer=location_completer)
239+
c.argument('description', help='Description of the project.')
240+
c.argument('display_name', help='Display name of the project.')
241+
242+
with self.argument_context('cognitiveservices account project', arg_group='Project Identity') as c:
243+
c.argument("assign_identity",
244+
options_list=['--include-system-identity', '--assign-identity'],
245+
help=('Use with --user-assigned-identity to generate and assign a '
246+
'system managed Azure Active Directory Identity for this project.'))
247+
c.argument('user_assigned_identity',
248+
help=('User assigned identity resource ID to use for the project. '
249+
'If not specified, a system assigned identity will be used.'),
250+
validator=_validate_user_assigned_identity)
251+
252+
with self.argument_context('cognitiveservices account project create') as c:
253+
c.argument('description', help='Description of the project.')
254+
c.argument('display_name', help='Display name of the project.')
255+
256+
with self.argument_context('cognitiveservices account project connection') as c:
257+
c.argument('connection_name', help='Cognitive Services account connection name')
258+
c.argument('file', help='Path to the connection file in JSON or YAML format.')
259+
260+
with self.argument_context('cognitiveservices account connection') as c:
261+
c.argument('connection_name', help='Cognitive Services account connection name')
262+
c.argument('file', help='Path to the connection file in JSON or YAML format.')

0 commit comments

Comments
 (0)