From 6ab87107d4aa31a9d5daaea45cb8fcc1154124fa Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 4 Dec 2023 12:24:51 +0900 Subject: [PATCH] Add pwsh script to get list of OpenAI instances (#9) --- .github/workflows/azure-dev.yml | 3 +- .gitignore | 1 + biceps/Get-OpenAIDetails.ps1 | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 biceps/Get-OpenAIDetails.ps1 diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index ebadbc24..dc6b5f92 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -85,8 +85,9 @@ jobs: $name = $_ $endpoint = az cognitiveservices account show -g rg-${{ vars.AZURE_ENV_NAME }} -n $name --query "properties.endpoint" -o tsv $apiKey = az cognitiveservices account keys list -g rg-${{ vars.AZURE_ENV_NAME }} -n $name --query "key1" -o tsv + $deploymentName = az cognitiveservices account deployment list -g rg-${{ vars.AZURE_ENV_NAME }} -n $name --query "[].name" -o tsv - $instance = @{ Endpoint = $endpoint; ApiKey = $apiKey; } + $instance = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentName = $deploymentName } $instances += $instance } diff --git a/.gitignore b/.gitignore index c981788f..60c94a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -501,3 +501,4 @@ resources.bicep # Aspire aspire-manifest.json +instances*.json diff --git a/biceps/Get-OpenAIDetails.ps1 b/biceps/Get-OpenAIDetails.ps1 new file mode 100644 index 00000000..1e4372d3 --- /dev/null +++ b/biceps/Get-OpenAIDetails.ps1 @@ -0,0 +1,64 @@ +# Gets list of the Azure OpenAI instances with specific deployment name +Param( + [string] + [Parameter(Mandatory=$false)] + $EnvironmentName = $null, + + [string] + [Parameter(Mandatory=$false)] + $DeploymentName = $null, + + [switch] + [Parameter(Mandatory=$false)] + $Help +) + +function Show-Usage { + Write-Output " This gets list of the Azure OpenAI instances with specific deployment name + + Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) `` + [-EnvironmentName ] `` + [-DeploymentName ] `` + + [-Help] + + Options: + -EnvironmentName Azure environment name. + -DeploymentName Azure OpenAI deployment name. + + -Help: Show this message. +" + + Exit 0 +} + +# Show usage +$needHelp = $Help -eq $true +if ($needHelp -eq $true) { + Show-Usage + Exit 0 +} + +if ($EnvironmentName -eq $null) { + Show-Usage + Exit 0 +} + +$rg = "rg-$EnvironmentName" + +$openAIs = az resource list -g $rg --query "[?type=='Microsoft.CognitiveServices/accounts'].name" | ConvertFrom-Json | Sort-Object +if ($DeploymentName -ne $null) { + $openAIs = $openAIs | Where-Object { $_ -like "*$DeploymentName*" } +} + +$instances = @() +$openAIs | ForEach-Object { + $name = $_ + $endpoint = az cognitiveservices account show -g $rg -n $name --query "properties.endpoint" -o tsv + $apiKey = az cognitiveservices account keys list -g $rg -n $name --query "key1" -o tsv + + $instance = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentName = $DeploymentName } + $instances += $instance +} + +$instances | ConvertTo-Json -Depth 100 | Out-File -FilePath ./biceps/instances-$DeploymentName.json -Encoding utf8 -Force