Skip to content

Commit

Permalink
Add pwsh script to get list of OpenAI instances (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo authored Dec 4, 2023
1 parent c258b8e commit 6ab8710
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/azure-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,4 @@ resources.bicep

# Aspire
aspire-manifest.json
instances*.json
64 changes: 64 additions & 0 deletions biceps/Get-OpenAIDetails.ps1
Original file line number Diff line number Diff line change
@@ -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 <Azure environment name>] ``
[-DeploymentName <Azure OpenAI deployment name>] ``
[-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

0 comments on commit 6ab8710

Please sign in to comment.