From e6d0ea1f97627b75a948dc80433d46e045d7db0e Mon Sep 17 00:00:00 2001 From: Priyanka-Microsoft Date: Fri, 13 Jun 2025 16:33:59 +0530 Subject: [PATCH 1/2] updated the validation file --- scripts/validate_model_quota.ps1 | 194 ++++++++++++++++-------- scripts/validate_model_quota.sh | 253 ++++++++++++++++++++----------- 2 files changed, 292 insertions(+), 155 deletions(-) diff --git a/scripts/validate_model_quota.ps1 b/scripts/validate_model_quota.ps1 index 46c13cc..e873a3d 100644 --- a/scripts/validate_model_quota.ps1 +++ b/scripts/validate_model_quota.ps1 @@ -5,49 +5,59 @@ param ( [int]$Capacity ) -# Validate parameters +$RECOMMENDED_TOKENS = 200 +$BicepParamsFile = "main.bicepparams" +$ParametersJsonFile = "./infra/main.parameters.json" +$PreferredRegions = @('australiaeast', 'eastus', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'southindia', 'swedencentral', 'uksouth', 'westus', 'westus3') +$AllResults = @() +$RecommendedRegions = @() +$NotRecommendedRegions = @() +$EligibleFallbacks = @() + +# ------------------ Validate Inputs ------------------ $MissingParams = @() if (-not $Location) { $MissingParams += "location" } if (-not $Model) { $MissingParams += "model" } -if (-not $Capacity) { $MissingParams += "capacity" } +if (-not $Capacity -or $Capacity -le 0) { $MissingParams += "capacity" } if ($MissingParams.Count -gt 0) { - Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')" + Write-Error "❌ ERROR: Missing or invalid parameters: $($MissingParams -join ', ')" Write-Host "Usage: .\validate_model_quota.ps1 -Location -Model -Capacity [-DeploymentType ]" exit 1 } if ($DeploymentType -ne "Standard" -and $DeploymentType -ne "GlobalStandard") { - Write-Error "❌ ERROR: Invalid deployment type: $DeploymentType. Allowed values are 'Standard' or 'GlobalStandard'." + Write-Error "❌ ERROR: Invalid deployment type: $DeploymentType. Allowed: 'Standard', 'GlobalStandard'" exit 1 } $ModelType = "OpenAI.$DeploymentType.$Model" -$PreferredRegions = @('australiaeast', 'eastus', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'southindia', 'swedencentral', 'uksouth', 'westus', 'westus3') -$AllResults = @() function Check-Quota { - param ( - [string]$Region - ) + param ([string]$Region) try { - $ModelInfoRaw = az cognitiveservices usage list --location $Region --query "[?name.value=='$ModelType']" --output json + $ModelInfoRaw = az cognitiveservices usage list --location $Region --query "[?name.value=='$ModelType']" --output json 2>$null $ModelInfo = $ModelInfoRaw | ConvertFrom-Json - if (-not $ModelInfo) { return $null } + if (-not $ModelInfo -or $ModelInfo.Count -eq 0) { + return $null + } - $CurrentValue = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).currentValue - $Limit = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).limit + $Current = [int]$ModelInfo[0].currentValue + $Limit = [int]$ModelInfo[0].limit + $Available = $Limit - $Current - $CurrentValue = [int]($CurrentValue -replace '\.0+$', '') - $Limit = [int]($Limit -replace '\.0+$', '') - $Available = $Limit - $CurrentValue + if ($Available -ge $RECOMMENDED_TOKENS) { + $script:RecommendedRegions += $Region + } else { + $script:NotRecommendedRegions += $Region + } return [PSCustomObject]@{ Region = $Region Model = $ModelType Limit = $Limit - Used = $CurrentValue + Used = $Current Available = $Available } } catch { @@ -56,81 +66,137 @@ function Check-Quota { } function Show-Table { - Write-Host "`n--------------------------------------------------------------------------------------------" - Write-Host "| No. | Region | Model Name | Limit | Used | Available |" - Write-Host "--------------------------------------------------------------------------------------------" - $count = 1 - foreach ($entry in $AllResults) { - Write-Host ("| {0,-3} | {1,-14} | {2,-35} | {3,-5} | {4,-5} | {5,-9} |" -f $count, $entry.Region, $entry.Model, $entry.Limit, $entry.Used, $entry.Available) - $count++ + Write-Host "`n--------------------------------------------------------------------------------------------------" + Write-Host "| No. | Region | Model Name | Limit | Used | Available |" + Write-Host "--------------------------------------------------------------------------------------------------" + $i = 1 + foreach ($entry in $AllResults | Where-Object { $_.Available -gt 50 }) { + Write-Host ("| {0,-3} | {1,-15} | {2,-35} | {3,-5} | {4,-5} | {5,-9} |" -f $i, $entry.Region, $entry.Model, $entry.Limit, $entry.Used, $entry.Available) + $i++ } - Write-Host "--------------------------------------------------------------------------------------------" + Write-Host "--------------------------------------------------------------------------------------------------" } -# ----------- First check the user-specified region ----------- +function Set-DeploymentValues($Region, $Capacity) { + azd env set AZURE_AISERVICE_LOCATION "$Region" | Out-Null + azd env set AZURE_ENV_MODEL_CAPACITY "$Capacity" | Out-Null + + if (Test-Path $ParametersJsonFile) { + try { + $json = Get-Content $ParametersJsonFile -Raw | ConvertFrom-Json + if ($json.parameters.aiModelDeployments.value.Count -gt 0) { + $json.parameters.aiModelDeployments.value[0].sku.capacity = $Capacity + $json | ConvertTo-Json -Depth 20 | Set-Content $ParametersJsonFile -Force + Write-Host "✅ Updated '$ParametersJsonFile' with capacity $Capacity." + } else { + Write-Host "⚠️ 'aiModelDeployments.value' array is empty. No changes made." + } + } catch { + Write-Host "❌ Failed to update '$ParametersJsonFile': $_" + } + } else { + Write-Host "⚠️ '$ParametersJsonFile' not found. Skipping update." + } +} + +# ------------------ Check Primary Region ------------------ Write-Host "`n🔍 Checking quota in the requested region '$Location'..." $PrimaryResult = Check-Quota -Region $Location if ($PrimaryResult) { $AllResults += $PrimaryResult if ($PrimaryResult.Available -ge $Capacity) { - Write-Host "`n✅ Sufficient quota found in original region '$Location'." - exit 0 + if ($RecommendedRegions -notcontains $Location -and $RecommendedRegions.Count -gt 0) { + Write-Host "`n⚠️ Selected region '$Location' has sufficient quota but is not among the recommended regions (≥ $RECOMMENDED_TOKENS tokens)." + Write-Host "🚨 Your application may not work as expected due to limited quota." + Write-Host "`nℹ️ Recommended regions: $($RecommendedRegions -join ', ')" + $choice = Read-Host "❓ Do you want to choose a recommended region instead? (y/n)" + if ($choice -match "^[Yy]$") { + Show-Table + break + } else { + if ($Capacity -gt 200) { + Write-Host "`n⚠️ Reducing capacity to 200 in '$BicepParamsFile' for safer deployment..." + (Get-Content $BicepParamsFile) -replace "capacity\s*:\s*\d+", "capacity: 200" | Set-Content $BicepParamsFile + Write-Host "✅ Updated '$BicepParamsFile' with capacity 200." + } + Set-DeploymentValues $Location $Capacity + Write-Host "✅ Proceeding with '$Location' as selected." + exit 0 + } + } else { + Write-Host "`n✅ Sufficient quota found in original region '$Location'." + Set-DeploymentValues $Location $Capacity + exit 0 + } } else { - Write-Host "`n⚠️ Insufficient quota in '$Location' (Available: $($PrimaryResult.Available), Required: $Capacity). Checking fallback regions..." + Write-Host "`n⚠️ Insufficient quota in '$Location'. Checking fallback regions..." } } else { - Write-Host "`n⚠️ Could not retrieve quota info for region '$Location'. Checking fallback regions..." + Write-Host "`n⚠️ Could not retrieve quota info for region '$Location'." } -# ----------- Check all other fallback regions ----------- -$FallbackRegions = $PreferredRegions | Where-Object { $_ -ne $Location } -$EligibleFallbacks = @() - -foreach ($region in $FallbackRegions) { +# ------------------ Check Fallback Regions ------------------ +foreach ($region in $PreferredRegions) { + if ($region -eq $Location) { continue } $result = Check-Quota -Region $region if ($result) { $AllResults += $result if ($result.Available -ge $Capacity) { - $EligibleFallbacks += $result + $EligibleFallbacks += $region } } } -# ----------- Show Table of All Regions Checked ----------- -$AllResults = $AllResults | Where-Object { $_.Available -gt 50 } Show-Table -# ----------- If eligible fallback regions found, ask user ----------- if ($EligibleFallbacks.Count -gt 0) { - Write-Host "`n❌ Deployment cannot proceed in '$Location'." - Write-Host "➡️ Found fallback regions with sufficient quota." - - while ($true) { - Write-Host "`nPlease enter a fallback region from the list above to proceed:" - $NewLocation = Read-Host "Enter region" - - if (-not $NewLocation) { - Write-Host "❌ No location entered. Exiting." - exit 1 + Write-Host "`n➡️ Found fallback regions with sufficient quota." + if ($RecommendedRegions.Count -gt 0) { + Write-Host "`nℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available):" + foreach ($region in $RecommendedRegions) { + Write-Host " - $region" } + } +} - $UserResult = Check-Quota -Region $NewLocation - if (-not $UserResult) { - Write-Host "⚠️ Could not retrieve quota info for region '$NewLocation'. Try again." - continue - } +# ------------------ Manual Prompt if No Quota Found ------------------ +Write-Host "`n❌ ERROR: No region has sufficient quota." - if ($UserResult.Available -ge $Capacity) { - Write-Host "✅ Sufficient quota found in '$NewLocation'. Proceeding with deployment." - azd env set AZURE_AISERVICE_LOCATION "$NewLocation" | Out-Null - Write-Host "➡️ Set AZURE_AISERVICE_LOCATION to '$NewLocation'." - exit 0 - } else { - Write-Host "❌ Insufficient quota in '$NewLocation'. Try another." +while ($true) { + $ManualRegion = Read-Host "`nPlease enter a region you want to try manually" + if (-not $ManualRegion) { + Write-Host "❌ ERROR: No region entered. Exiting." + exit 1 + } + + $ManualCapacityStr = Read-Host "Enter the capacity you want to use (numeric value)" + if (-not ($ManualCapacityStr -as [int]) -or [int]$ManualCapacityStr -le 0) { + Write-Host "❌ Invalid capacity value. Try again." + continue + } + + $ManualCapacity = [int]$ManualCapacityStr + $ManualResult = Check-Quota -Region $ManualRegion + + if (-not $ManualResult) { + Write-Host "⚠️ Could not retrieve quota info for region '$ManualRegion'. Try again." + continue + } + + if ($ManualResult.Available -ge $ManualCapacity) { + if ($ManualResult.Available -lt $RECOMMENDED_TOKENS) { + Write-Host "`n⚠️ Region '$ManualRegion' has less than recommended ($RECOMMENDED_TOKENS) tokens." + $proceed = Read-Host "❓ Proceed anyway? (y/n)" + if ($proceed -notmatch "^[Yy]$") { + continue + } } + + Set-DeploymentValues $ManualRegion $ManualCapacity + Write-Host "✅ Deployment values set. Exiting." + exit 0 + } else { + Write-Host "❌ Quota in region '$ManualRegion' is insufficient. Available: $($ManualResult.Available), Required: $ManualCapacity" } } - -Write-Error "`n❌ ERROR: No available quota found in any region." -exit 1 \ No newline at end of file diff --git a/scripts/validate_model_quota.sh b/scripts/validate_model_quota.sh index 9b8e243..ad8306a 100644 --- a/scripts/validate_model_quota.sh +++ b/scripts/validate_model_quota.sh @@ -4,78 +4,67 @@ LOCATION="" MODEL="" DEPLOYMENT_TYPE="Standard" CAPACITY=0 +RECOMMENDED_TOKENS=200 ALL_REGIONS=('australiaeast' 'eastus' 'eastus2' 'francecentral' 'japaneast' 'norwayeast' 'southindia' 'swedencentral' 'uksouth' 'westus' 'westus3') -# -------------------- Parse Args -------------------- -while [[ $# -gt 0 ]]; do - case "$1" in - --model) - MODEL="$2" - shift 2 - ;; - --capacity) - CAPACITY="$2" - shift 2 - ;; - --deployment-type) - DEPLOYMENT_TYPE="$2" - shift 2 - ;; - --location) - LOCATION="$2" - shift 2 - ;; - *) - echo "❌ ERROR: Unknown option: $1" - exit 1 - ;; - esac -done +# Globals for recommended/not recommended regions +RECOMMENDED_REGIONS=() +NOT_RECOMMENDED_REGIONS=() +ALL_RESULTS=() +FALLBACK_RESULTS=() -# -------------------- Validate Inputs -------------------- -MISSING_PARAMS=() -[[ -z "$LOCATION" ]] && MISSING_PARAMS+=("location") -[[ -z "$MODEL" ]] && MISSING_PARAMS+=("model") -[[ "$CAPACITY" -le 0 ]] && MISSING_PARAMS+=("capacity") +# -------------------- Utility: Update .env and main.parameters.json -------------------- +update_env_and_parameters() { + local new_location="$1" + local new_capacity="$2" -if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then - echo "❌ ERROR: Missing or invalid parameters: ${MISSING_PARAMS[*]}" - echo "Usage: $0 --location --model --capacity [--deployment-type ]" - exit 1 -fi + echo "➡️ Updating environment and parameters with Location='$new_location' and Capacity='$new_capacity'..." -if [[ "$DEPLOYMENT_TYPE" != "Standard" && "$DEPLOYMENT_TYPE" != "GlobalStandard" ]]; then - echo "❌ ERROR: Invalid deployment type: $DEPLOYMENT_TYPE. Allowed values: 'Standard', 'GlobalStandard'." - exit 1 -fi + # Update the AZD environment + azd env set AZURE_AISERVICE_LOCATION "$new_location" + azd env set AZURE_ENV_MODEL_CAPACITY "$new_capacity" -MODEL_TYPE="OpenAI.$DEPLOYMENT_TYPE.$MODEL" -ALL_RESULTS=() -FALLBACK_RESULTS=() -ROW_NO=1 + # Update main.parameters.json + local PARAM_FILE="./infra/main.parameters.json" + if [[ ! -f "$PARAM_FILE" ]]; then + echo "❌ ERROR: $PARAM_FILE not found, cannot update parameters." + return 1 + fi -# Print validating message only once -echo "🔍 Checking quota in the requested region '$LOCATION' for the Model '$MODEL'..." + jq --arg loc "$new_location" \ + '.parameters.location.value = $loc' "$PARAM_FILE" > "${PARAM_FILE}.tmp" && mv "${PARAM_FILE}.tmp" "$PARAM_FILE" + + jq --argjson cap "$new_capacity" --arg model "$MODEL" \ + '(.parameters.aiModelDeployments.value[] | select(.name == $model) | .sku.capacity) |= $cap' "$PARAM_FILE" > "${PARAM_FILE}.tmp" && mv "${PARAM_FILE}.tmp" "$PARAM_FILE" + + echo "✅ Updated .env and $PARAM_FILE successfully." +} # -------------------- Function: Check Quota -------------------- check_quota() { local region="$1" + local MODEL_TYPE="OpenAI.$DEPLOYMENT_TYPE.$MODEL" local output + output=$(az cognitiveservices usage list --location "$region" --query "[?name.value=='$MODEL_TYPE']" --output json 2>/dev/null) if [[ -z "$output" || "$output" == "[]" ]]; then return 2 # No data fi - local CURRENT_VALUE - local LIMIT - CURRENT_VALUE=$(echo "$output" | jq -r '.[0].currentValue // 0' | cut -d'.' -f1) - LIMIT=$(echo "$output" | jq -r '.[0].limit // 0' | cut -d'.' -f1) + local CURRENT_VALUE=$(echo "$output" | jq -r '.[0].currentValue // 0' | cut -d'.' -f1) + local LIMIT=$(echo "$output" | jq -r '.[0].limit // 0' | cut -d'.' -f1) local AVAILABLE=$((LIMIT - CURRENT_VALUE)) ALL_RESULTS+=("$region|$LIMIT|$CURRENT_VALUE|$AVAILABLE") + if [[ "$AVAILABLE" -ge "$RECOMMENDED_TOKENS" ]]; then + RECOMMENDED_REGIONS+=("$region") + else + NOT_RECOMMENDED_REGIONS+=("$region") + fi + if [[ "$AVAILABLE" -ge "$CAPACITY" ]]; then return 0 else @@ -83,86 +72,168 @@ check_quota() { fi } -# -------------------- Check User-Specified Region -------------------- -check_quota "$LOCATION" -primary_status=$? +# -------------------- Input Validation -------------------- +while [[ $# -gt 0 ]]; do + case "$1" in + --model) + MODEL="$2"; shift 2 ;; + --capacity) + CAPACITY="$2"; shift 2 ;; + --deployment-type) + DEPLOYMENT_TYPE="$2"; shift 2 ;; + --location) + LOCATION="$2"; shift 2 ;; + *) + echo "❌ ERROR: Unknown option: $1"; exit 1 ;; + esac +done -if [[ $primary_status -eq 2 ]]; then - echo -e "\n⚠️ Could not retrieve quota info for region: '$LOCATION'." +[[ -z "$LOCATION" ]] && MISSING_PARAMS+=("location") +[[ -z "$MODEL" ]] && MISSING_PARAMS+=("model") +if ! [[ "$CAPACITY" =~ ^[0-9]+$ ]] || [[ "$CAPACITY" -le 0 ]]; then + MISSING_PARAMS+=("capacity") +fi + +if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then + echo "❌ ERROR: Missing/invalid: ${MISSING_PARAMS[*]}" + echo "Usage: $0 --location --model --capacity [--deployment-type ]" exit 1 fi +if [[ "$DEPLOYMENT_TYPE" != "Standard" && "$DEPLOYMENT_TYPE" != "GlobalStandard" ]]; then + echo "❌ ERROR: Invalid deployment type: $DEPLOYMENT_TYPE" + exit 1 +fi + +# -------------------- Main Logic Starts -------------------- +echo "🔍 Checking quota in '$LOCATION' for model '$MODEL'..." + +check_quota "$LOCATION" +primary_status=$? + if [[ $primary_status -eq 1 ]]; then - # Get available quota from ALL_RESULTS for LOCATION to use in warning primary_entry="${ALL_RESULTS[0]}" IFS='|' read -r _ limit used available <<< "$primary_entry" echo -e "\n⚠️ Insufficient quota in '$LOCATION' (Available: $available, Required: $CAPACITY). Checking fallback regions..." fi -# -------------------- Check Fallback Regions -------------------- for region in "${ALL_REGIONS[@]}"; do [[ "$region" == "$LOCATION" ]] && continue check_quota "$region" - if [[ $? -eq 0 ]]; then - FALLBACK_RESULTS+=("$region") - fi + [[ $? -eq 0 ]] && FALLBACK_RESULTS+=("$region") done -# -------------------- Print Results Table -------------------- +# -------------------- Quota Table Output -------------------- echo "" printf "%-5s | %-16s | %-33s | %-6s | %-6s | %-9s\n" "No." "Region" "Model Name" "Limit" "Used" "Available" printf -- "---------------------------------------------------------------------------------------------\n" index=1 +REGIONS_WITH_QUOTA=() for result in "${ALL_RESULTS[@]}"; do IFS='|' read -r region limit used available <<< "$result" - if [[ "$available" -gt 50 ]]; then - printf "| %-3s | %-16s | %-33s | %-6s | %-6s | %-9s |\n" "$index" "$region" "$MODEL_TYPE" "$limit" "$used" "$available" + if (( available >= 50 )); then + printf "| %-3s | %-16s | %-33s | %-6s | %-6s | %-9s |\n" "$index" "$region" "OpenAI.$DEPLOYMENT_TYPE.$MODEL" "$limit" "$used" "$available" + REGIONS_WITH_QUOTA+=("$region|$available") ((index++)) fi done -printf -- "-------------------------------------------------------------------------------------------------------------\n" +printf -- "---------------------------------------------------------------------------------------------\n" -# -------------------- Output Result -------------------- -if [[ $primary_status -eq 0 ]]; then - echo -e "\n✅ Sufficient quota found in original region '$LOCATION'." +# -------------------- Prompt if No Region Has Enough -------------------- +if [[ $primary_status -ne 0 && ${#FALLBACK_RESULTS[@]} -eq 0 ]]; then + echo -e "\n❌ No region has sufficient quota (≥ $CAPACITY tokens)." + + max_available=0; max_region="" + for result in "${ALL_RESULTS[@]}"; do + IFS='|' read -r region limit used available <<< "$result" + if (( available > max_available )); then + max_available=$available + max_region=$region + fi + done + + if (( max_available == 0 )); then + echo "⚠️ No quota info from any region. Cannot proceed." + exit 1 + fi + + echo "➡️ Highest available quota: $max_available tokens in '$max_region'." + echo -n "❓ Enter new capacity to use (<= $max_available): " + read -r new_capacity < /dev/tty + + if ! [[ "$new_capacity" =~ ^[0-9]+$ ]] || (( new_capacity > max_available )) || (( new_capacity <= 0 )); then + echo "❌ Invalid capacity entered. Exiting." + exit 1 + fi + + echo -n "❓ Enter location to use (default: $max_region): " + read -r new_location < /dev/tty + new_location="${new_location:-$max_region}" + + CAPACITY=$new_capacity + LOCATION=$new_location + + check_quota "$LOCATION" + [[ $? -eq 0 ]] || { echo "❌ Insufficient quota in '$LOCATION'. Exiting."; exit 1; } + + update_env_and_parameters "$LOCATION" "$CAPACITY" + echo "✅ Deployment settings updated." exit 0 fi - -# Function: Ask user for location and validate quota +# -------------------- Handle Fallback Prompt -------------------- ask_for_location() { - echo "Please enter any other location from the above table where you want to deploy AI Services:" - read LOCATION < /dev/tty + echo -e "\nPlease choose a region from the above list:" + echo -n "📍 Enter region: " + read -r new_location < /dev/tty - # Validate user input - if [[ -z "$LOCATION" ]]; then + if [[ -z "$new_location" ]]; then echo "❌ ERROR: No location entered. Exiting." exit 1 fi - echo "🔍 Checking quota in '$LOCATION'..." - check_quota "$LOCATION" - user_region_status=$? + echo -n "🔢 Enter capacity (tokens): " + read -r new_capacity < /dev/tty - if [[ $user_region_status -eq 0 ]]; then - echo "✅ Sufficient quota found in '$LOCATION'. Proceeding with deployment." - azd env set AZURE_AISERVICE_LOCATION "$LOCATION" - echo "➡️ Set AZURE_AISERVICE_LOCATION to '$LOCATION'." + if ! [[ "$new_capacity" =~ ^[0-9]+$ ]] || (( new_capacity <= 0 )); then + echo "❌ Invalid capacity entered." + ask_for_location + return + fi + + CAPACITY=$new_capacity + LOCATION=$new_location + + check_quota "$LOCATION" + if [[ $? -eq 0 ]]; then + update_env_and_parameters "$LOCATION" "$CAPACITY" + echo "✅ Updated and ready to deploy in '$LOCATION'." exit 0 - elif [[ $user_region_status -eq 2 ]]; then - echo "⚠️ Could not retrieve quota info for region: '$LOCATION'. Exiting." - exit 1 else - echo "❌ Insufficient quota in '$LOCATION'." - ask_for_location # **Recursively call the function until valid input is provided** + echo "❌ Insufficient quota in '$LOCATION'. Try another." + ask_for_location fi } -# Main Logic -if [[ ${#FALLBACK_RESULTS[@]} -gt 0 ]]; then - echo -e "\n❌ Deployment cannot proceed in this location: '$LOCATION'." - echo "➡️ Found fallback regions with sufficient quota." - - ask_for_location # **Call function to prompt user for input** -fi \ No newline at end of file +# -------------------- Final Decision Logic -------------------- +if [[ $primary_status -eq 0 ]]; then + if [[ " ${NOT_RECOMMENDED_REGIONS[*]} " == *" $LOCATION "* ]]; then + echo -e "\n⚠️ Region '$LOCATION' is not recommended (available < $RECOMMENDED_TOKENS)." + echo -n "❓ Proceed anyway? (y/n): " + read -r proceed < /dev/tty + if [[ "$proceed" =~ ^[Yy]$ ]]; then + update_env_and_parameters "$LOCATION" "$CAPACITY" + echo "✅ Proceeding with '$LOCATION'." + exit 0 + else + ask_for_location + fi + else + update_env_and_parameters "$LOCATION" "$CAPACITY" + echo "✅ Quota is sufficient in '$LOCATION'. Proceeding." + exit 0 + fi +else + ask_for_location +fi From 5c5dfbc0b9689210698b5ffffe2584610bd959d3 Mon Sep 17 00:00:00 2001 From: Priyanka-Microsoft Date: Fri, 13 Jun 2025 17:32:24 +0530 Subject: [PATCH 2/2] updated the recommended list --- scripts/validate_model_quota.ps1 | 1 + scripts/validate_model_quota.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/validate_model_quota.ps1 b/scripts/validate_model_quota.ps1 index e873a3d..e151628 100644 --- a/scripts/validate_model_quota.ps1 +++ b/scripts/validate_model_quota.ps1 @@ -110,6 +110,7 @@ if ($PrimaryResult) { Write-Host "`n⚠️ Selected region '$Location' has sufficient quota but is not among the recommended regions (≥ $RECOMMENDED_TOKENS tokens)." Write-Host "🚨 Your application may not work as expected due to limited quota." Write-Host "`nℹ️ Recommended regions: $($RecommendedRegions -join ', ')" + Write-Host "👉 It's advisable to deploy in one of these regions for optimal app performance." $choice = Read-Host "❓ Do you want to choose a recommended region instead? (y/n)" if ($choice -match "^[Yy]$") { Show-Table diff --git a/scripts/validate_model_quota.sh b/scripts/validate_model_quota.sh index ad8306a..b1ca2bf 100644 --- a/scripts/validate_model_quota.sh +++ b/scripts/validate_model_quota.sh @@ -218,8 +218,15 @@ ask_for_location() { # -------------------- Final Decision Logic -------------------- if [[ $primary_status -eq 0 ]]; then + if [[ " ${NOT_RECOMMENDED_REGIONS[*]} " == *" $LOCATION "* ]]; then - echo -e "\n⚠️ Region '$LOCATION' is not recommended (available < $RECOMMENDED_TOKENS)." + recommended_list=$(IFS=, ; echo "${RECOMMENDED_REGIONS[*]}") + bold_regions=$(printf "\033[1m%s\033[0m" "$recommended_list") + echo -e "\n⚠️ \033[1mWarning:\033[0m Region '$LOCATION' has available tokens less than the recommended threshold ($RECOMMENDED_TOKENS)." + echo -e "🚨 Your application may not work as expected due to limited quota." + echo -e "\nℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): $bold_regions" + echo -e "👉 It's advisable to deploy in one of these regions for optimal app performance." + echo -n "❓ Proceed anyway? (y/n): " read -r proceed < /dev/tty if [[ "$proceed" =~ ^[Yy]$ ]]; then