|
7 | 7 | def get_cognitiveservices_management_client(cli_ctx, *_): |
8 | 8 | from azure.cli.core.commands.client_factory import get_mgmt_service_client |
9 | 9 | from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient |
| 10 | + |
10 | 11 | return get_mgmt_service_client(cli_ctx, CognitiveServicesManagementClient) |
11 | 12 |
|
12 | 13 |
|
@@ -42,6 +43,48 @@ def cf_usages(cli_ctx, *_): |
42 | 43 | return get_cognitiveservices_management_client(cli_ctx).usages |
43 | 44 |
|
44 | 45 |
|
| 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 | + |
45 | 88 | def cf_projects(cli_ctx, *_): |
46 | 89 | return get_cognitiveservices_management_client(cli_ctx).projects |
47 | 90 |
|
|
0 commit comments