Skip to content

Commit

Permalink
Add ps1 script for AOAI instance provision
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo committed Feb 12, 2024
1 parent b847613 commit 6f26025
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ appsettings.Production.json
# azd
.azure

# biceps
model-*.json

# azd infra synth
manifests
next-steps.md
Expand Down
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,42 @@ This provides a proxy server application of Azure OpenAI Service API that round-

## Prerequisites

- .NET SDK 8.0 or later + Aspire workload
- .NET SDK 8.0.100 or later + Aspire workload
- Visual Studio 2022 17.9+ or Visual Studio Code + C# DevKit
- Azure Subscription
- Azure OpenAI Subscription

## Getting Started

1. Run PowerShell script to prepare AOAI instance locations and models – `ADA`, `GPT 3.5 Turbo 16K`, `GPT 4 32K` and `DALL-E 3`.

```powershell
$RESOURCE_GROUP_LOCATION = "{{ RESOURCE_GROUP_LOCATION }}"
$AZURE_ENV_NAME = "{{ AZURE_ENVIRONMENT_NAME }}"
# Text embedding with Ada
./biceps/Get-OpenAILocations.ps1 -ResourceGroupLocation $RESOURCE_GROUP_LOCATION -AzureEnvironmentName $AZURE_ENV_NAME -ModelName "text-embedding-ada-002" -ModelVersion "2"
# GPT 3.5 Turbo 16K
./biceps/Get-OpenAILocations.ps1 -ResourceGroupLocation $RESOURCE_GROUP_LOCATION -AzureEnvironmentName $AZURE_ENV_NAME -ModelName "gpt-35-turbo-16k" -ModelVersion "0613"
# GPT 4 32K
./biceps/Get-OpenAILocations.ps1 -ResourceGroupLocation $RESOURCE_GROUP_LOCATION -AzureEnvironmentName $AZURE_ENV_NAME -ModelName "gpt-4-32k" -ModelVersion "0613"
# DALL-E 3.0
./biceps/Get-OpenAILocations.ps1 -ResourceGroupLocation $RESOURCE_GROUP_LOCATION -AzureEnvironmentName $AZURE_ENV_NAME -ModelName "dall-e-3" -ModelVersion "3.0"
```

1. azd init
2. azd provision
3. azd pipeline config
4. Set-GitHubActionsVariables.ps1
5. Run-PostProvision.ps1
6. azd deploy
1. azd provision
1. azd pipeline config
1. Set-GitHubActionsVariables.ps1
1. Run-PostProvision.ps1
1. azd deploy

7. Create a new event
8. Create a new access code that belongs to the event
1. Create a new event
1. Create a new access code that belongs to the event

9. azd down
10. Purge-CognitiveServices.ps1
1. azd down
1. Purge-CognitiveServices.ps1

2 changes: 1 addition & 1 deletion biceps/Get-OpenAIDetails.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ $openAIs | ForEach-Object {
$instances += $instance
}

$instances | ConvertTo-Json -Depth 100 | Out-File -FilePath ./biceps/instances-$DeploymentName.json -Encoding utf8 -Force
$instances | ConvertTo-Json -Depth 100 | Out-File -FilePath "./biceps/instances-$($DeploymentName).json" -Encoding utf8 -Force
125 changes: 125 additions & 0 deletions biceps/Get-OpenAILocations.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Gets list of the available locations for Azure OpenAI Services and available models on repective locations
Param(
[string]
[Parameter(Mandatory=$false)]
$ResourceGroupLocation = "koreacentral",

[string]
[Parameter(Mandatory=$false)]
$AzureEnvironmentName = "aoai-collection",

[string]
[Parameter(Mandatory=$false)]
$ModelName = "gpt-4-32k",

[string]
[Parameter(Mandatory=$false)]
$ModelVersion = "0613",

[string]
[Parameter(Mandatory=$false)]
$ApiVersion = "2023-05-01",

[switch]
[Parameter(Mandatory=$false)]
$Help
)

function Show-Usage {
Write-Output " This gets list of the available locations for Azure OpenAI Services and available models on repective locations
Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) ``
[-ResourceGroupLocation <Resource group location>] ``
[-AzureEnvironmentName <Azure environment name>] ``
[-ModelName <Azure OpenAI model name>] ``
[-ModelVersion <Azure OpenAI model version>] ``
[-ApiVersion <API version>] ``
[-Help]
Options:
-ResourceGroupLocation Resource group name. Default value is `'koreacentral`'
-AzureEnvironmentName Azure eovironment name. Default value is `'aoai-collection`'
-ModelName Azure OpenAI model name. Default value is `'gpt-4-32k`'
-ModelVersion Azure OpenAI model version. Default value is `'0613`'
-ApiVersion API version. Default value is `'2023-05-01`'
-Help: Show this message.
"

Exit 0
}

# Show usage
$needHelp = $Help -eq $true
if ($needHelp -eq $true) {
Show-Usage
Exit 0
}

if (($ResourceGroupLocation -eq $null) -or ($AzureEnvironmentName -eq $null) -or ($ModelName -eq $null) -or ($ModelVersion -eq $null) -or ($ApiVersion -eq $null)) {
Show-Usage
Exit 0
}

$resourceGroupName = "rg-$AzureEnvironmentName"

$resourceGroupExists = az group exists -n $resourceGroupName
if ($resourceGroupExists -eq $false) {
$rg = az group create -n $resourceGroupName -l $ResourceGroupLocation
}

$subscriptionId = az account show --query "id" -o tsv
$url = "/subscriptions/$subscriptionId/providers/Microsoft.CognitiveServices"

$locations = az rest --method GET `
--uri "$url/skus?api-version=$ApiVersion" `
--query "value[?kind=='OpenAI'] | [?resourceType == 'accounts'].locations[0]" | ConvertFrom-Json

$locations | ForEach-Object {
$location = $_.ToLowerInvariant()

$models = az rest --method GET `
--uri "$url/locations/$location/models?api-version=$ApiVersion" `
--query "sort_by(value[?kind == 'OpenAI'].{ name: model.name, version: model.version, skus: model.skus }, &name)" | ConvertFrom-Json

$model = $models | Where-Object { $_.name -eq $ModelName -and $_.version -eq $ModelVersion -and $_.skus.Count -gt 0 -and $_.skus[0].name -eq "Standard" }
if ($model -ne $null) {
$cogsvc = az cognitiveservices account list -g $ResourceGroupName --query "[?location=='$location']" | ConvertFrom-Json
if ($cogsvc -eq $null) {
$cogsvc = az cognitiveservices account create `
-g $resourceGroupName `
-n "cogsvc-$AzureEnvironmentName-$location" `
-l $location `
--kind OpenAI `
--sku S0 `
--tags azd-env-name=$AzureEnvironmentName

Write-Output "$($cogsvc.name) instance has been provisioned"
}

$modelNameShortened = $ModelName.Replace("-", "").Replace(".", "")
$modelVersionShortened = $ModelVersion.Replace("-", "").Replace(".", "")
$deploymentName = "model-$modelNameShortened-$modelVersionShortened"
$capacity = $ModelName -eq "dall-e-3" ? 1 : 4

$deployment = az cognitiveservices account deployment list `
-g $resourceGroupName `
-n "cogsvc-$AzureEnvironmentName-$location" `
--query "[?name=='$deploymentName']" | ConvertFrom-Json

if ($deployment -eq $null) {
$deployment = az cognitiveservices account deployment create `
-g $resourceGroupName `
-n "cogsvc-$AzureEnvironmentName-$location" `
--model-format OpenAI `
--model-name $ModelName `
--model-version $ModelVersion `
--deployment-name $deploymentName `
--sku-name Standard `
--sku-capacity $capacity

Write-Output "$deploymentName on the $($cogsvc.name) instance has been deployed"
}
}
}

0 comments on commit 6f26025

Please sign in to comment.