From 40ac1e2831eb7ddcfdf4dae684322bd8edd5206d Mon Sep 17 00:00:00 2001 From: brandom-msft Date: Wed, 24 Apr 2024 15:29:33 -0700 Subject: [PATCH 1/7] Add bicep files for Azure OpenAI resource provisioning --- Backend/bicep/abbreviations.json | 4 +++ Backend/bicep/ai.bicep | 48 +++++++++++++++++++++++++++ Backend/bicep/main.bicep | 52 ++++++++++++++++++++++++++++++ Backend/bicep/main.parameters.json | 18 +++++++++++ 4 files changed, 122 insertions(+) create mode 100644 Backend/bicep/abbreviations.json create mode 100644 Backend/bicep/ai.bicep create mode 100644 Backend/bicep/main.bicep create mode 100644 Backend/bicep/main.parameters.json diff --git a/Backend/bicep/abbreviations.json b/Backend/bicep/abbreviations.json new file mode 100644 index 0000000..7e9ecd2 --- /dev/null +++ b/Backend/bicep/abbreviations.json @@ -0,0 +1,4 @@ +{ + "keyVaultVaults": "kv-", + "resourcesResourceGroups": "rg-" +} diff --git a/Backend/bicep/ai.bicep b/Backend/bicep/ai.bicep new file mode 100644 index 0000000..055ff97 --- /dev/null +++ b/Backend/bicep/ai.bicep @@ -0,0 +1,48 @@ +param name string +param location string +param deployments array = [ + { + name: 'chat' + model: { + format: 'OpenAI' + name: 'gpt-4' + version: '0613' + } + sku: { + capacity: 1000 + } + } +] + +@description('') +resource azureOpenAiResource 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = { + name: name + location: location + sku: { + name: 'S0' + } + kind: 'OpenAI' + tags: {} + properties: { + // customSubDomainName: needed? + networkAcls: { + defaultAction: 'Allow' + virtualNetworkRules: [] + ipRules: [] + } + publicNetworkAccess: 'Enabled' + } +} + +resource modelDeployments 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [for item in deployments: { + parent: azureOpenAiResource + name: item.name + sku: (contains(item, 'sku') ? item.sku : { + name: 'Standard' + capacity: item.capacity + }) + properties: { + model: item.model + raiPolicyName: (contains(item, 'raiPolicyName') ? item.raiPolicyName : null) + } +}] diff --git a/Backend/bicep/main.bicep b/Backend/bicep/main.bicep new file mode 100644 index 0000000..ef42b66 --- /dev/null +++ b/Backend/bicep/main.bicep @@ -0,0 +1,52 @@ +targetScope='subscription' + +// The main bicep module to provision Azure resources. +// For a more complete walkthrough to understand how this file works with azd, +// see https://learn.microsoft.com/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-create + +var abbrs = loadJsonContent('./abbreviations.json') + +// Optional parameters to override the default azd resource naming conventions. +// Add the following to main.parameters.json to provide values: +// "resourceGroupName": { +// "value": "myGroupName" +// } +param resourceGroupName string = '' +param azureOpenAIServiceName string = '' + +@minLength(1) +@maxLength(64) +@description('Name of the environment which is used to generate a short, unique hash used in all resources.') +// For an overview on this and other key Azure concepts, +// see https://learn.microsoft.com/azure/deployment-environments/concept-environments-key-concepts#environments +param environmentName string + +// tags that will be applied to all resources. +var tags = { + // Tag all resources with the environment name. + 'azd-env-name': environmentName +} + +@description('Location of all resources') +param location string + +// Generate a unique token to be used in naming resources. +// Remove linter suppression after using. +#disable-next-line no-unused-vars +var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) + +// Resources are organized in a resource group +resource rg 'Microsoft.Resources/resourceGroups@2022-09-01' = { + name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}' + location: location + tags: tags +} + +module azureOpenAi 'ai.bicep' = { + name: 'azureOpenAi' + params: { + name: !empty(azureOpenAIServiceName) ? azureOpenAIServiceName : 'aoai-${resourceToken}' + location: location + } + scope: rg +} diff --git a/Backend/bicep/main.parameters.json b/Backend/bicep/main.parameters.json new file mode 100644 index 0000000..3b4323c --- /dev/null +++ b/Backend/bicep/main.parameters.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "environmentName": { + "value": "${AZURE_ENV_NAME}" + }, + "location": { + "value": "${AZURE_LOCATION}" + }, + "resourceGroupName": { + "value": "${AZURE_RESOURCE_GROUP}" + }, + "openAiServiceName": { + "value": "${AZURE_OPENAI_SERVICE}" + } + } +} \ No newline at end of file From 3031f8d51c42ed4bde8e6c42aaae20d6bb5c9c1c Mon Sep 17 00:00:00 2001 From: brandom-msft Date: Wed, 24 Apr 2024 15:41:02 -0700 Subject: [PATCH 2/7] Update Azure OpenAI resource endpoint outputs in bicep files --- Backend/bicep/ai.bicep | 2 ++ Backend/bicep/main.bicep | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Backend/bicep/ai.bicep b/Backend/bicep/ai.bicep index 055ff97..118fa58 100644 --- a/Backend/bicep/ai.bicep +++ b/Backend/bicep/ai.bicep @@ -46,3 +46,5 @@ resource modelDeployments 'Microsoft.CognitiveServices/accounts/deployments@2023 raiPolicyName: (contains(item, 'raiPolicyName') ? item.raiPolicyName : null) } }] + +output endpoint string = azureOpenAiResource.properties.endpoint diff --git a/Backend/bicep/main.bicep b/Backend/bicep/main.bicep index ef42b66..27ebeb1 100644 --- a/Backend/bicep/main.bicep +++ b/Backend/bicep/main.bicep @@ -50,3 +50,5 @@ module azureOpenAi 'ai.bicep' = { } scope: rg } + +output AZURE_OPENAI_ENDPOINT string = azureOpenAi.outputs.endpoint From 18a770c04eccb495c0b85b29b1d5b26d47695937 Mon Sep 17 00:00:00 2001 From: brandom-msft Date: Tue, 30 Apr 2024 22:33:36 +0000 Subject: [PATCH 3/7] simplifying ai bicep setup --- Backend/bicep/ai.bicep | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Backend/bicep/ai.bicep b/Backend/bicep/ai.bicep index 118fa58..c99b96c 100644 --- a/Backend/bicep/ai.bicep +++ b/Backend/bicep/ai.bicep @@ -1,18 +1,16 @@ param name string param location string -param deployments array = [ - { - name: 'chat' - model: { - format: 'OpenAI' - name: 'gpt-4' - version: '0613' - } - sku: { - capacity: 1000 - } +param deployment object = { + name: 'chat' + model: { + format: 'OpenAI' + name: 'gpt-4' + version: '0613' + } + sku: { + capacity: 1 } -] +} @description('') resource azureOpenAiResource 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = { @@ -24,7 +22,7 @@ resource azureOpenAiResource 'Microsoft.CognitiveServices/accounts@2023-10-01-pr kind: 'OpenAI' tags: {} properties: { - // customSubDomainName: needed? + customSubDomainName: name networkAcls: { defaultAction: 'Allow' virtualNetworkRules: [] @@ -34,17 +32,18 @@ resource azureOpenAiResource 'Microsoft.CognitiveServices/accounts@2023-10-01-pr } } -resource modelDeployments 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [for item in deployments: { +resource modelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = { parent: azureOpenAiResource - name: item.name - sku: (contains(item, 'sku') ? item.sku : { + name: deployment.name + sku: (contains(deployment.sku, 'sku') ? deployment.sku : { name: 'Standard' - capacity: item.capacity + capacity: deployment.sku.capacity }) properties: { - model: item.model - raiPolicyName: (contains(item, 'raiPolicyName') ? item.raiPolicyName : null) + model: deployment.model + raiPolicyName: (contains(deployment, 'raiPolicyName') ? deployment.raiPolicyName : null) } -}] +} output endpoint string = azureOpenAiResource.properties.endpoint +output deploymentName string = modelDeployment.name From c1532f4716e539eaf20bb317a0b8df3bef3004c5 Mon Sep 17 00:00:00 2001 From: brandom-msft Date: Tue, 30 Apr 2024 22:34:06 +0000 Subject: [PATCH 4/7] additional output vars from main --- Backend/bicep/main.bicep | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Backend/bicep/main.bicep b/Backend/bicep/main.bicep index 27ebeb1..16a7444 100644 --- a/Backend/bicep/main.bicep +++ b/Backend/bicep/main.bicep @@ -52,3 +52,5 @@ module azureOpenAi 'ai.bicep' = { } output AZURE_OPENAI_ENDPOINT string = azureOpenAi.outputs.endpoint +output AZURE_OPENAI_DEPLOYMENT string = azureOpenAi.outputs.deploymentName +output USE_AZURE_OPENAI bool = true From 8f780ebd8c3fd34f4374c97c2cb92a4cd3fa0c53 Mon Sep 17 00:00:00 2001 From: brandom-msft Date: Tue, 30 Apr 2024 22:34:48 +0000 Subject: [PATCH 5/7] update var usage --- Backend/Services/SemanticKernelApp.cs | 6 +++--- Backend/bicep/main.parameters.json | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Backend/Services/SemanticKernelApp.cs b/Backend/Services/SemanticKernelApp.cs index fb08d6c..1ef0e78 100644 --- a/Backend/Services/SemanticKernelApp.cs +++ b/Backend/Services/SemanticKernelApp.cs @@ -19,11 +19,11 @@ internal struct SemanticKernelConfig internal static async Task CreateAsync(ISecretStore secretStore, CancellationToken cancellationToken) { - var useAzureOpenAI = await secretStore.GetSecretAsync("UseAzureOpenAI", cancellationToken).ContinueWith(task => bool.Parse(task.Result)); + var useAzureOpenAI = await secretStore.GetSecretAsync("USE_AZURE_OPENAI", cancellationToken).ContinueWith(task => bool.Parse(task.Result)); if (useAzureOpenAI) { - var azureDeployment = await secretStore.GetSecretAsync("AzureDeployment", cancellationToken); - var azureEndpoint = await secretStore.GetSecretAsync("AzureEndpoint", cancellationToken); + var azureDeployment = await secretStore.GetSecretAsync("AZURE_OPENAI_DEPLOYMENT", cancellationToken); + var azureEndpoint = await secretStore.GetSecretAsync("AZURE_OPENAI_ENDPOINT", cancellationToken); return new SemanticKernelConfig { diff --git a/Backend/bicep/main.parameters.json b/Backend/bicep/main.parameters.json index 3b4323c..6dbbe86 100644 --- a/Backend/bicep/main.parameters.json +++ b/Backend/bicep/main.parameters.json @@ -13,6 +13,12 @@ }, "openAiServiceName": { "value": "${AZURE_OPENAI_SERVICE}" + }, + "azureOpenAIEndpoint": { + "value": "${AZURE_OPENAI_ENDPOINT}" + }, + "azureOpenAiDeploymentName": { + "value": "${AZURE_OPENAI_DEPLOYMENT}" } } } \ No newline at end of file From 90edba4c8aa800d2d313157d4b5ca4fcc63873f3 Mon Sep 17 00:00:00 2001 From: brandom Date: Tue, 30 Apr 2024 16:00:54 -0700 Subject: [PATCH 6/7] add azd support to devcontainer --- .devcontainer/devcontainer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index df71b1f..df547a6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,8 +9,12 @@ "vscode": { "extensions": [ "ms-dotnettools.csdevkit", - "ms-vscode.vscode-typescript-next" + "ms-vscode.vscode-typescript-next", + "ms-azuretools.vscode-bicep" ] } + }, + "features": { + "ghcr.io/azure/azure-dev/azd:latest": {} } } From 678208df30b71c136851f68cc53610aed424709c Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 1 May 2024 16:26:10 -0700 Subject: [PATCH 7/7] add docker-in-docker for azd --- .devcontainer/devcontainer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index df547a6..d6f5ac4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,6 +15,9 @@ } }, "features": { + // See https://containers.dev/features for list of features + "ghcr.io/devcontainers/features/docker-in-docker:2": { + }, "ghcr.io/azure/azure-dev/azd:latest": {} } }