Skip to content

Commit c9e6351

Browse files
authored
[CognitiveServices] Add commands for container agents (#32372)
1 parent 42b2e87 commit c9e6351

File tree

6 files changed

+727
-95
lines changed

6 files changed

+727
-95
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
def get_cognitiveservices_management_client(cli_ctx, *_):
88
from azure.cli.core.commands.client_factory import get_mgmt_service_client
99
from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient
10+
1011
return get_mgmt_service_client(cli_ctx, CognitiveServicesManagementClient)
1112

1213

@@ -42,6 +43,48 @@ def cf_usages(cli_ctx, *_):
4243
return get_cognitiveservices_management_client(cli_ctx).usages
4344

4445

46+
def cf_ai_projects(cli_ctx, command_args):
47+
"""
48+
Create AI Projects client for data plane operations.
49+
Similar to keyvault's data plane client factory pattern.
50+
"""
51+
from azure.ai.projects import AIProjectClient
52+
from azure.cli.core.commands.client_factory import prepare_client_kwargs_track2
53+
from azure.cli.core._profile import Profile
54+
55+
# Get credentials using Azure CLI login
56+
profile = Profile(cli_ctx=cli_ctx)
57+
credential, _, _ = profile.get_login_credentials(
58+
subscription_id=cli_ctx.data.get("subscription_id")
59+
)
60+
61+
# Get endpoint from command arguments (similar to keyvault's vault_url)
62+
account_name = command_args.get("account_name", None)
63+
endpoint = command_args.get("endpoint", None)
64+
project = command_args.get("project_name", None)
65+
66+
# If no explicit endpoint provided, construct from account name
67+
if not endpoint and account_name:
68+
# Construct endpoint URL from account name
69+
# Format: https://{account_name}.cognitiveservices.azure.com
70+
endpoint = (
71+
f"https://{account_name}.services.ai.azure.com/api/projects/{project}"
72+
)
73+
74+
if not endpoint:
75+
from azure.cli.core.azclierror import RequiredArgumentMissingError
76+
77+
raise RequiredArgumentMissingError(
78+
"Please specify --account-name or --endpoint"
79+
)
80+
81+
# Prepare client kwargs with proper logging and telemetry
82+
client_kwargs = prepare_client_kwargs_track2(cli_ctx)
83+
84+
# Create and return the AI Projects client
85+
return AIProjectClient(endpoint=endpoint, credential=credential, **client_kwargs)
86+
87+
4588
def cf_projects(cli_ctx, *_):
4689
return get_cognitiveservices_management_client(cli_ctx).projects
4790

0 commit comments

Comments
 (0)