Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -7,6 +7,7 @@
def get_cognitiveservices_management_client(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient

return get_mgmt_service_client(cli_ctx, CognitiveServicesManagementClient)


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


def cf_ai_projects(cli_ctx, command_args):
"""
Create AI Projects client for data plane operations.
Similar to keyvault's data plane client factory pattern.
"""
from azure.ai.projects import AIProjectClient
from azure.cli.core.commands.client_factory import prepare_client_kwargs_track2
from azure.cli.core._profile import Profile

# Get credentials using Azure CLI login
profile = Profile(cli_ctx=cli_ctx)
credential, _, _ = profile.get_login_credentials(
subscription_id=cli_ctx.data.get("subscription_id")
)

# Get endpoint from command arguments (similar to keyvault's vault_url)
account_name = command_args.get("account_name", None)
endpoint = command_args.get("endpoint", None)
project = command_args.get("project_name", None)

# If no explicit endpoint provided, construct from account name
if not endpoint and account_name:
# Construct endpoint URL from account name
# Format: https://{account_name}.cognitiveservices.azure.com
endpoint = (
f"https://{account_name}.services.ai.azure.com/api/projects/{project}"
)

if not endpoint:
from azure.cli.core.azclierror import RequiredArgumentMissingError

raise RequiredArgumentMissingError(
"Please specify --account-name or --endpoint"
)

# Prepare client kwargs with proper logging and telemetry
client_kwargs = prepare_client_kwargs_track2(cli_ctx)

# Create and return the AI Projects client
return AIProjectClient(endpoint=endpoint, credential=credential, **client_kwargs)


def cf_projects(cli_ctx, *_):
return get_cognitiveservices_management_client(cli_ctx).projects

Expand Down
Loading
Loading