-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pwsh script to get list of OpenAI instances (#9)
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -501,3 +501,4 @@ resources.bicep | |
|
||
# Aspire | ||
aspire-manifest.json | ||
instances*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |