diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index df71b1f..d6f5ac4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,8 +9,15 @@ "vscode": { "extensions": [ "ms-dotnettools.csdevkit", - "ms-vscode.vscode-typescript-next" + "ms-vscode.vscode-typescript-next", + "ms-azuretools.vscode-bicep" ] } + }, + "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": {} } } diff --git a/Backend/Services/SemanticKernelApp.cs b/Backend/Services/SemanticKernelApp.cs index 18cab54..a266746 100644 --- a/Backend/Services/SemanticKernelApp.cs +++ b/Backend/Services/SemanticKernelApp.cs @@ -21,11 +21,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/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..c99b96c --- /dev/null +++ b/Backend/bicep/ai.bicep @@ -0,0 +1,49 @@ +param name string +param location string +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' = { + name: name + location: location + sku: { + name: 'S0' + } + kind: 'OpenAI' + tags: {} + properties: { + customSubDomainName: name + networkAcls: { + defaultAction: 'Allow' + virtualNetworkRules: [] + ipRules: [] + } + publicNetworkAccess: 'Enabled' + } +} + +resource modelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = { + parent: azureOpenAiResource + name: deployment.name + sku: (contains(deployment.sku, 'sku') ? deployment.sku : { + name: 'Standard' + capacity: deployment.sku.capacity + }) + properties: { + model: deployment.model + raiPolicyName: (contains(deployment, 'raiPolicyName') ? deployment.raiPolicyName : null) + } +} + +output endpoint string = azureOpenAiResource.properties.endpoint +output deploymentName string = modelDeployment.name diff --git a/Backend/bicep/main.bicep b/Backend/bicep/main.bicep new file mode 100644 index 0000000..16a7444 --- /dev/null +++ b/Backend/bicep/main.bicep @@ -0,0 +1,56 @@ +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 +} + +output AZURE_OPENAI_ENDPOINT string = azureOpenAi.outputs.endpoint +output AZURE_OPENAI_DEPLOYMENT string = azureOpenAi.outputs.deploymentName +output USE_AZURE_OPENAI bool = true diff --git a/Backend/bicep/main.parameters.json b/Backend/bicep/main.parameters.json new file mode 100644 index 0000000..6dbbe86 --- /dev/null +++ b/Backend/bicep/main.parameters.json @@ -0,0 +1,24 @@ +{ + "$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}" + }, + "azureOpenAIEndpoint": { + "value": "${AZURE_OPENAI_ENDPOINT}" + }, + "azureOpenAiDeploymentName": { + "value": "${AZURE_OPENAI_DEPLOYMENT}" + } + } +} \ No newline at end of file