|
| 1 | +param ( |
| 2 | + [string]$SubscriptionId, |
| 3 | + [string]$Location, |
| 4 | + [string]$ModelsParameter |
| 5 | +) |
| 6 | + |
| 7 | +$AiFoundryName = $env:AZURE_AIFOUNDRY_NAME |
| 8 | +$ResourceGroup = $env:AZURE_RESOURCE_GROUP |
| 9 | + |
| 10 | +# Validate required parameters |
| 11 | +$MissingParams = @() |
| 12 | +if (-not $SubscriptionId) { $MissingParams += "SubscriptionId" } |
| 13 | +if (-not $Location) { $MissingParams += "Location" } |
| 14 | +if (-not $ModelsParameter) { $MissingParams += "ModelsParameter" } |
| 15 | + |
| 16 | +if ($MissingParams.Count -gt 0) { |
| 17 | + Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')" |
| 18 | + exit 1 |
| 19 | +} |
| 20 | + |
| 21 | +# Check Azure login |
| 22 | +try { |
| 23 | + $accountCheck = az account show --output none 2>$null |
| 24 | + if ($LASTEXITCODE -ne 0) { |
| 25 | + Write-Error "❌ ERROR: You are not logged in to Azure CLI. Please run 'az login'." |
| 26 | + exit 1 |
| 27 | + } |
| 28 | +} catch { |
| 29 | + Write-Error "❌ ERROR: Failed to verify Azure login." |
| 30 | + exit 1 |
| 31 | +} |
| 32 | + |
| 33 | +# Load model deployments from parameter file |
| 34 | +$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json |
| 35 | +$availableKeys = $JsonContent.parameters.PSObject.Properties.Name |
| 36 | + |
| 37 | +if (-not $JsonContent.parameters.$ModelsParameter) { |
| 38 | + Write-Error "❌ ERROR: '$ModelsParameter' not found in main.parameters.json" |
| 39 | + Write-Host "Available Parameters: $($availableKeys -join ', ')" |
| 40 | + exit 1 |
| 41 | +} |
| 42 | + |
| 43 | +$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value |
| 44 | + |
| 45 | +if (-not $aiModelDeployments -or $aiModelDeployments.Count -lt 2) { |
| 46 | + Write-Error "❌ ERROR: Expected at least 2 model deployments in '$ModelsParameter'" |
| 47 | + exit 1 |
| 48 | +} |
| 49 | + |
| 50 | +Write-Host "ℹ️ Loaded AI model deployments from main.parameters.json" |
| 51 | +$aiModelDeployments | ConvertTo-Json -Depth 10 | Write-Host |
| 52 | + |
| 53 | +# Extract both model configs |
| 54 | +$gpt4o = $aiModelDeployments | Where-Object { $_.model.name -like "gpt-4o*" } |
| 55 | +$embed = $aiModelDeployments | Where-Object { $_.model.name -like "text-embedding-ada-002" } |
| 56 | + |
| 57 | +if (-not $gpt4o -or -not $embed) { |
| 58 | + Write-Error "❌ ERROR: Could not find both gpt-4o and text-embedding-ada-002 models." |
| 59 | + exit 1 |
| 60 | +} |
| 61 | + |
| 62 | +$GPT4O_Name = if ($env:AZURE_ENV_MODEL_NAME) { $env:AZURE_ENV_MODEL_NAME } else { $gpt4o.model.name } |
| 63 | +$GPT4O_Capacity = if ($env:AZURE_ENV_MODEL_CAPACITY) { $env:AZURE_ENV_MODEL_CAPACITY } else { $gpt4o.sku.capacity } |
| 64 | +$GPT4O_DeploymentType = if ($env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE) { $env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $gpt4o.sku.name } |
| 65 | + |
| 66 | +$Embedding_Name = if ($env:AZURE_ENV_EMBEDDING_MODEL_NAME) { $env:AZURE_ENV_EMBEDDING_MODEL_NAME } else { $embed.model.name } |
| 67 | +$Embedding_Capacity = if ($env:AZURE_ENV_EMBEDDING_MODEL_CAPACITY) { $env:AZURE_ENV_EMBEDDING_MODEL_CAPACITY } else { $embed.sku.capacity } |
| 68 | +$Embedding_DeploymentType = $embed.sku.name |
| 69 | + |
| 70 | +# Optional: Check if already deployed |
| 71 | +if (-not $AiFoundryName -and $ResourceGroup) { |
| 72 | + $AiFoundryName = az cognitiveservices account list ` |
| 73 | + --resource-group $ResourceGroup ` |
| 74 | + --query "sort_by([?kind=='AIServices'], &name)[0].name" ` |
| 75 | + -o tsv 2>$null |
| 76 | +} |
| 77 | + |
| 78 | +if ($AiFoundryName -and $ResourceGroup) { |
| 79 | + $existing = az cognitiveservices account show ` |
| 80 | + --name $AiFoundryName ` |
| 81 | + --resource-group $ResourceGroup ` |
| 82 | + --query "name" --output tsv 2>$null |
| 83 | + |
| 84 | + if ($existing) { |
| 85 | + azd env set AZURE_AIFOUNDRY_NAME $existing | Out-Null |
| 86 | + |
| 87 | + $deployedModelsOutput = az cognitiveservices account deployment list ` |
| 88 | + --name $AiFoundryName ` |
| 89 | + --resource-group $ResourceGroup ` |
| 90 | + --query "[].name" --output tsv 2>$null |
| 91 | + |
| 92 | + $deployedModels = @() |
| 93 | + if ($deployedModelsOutput -is [string]) { |
| 94 | + $deployedModels += $deployedModelsOutput |
| 95 | + } elseif ($deployedModelsOutput) { |
| 96 | + $deployedModels = $deployedModelsOutput -split "`r?`n" |
| 97 | + } |
| 98 | + |
| 99 | + $missingDeployments = @($gpt4o.name, $embed.name) | Where-Object { $_ -notin $deployedModels } |
| 100 | + |
| 101 | + if ($missingDeployments.Count -eq 0) { |
| 102 | + Write-Host "⏭️ All models already deployed in AI Foundry '$AiFoundryName'. Skipping validation." |
| 103 | + exit 0 |
| 104 | + } else { |
| 105 | + Write-Host "🔍 Missing models: $($missingDeployments -join ', ')" |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +# Set subscription and call inner script |
| 111 | +az account set --subscription $SubscriptionId |
| 112 | +Write-Host "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)" |
| 113 | + |
| 114 | +# ✅ CALL INNER SCRIPT ONCE with all values together |
| 115 | +& .\infra\scripts\validate_model_quota.ps1 ` |
| 116 | + -Location $Location ` |
| 117 | + -GPT4O_Name $GPT4O_Name ` |
| 118 | + -GPT4O_Capacity $GPT4O_Capacity ` |
| 119 | + -GPT4O_DeploymentType $GPT4O_DeploymentType ` |
| 120 | + -Embedding_Name $Embedding_Name ` |
| 121 | + -Embedding_Capacity $Embedding_Capacity ` |
| 122 | + -Embedding_DeploymentType $Embedding_DeploymentType |
| 123 | + |
| 124 | +$exitCode = $LASTEXITCODE |
| 125 | +if ($exitCode -ne 0) { |
| 126 | + Write-Error "❌ ERROR: Quota validation failed." |
| 127 | + exit 1 |
| 128 | +} else { |
| 129 | + Write-Host "✅ All model deployments passed quota validation successfully." |
| 130 | + exit 0 |
| 131 | +} |
0 commit comments