|
| 1 | +# Setting Up Azure Environment for Azure GenAI Cloud Lab |
| 2 | + |
| 3 | +Welcome! This guide will help you set up your Azure environment to complete the activities in the [Azure GenAI](../) directory of the NIH Cloud Lab. We will walk you through the steps required to configure PowerShell, deploy necessary resources using an ARM template, upload local files to Azure Storage Account, and acquire keys and secrets for `.env` variables. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- An active Azure subscription |
| 8 | +- PowerShell installed on your machine (option 1) |
| 9 | +- Azure CLI installed (option 2) |
| 10 | + |
| 11 | +## Steps |
| 12 | + |
| 13 | +### 1. Setting Up the Azure Module in PowerShell |
| 14 | + |
| 15 | +First, you need to install the Azure module in PowerShell to connect to your Azure account. |
| 16 | + |
| 17 | +```powershell |
| 18 | +# Install the Az module (if using PowerShell) |
| 19 | +Install-Module -Name Az -AllowClobber -Force |
| 20 | + |
| 21 | +# Import the Az module (if using Azure CLI) |
| 22 | +Import-Module Az |
| 23 | +``` |
| 24 | + |
| 25 | +### 2. Logging into Azure |
| 26 | + |
| 27 | +You can log into your Azure account either using PowerShell or Azure CLI. |
| 28 | + |
| 29 | +**Using PowerShell** |
| 30 | +```powershell |
| 31 | +# Log into your Azure account |
| 32 | +Connect-AzAccount |
| 33 | +``` |
| 34 | +**Using Azure CLI** |
| 35 | +```powershell |
| 36 | +# Log into your Azure account |
| 37 | +az login |
| 38 | +``` |
| 39 | + |
| 40 | +### 3. Setting Variables |
| 41 | + |
| 42 | +Set the following variables, which you'll need throughout the setup process. |
| 43 | + |
| 44 | +**Using PowerShell** |
| 45 | +```powershell |
| 46 | +# Variables |
| 47 | +$resourceGroupName="nihcloudlabrg" |
| 48 | +$location="eastus2" |
| 49 | +$templateFilePath="Path To ./arm_resources.json" |
| 50 | +$storageAccountName="cloudlabstgacct" |
| 51 | +$containerName="cloudlabdocuments" |
| 52 | +$localFilePath="Path To ../search_documents" |
| 53 | +$searchServiceName="cloudlabsearch" |
| 54 | +$openAIResourceName="cloudlabaoai" |
| 55 | +``` |
| 56 | +**Using Azure CLI** |
| 57 | +```bash |
| 58 | +# Variables |
| 59 | +resourceGroupName="nihcloudlabrg" |
| 60 | +location="eastus2" |
| 61 | +templateFilePath="Path To ./arm_resources.json" |
| 62 | +storageAccountName="cloudlabstgacct" |
| 63 | +containerName="cloudlabdocuments" |
| 64 | +localFilePath="Path To ../search_documents" |
| 65 | +searchServiceName="cloudlabsearch" |
| 66 | +openAIResourceName="cloudlabaoai" |
| 67 | +``` |
| 68 | + |
| 69 | +### 4. Creating an Empty Resource Group |
| 70 | + |
| 71 | +Create an empty resource group where the ARM template will deploy the necessary resources. |
| 72 | + |
| 73 | +**Using PowerShell** |
| 74 | +```powershell |
| 75 | +# Create a resource group |
| 76 | +New-AzResourceGroup -Name $resourceGroupName -Location $location |
| 77 | +``` |
| 78 | +**Using Azure CLI** |
| 79 | +```bash |
| 80 | +# Create a resource group |
| 81 | +az group create --name $resourceGroupName --location $location |
| 82 | +``` |
| 83 | + |
| 84 | +### 5. Deploying the ARM Template |
| 85 | + |
| 86 | +Deploy the [ARM template](/notebooks/GenAI/azure_infra_setup/arm_resources.json) to create the Azure Storage Account, Azure AI Search, and Azure OpenAI resources. |
| 87 | + |
| 88 | +***Using PowerShell*** |
| 89 | +```powershell |
| 90 | +# Deploy the ARM template |
| 91 | +New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath |
| 92 | +``` |
| 93 | +***Using Azure CLI*** |
| 94 | +```bash |
| 95 | +# Deploy the ARM template |
| 96 | +az deployment group create --resource-group $resourceGroupName --template-file $templateFilePath |
| 97 | +``` |
| 98 | + |
| 99 | +### 6. Uploading Local Files to Azure Storage |
| 100 | + |
| 101 | +Upload your local files to the blob container in the Azure Storage Account. |
| 102 | + |
| 103 | +**Using PowerShell** |
| 104 | +```powershell |
| 105 | +# Get storage account context |
| 106 | +$storageContext = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName).Context |
| 107 | + |
| 108 | +# Upload all files in the directory |
| 109 | +Get-ChildItem -Path $localFilePath -File | ForEach-Object { |
| 110 | + Set-AzStorageBlobContent -File $_.FullName -Container $containerName -Context $storageContext |
| 111 | +} |
| 112 | +``` |
| 113 | +**Using Azure CLI** |
| 114 | +```bash |
| 115 | +# Get storage account key |
| 116 | +storageAccountKey=$(az storage account keys list --resource-group $resourceGroupName --account-name $storageAccountName --query "[0].value" --output tsv) |
| 117 | + |
| 118 | +# Upload all files in the directory |
| 119 | +for file in localFilePath/*; do |
| 120 | + az storage blob upload --account-name $storageAccountName --account-key $storageAccountKey --container-name $containerName --file file --name (basename file) |
| 121 | +done |
| 122 | +``` |
| 123 | + |
| 124 | +### 7. Retrieving API Keys |
| 125 | + |
| 126 | +Retrieve the API keys for each service created by the ARM template deployment. These secrets are confidential and should be handled appropriately. Once the output is received, the values will be added to your `.env` file, which should be created in the ./notebooks/GenAI directory. Note that this `.env` file is already added to the `.gitignore`. |
| 127 | + |
| 128 | +**Azure Storage Account** |
| 129 | + |
| 130 | +***Using PowerShell*** |
| 131 | +```powershell |
| 132 | +# Get the storage account key |
| 133 | +$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName)[0].Value |
| 134 | +# Construct the Blob connection string |
| 135 | +$connectionString = "DefaultEndpointsProtocol=https;AccountName=$storageAccountName;AccountKey=$storageAccountKey;EndpointSuffix=core.windows.net" |
| 136 | +# Output the connection string |
| 137 | +Write-Output $connectionString |
| 138 | +``` |
| 139 | +***Using Azure CLI*** |
| 140 | +```bash |
| 141 | +# Get the storage account key |
| 142 | +storageAccountKey=(az storage account keys list --resource-group $resourceGroupName --account-name $storageAccountName --query '[0].value' --output tsv) |
| 143 | +echo $storageAccountKey |
| 144 | +# Construct the Blob connection string |
| 145 | +connectionString="DefaultEndpointsProtocol=https;AccountName=$storageAccountName;AccountKey=$storageAccountKey;EndpointSuffix=core.windows.net" |
| 146 | +echo $connectionString |
| 147 | +``` |
| 148 | + |
| 149 | +You now have the secrets to set the following .env variables in your local file. Copy the values to your `.env`: |
| 150 | +- ***BLOB_CONTAINER_NAME*** = Use the value of `$containerName` or `containerName`. |
| 151 | +- ***BLOB_CONNECTION_STRING*** = Use the value of `$connectionString ` or `connectionString`. |
| 152 | +- ***BLOB_ACCOUNT_NAME*** = Use the value of `$storageAccountName` or `storageAccountName`. |
| 153 | + |
| 154 | +**Azure AI Search** |
| 155 | + |
| 156 | +***Using PowerShell*** |
| 157 | +```powershell |
| 158 | +# Acquire the AI Search Admin Key |
| 159 | +$adminKeys = Get-AzSearchAdminKeyPair -ResourceGroupName $resourceGroupName -ServiceName $searchServiceName |
| 160 | +Write-Output $adminKeys |
| 161 | +# Construct the AI Search Admin Key |
| 162 | +$searchServiceEndpoint="https://$searchServiceName.search.windows.net" |
| 163 | +Write-Output $searchServiceEndpoint |
| 164 | +``` |
| 165 | +***Using Azure CLI*** |
| 166 | +```bash |
| 167 | +# Acquire the AI Search Admin Key |
| 168 | +searchServiceKey = az search admin-key show --resource-group resourceGroupName --service-name $searchServiceName --query primaryKey -o tsv |
| 169 | +echo $searchServiceKey |
| 170 | +# Construct the AI Search endpoint |
| 171 | +searchServiceEndpoint="https://$searchServiceName.search.windows.net" |
| 172 | +echo $searchServiceEndpoint |
| 173 | +``` |
| 174 | + |
| 175 | +You now have the secrets to set the following .env variables in your local file. Copy the values to your `.env`: |
| 176 | +- ***AZURE_SEARCH_ENDPOINT*** = Use the value of `$searchServiceEndpoint` or `searchServiceEndpoint`. |
| 177 | +- ***AZURE_SEARCH_ADMIN_KEY*** = Use the value of `$searchServiceKey` or `searchServiceKey`. |
| 178 | + |
| 179 | +**Azure OpenAI** |
| 180 | + |
| 181 | +***Using PowerShell*** |
| 182 | +```powershell |
| 183 | +# Get the Azure OpenAI key 1 |
| 184 | +$openAIKey = az cognitiveservices account keys list --resource-group $resourceGroupName --name $openAIResourceName --query "key1" --output tsv |
| 185 | +Write-Output $openAIKey |
| 186 | +# Construct the Azure OpenAI endpoint |
| 187 | +$openAIEndpoint = "https://$openAIResourceName.openai.azure.com/" |
| 188 | +Write-Output $openAIEndpoint |
| 189 | +``` |
| 190 | +***Using Azure CLI*** |
| 191 | +```bash |
| 192 | +# Get the Azure OpenAI key |
| 193 | +openAIKey=$(az cognitiveservices account keys list --resource-group $resourceGroupName --name $openAIResourceName --query "key1" --output tsv) |
| 194 | +echo $openAIKey |
| 195 | +# Construct the Azure OpenAI endpoint |
| 196 | +openAIEndpoint = "https://$openAIResourceName.openai.azure.com/" |
| 197 | +echo $openAIEndpoint |
| 198 | +``` |
| 199 | + |
| 200 | +You now have the secrets to set the following .env variables in your local file. Copy the values to your `.env`: |
| 201 | +- ***AZURE_OPENAI_ENDPOINT*** = Use the value of `$openAIEndpoint` or `openAIEndpoint`. |
| 202 | +- ***AZURE_OPENAI_KEY*** = Use the value of `$openAIKey` or `openAIKey`. |
| 203 | +- ***AZURE_GPT_DEPLOYMENT*** = Use the value of `gpt-4o-mini`. |
| 204 | +- ***AZURE_EMBEDDINGS_DEPLOYMENT*** = Use the value of `text-embedding-3-small`. |
| 205 | + |
| 206 | +**Note**: To find the ***API version (Azure_OPENAI_VERSION)*** for your resource in the Azure OpenAI playground, follow these steps: |
| 207 | +1. **Navigate to Deployments**: In the left side panel of the Azure OpenAI playground, click on “Deployments.” |
| 208 | +2. **Select the Model Deployment**: Click on the specific model deployment you are working with. |
| 209 | +3. **Locate the Endpoint Section**: In the endpoint section, you will see the Target URI. |
| 210 | +4. **Find the API Version**: Look for the part of the URL that includes `api-version=2024-08-01-preview`. This will be your API version. |
| 211 | + |
| 212 | +Your final local `.env` file should look something like this: |
| 213 | +```sh |
| 214 | +AZURE_OPENAI_VERSION = "Your Azure OpenAI API version" |
| 215 | +AZURE_OPENAI_ENDPOINT = "Your Azure OpenAI API endpoint" |
| 216 | +AZURE_OPENAI_KEY = "Your Azure OpenAI API key" |
| 217 | +AZURE_GPT_DEPLOYMENT = "Your Azure OpenAI deployed GPT model name" |
| 218 | +AZURE_EMBEDDINGS_DEPLOYMENT = "Your Azure OpenAI deployed ADA model name" |
| 219 | +AZURE_SEARCH_ENDPOINT = "Your Azure AI Search API endpoint" |
| 220 | +AZURE_SEARCH_ADMIN_KEY = "Your Azure AI Search API key" |
| 221 | +BLOB_CONTAINER_NAME = "Your Azure Blob Container name hosting files from /search_documents" |
| 222 | +BLOB_CONNECTION_STRING = "Your Azure Blob connection string" |
| 223 | +``` |
| 224 | +## Conclusion |
| 225 | + |
| 226 | +Congratulations on completing the Azure setup! During this process, we established a new resource group dedicated to the NIH Cloud Lab environment and configured three Azure resources in your tenant using an ARM template file. The resources include: |
| 227 | + |
| 228 | +- An Azure Storage Account with a deployed Blob container and files uploaded from `../search_documents` |
| 229 | +- Azure AI Search |
| 230 | +- Azure OpenAI with deployed `gpt-4o-mini` and `text-embedding-3-small` models |
| 231 | + |
| 232 | +Additionally, we configured `.env` variables in your local `.env` file, which is added to `.gitignore` by default. |
| 233 | + |
| 234 | +You are now ready to proceed with the GenAI activities in the NIH Cloud Lab. |
0 commit comments