Skip to content

Commit 45a42aa

Browse files
committed
fixed variables, functions, other bugs, and added additional explainations
1 parent e206509 commit 45a42aa

File tree

8 files changed

+618
-353
lines changed

8 files changed

+618
-353
lines changed

notebooks/GenAI/azure_infra_setup/README.md

Lines changed: 96 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ Please refer to the [Azure Pricing Calculator](https://azure.microsoft.com/en-us
7676
### 1. Setting Up the Azure Module in PowerShell
7777

7878
First, you need to install the Azure module in PowerShell to connect to your Azure account.
79-
80-
```powershell
79+
80+
```powershell
8181
# Install the Az module (if using PowerShell)
8282
Install-Module -Name Az -AllowClobber -Force
8383
```
@@ -92,9 +92,9 @@ You can log into your Azure account either using PowerShell or Azure CLI.
9292
Connect-AzAccount
9393
```
9494
**Using Azure CLI**
95-
```bash
95+
```powershell
9696
# Log into your Azure account
97-
az login
97+
!az login
9898
```
9999

100100
### 3. Setting Variables
@@ -114,16 +114,18 @@ $searchServiceName="cloudlabsearch"
114114
$openAIResourceName="cloudlabaoai"
115115
```
116116
**Using Azure CLI**
117-
```bash
117+
```powershell
118118
# Variables
119-
resourceGroupName="nihcloudlabrg"
120-
location="eastus2"
121-
templateFilePath="Path To ./arm_resources.json"
122-
storageAccountName="cloudlabstgacct"
123-
containerName="cloudlabdocuments"
124-
localFilePath="Path To ../search_documents"
125-
searchServiceName="cloudlabsearch"
126-
openAIResourceName="cloudlabaoai"
119+
resourceGroupName = 'nihcloudlabrg'
120+
location = 'eastus2'
121+
templateFilePath = "arm_resources.json"
122+
storageAccountName = "cloudlabstgacct"
123+
containerName = "cloudlabdocuments"
124+
localFilePath = "../search_documents"
125+
searchServiceName = "cloudlabsearch"
126+
openAIResourceName = "cloudlabaoai"
127+
openAImodel_name = "gpt-4o-mini"
128+
openAIEmbeddingmodel_name = "text-embedding-3-small"
127129
```
128130

129131
### 4. Creating an Empty Resource Group
@@ -133,12 +135,12 @@ Create an empty resource group where the ARM template will deploy the necessary
133135
**Using PowerShell**
134136
```powershell
135137
# Create a resource group
136-
New-AzResourceGroup -Name $resourceGroupName -Location $location
138+
New-AzResourceGroup -Name $resourceGroupName -Location $location
137139
```
138140
**Using Azure CLI**
139-
```bash
141+
```powershell
140142
# Create a resource group
141-
az group create --name $resourceGroupName --location $location
143+
! az group create --name {resourceGroupName} --location {location}
142144
```
143145

144146
### 5. Deploying the ARM Template
@@ -151,17 +153,25 @@ Deploy the [ARM template](arm_resources.json) to create the Azure Storage Accoun
151153
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath
152154
```
153155
***Using Azure CLI***
154-
```bash
156+
```powershell
155157
# Deploy the ARM template
156-
az deployment group create --resource-group $resourceGroupName --template-file $templateFilePath
158+
!az deployment group create \
159+
--resource-group {resourceGroupName} \
160+
--template-file {templateFilePath} \
161+
--parameters accounts_cloudlabaoai_name={openAIResourceName} \
162+
--parameters model_name={openAImodel_name} \
163+
--parameters embeddingModel_name={openAIEmbeddingmodel_name} \
164+
--parameters searchServices_cloudlabsearch_name={searchServiceName} \
165+
--parameters storageAccounts_genaicloudlab_name={storageAccountName}
166+
157167
```
158168

159169
### 6. Uploading Local Files to Azure Storage
160170

161171
Upload your local files to the blob container in the Azure Storage Account.
162172

163173
**Using PowerShell**
164-
```powershell
174+
```powershell
165175
# Get storage account context
166176
$storageContext = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName).Context
167177
@@ -171,14 +181,16 @@ Get-ChildItem -Path $localFilePath -File | ForEach-Object {
171181
}
172182
```
173183
**Using Azure CLI**
174-
```bash
175-
# Get storage account key
176-
storageAccountKey=$(az storage account keys list --resource-group $resourceGroupName --account-name $storageAccountName --query "[0].value" --output tsv)
177-
178-
# Upload all files in the directory
179-
for file in localFilePath/*; do
180-
az storage blob upload --account-name $storageAccountName --account-key $storageAccountKey --container-name $containerName --file file --name (basename file)
181-
done
184+
```powershell
185+
# Get storage account key
186+
storageAccountKey=!az storage account keys list --resource-group {resourceGroupName} --account-name {storageAccountName} --output tsv --query "[0].value"
187+
```
188+
189+
```bash magic_args="-s \"$localFilePath\" \"$storageAccountName\" \"$storageAccountKey\" \"$containerName\""
190+
for file in $1/*;
191+
do
192+
az storage blob upload --account-name $2 --account-key $3 --container-name $4 --file "$file" --name $(basename "$file")
193+
done
182194
```
183195

184196
### 7. Retrieving API Keys
@@ -201,19 +213,26 @@ $connectionString = "DefaultEndpointsProtocol=https;AccountName=$storageAccountN
201213
Write-Output $connectionString
202214
```
203215
***Using Azure CLI***
204-
```bash
205-
# Get the storage account key
206-
storageAccountKey=(az storage account keys list --resource-group $resourceGroupName --account-name $storageAccountName --query '[0].value' --output tsv)
207-
echo $storageAccountKey
216+
```powershell
217+
# Get the storage account key that was made before in step 6
218+
!echo "BLOB_CONTAINER_NAME={containerName}" >> .env
219+
!echo "BLOB_ACCOUNT_NAME={storageAccountName}" >> .env
208220
# Construct the Blob connection string
209-
connectionString="DefaultEndpointsProtocol=https;AccountName=$storageAccountName;AccountKey=$storageAccountKey;EndpointSuffix=core.windows.net"
210-
echo $connectionString
221+
connectionString=f"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey[0]};EndpointSuffix=core.windows.net"
222+
!echo "BLOB_CONNECTION_STRING={connectionString}" >> .env
223+
211224
```
212225

213-
You now have the secrets to set the following .env variables in your local file. Copy the values to your `.env`:
214-
- ***BLOB_CONTAINER_NAME*** = Use the value of `$containerName` or `containerName`.
215-
- ***BLOB_CONNECTION_STRING*** = Use the value of `$connectionString ` or `connectionString`.
226+
Lets take a look at our .env file!
227+
228+
```powershell
229+
!cat .env
230+
```
231+
232+
You now have the secrets and variables set in a .env. If you run into any errors you can also copy them to your .env file using the info below:
233+
- ***BLOB_CONTAINER_NAME*** = Use the value of `$containerName` or `containerName`.
216234
- ***BLOB_ACCOUNT_NAME*** = Use the value of `$storageAccountName` or `storageAccountName`.
235+
- ***BLOB_CONNECTION_STRING*** = Use the value of `$connectionString ` or `connectionString`.
217236

218237
**Azure AI Search**
219238

@@ -227,22 +246,31 @@ $searchServiceEndpoint="https://$searchServiceName.search.windows.net"
227246
Write-Output $searchServiceEndpoint
228247
```
229248
***Using Azure CLI***
230-
```bash
249+
```powershell
231250
# Acquire the AI Search Admin Key
232-
searchServiceKey = az search admin-key show --resource-group resourceGroupName --service-name $searchServiceName --query primaryKey -o tsv
233-
echo $searchServiceKey
251+
searchServiceKey = !az search admin-key show --resource-group {resourceGroupName} --service-name {searchServiceName} --query primaryKey -o tsv
252+
!echo "AZURE_SEARCH_API_KEY={searchServiceKey[0]}" >> .env
234253
# Construct the AI Search endpoint
235-
searchServiceEndpoint="https://$searchServiceName.search.windows.net"
236-
echo $searchServiceEndpoint
254+
searchServiceEndpoint=f"https://{searchServiceName}.search.windows.net"
255+
!echo "AZURE_SEARCH_SERVICE_ENDPOINT={searchServiceEndpoint}" >> .env
237256
```
238257

239-
You now have the secrets to set the following .env variables in your local file. Copy the values to your `.env`:
240-
- ***AZURE_SEARCH_ENDPOINT*** = Use the value of `$searchServiceEndpoint` or `searchServiceEndpoint`.
258+
Lets take a look at our .env file!
259+
260+
```powershell
261+
!cat .env
262+
```
263+
264+
<!-- #region -->
265+
You now have the secrets and variables set in a .env. If you run into any errors you can also copy them to your .env file using the info below:
241266
- ***AZURE_SEARCH_ADMIN_KEY*** = Use the value of `$searchServiceKey` or `searchServiceKey`.
267+
- ***AZURE_SEARCH_ENDPOINT*** = Use the value of `$searchServiceEndpoint` or `searchServiceEndpoint`.
268+
242269

243270
**Azure OpenAI**
244271

245272
***Using PowerShell***
273+
<!-- #endregion -->
246274
```powershell
247275
# Get the Azure OpenAI key 1
248276
$openAIKey = az cognitiveservices account keys list --resource-group $resourceGroupName --name $openAIResourceName --query "key1" --output tsv
@@ -252,39 +280,43 @@ $openAIEndpoint = "https://$openAIResourceName.openai.azure.com/"
252280
Write-Output $openAIEndpoint
253281
```
254282
***Using Azure CLI***
255-
```bash
256-
# Get the Azure OpenAI key
257-
openAIKey=$(az cognitiveservices account keys list --resource-group $resourceGroupName --name $openAIResourceName --query "key1" --output tsv)
258-
echo $openAIKey
283+
```powershell
284+
!echo "AZURE_GPT_DEPLOYMENT={openAImodel_name}" >> .env
285+
!echo "AZURE_EMBEDDINGS_DEPLOYMENT={openAIEmbeddingmodel_name}" >>.env
286+
259287
# Construct the Azure OpenAI endpoint
260-
openAIEndpoint = "https://$openAIResourceName.openai.azure.com/"
261-
echo $openAIEndpoint
288+
openAIEndpoint = f"https://{openAIResourceName}.openai.azure.com/"
289+
!echo "AZURE_OPENAI_ENDPOINT={openAIEndpoint}" >> .env
290+
# Get the Azure OpenAI key
291+
openAIKey=!az cognitiveservices account keys list --resource-group {resourceGroupName} --name {openAIResourceName} --query "key1" --output tsv
292+
!echo "AZURE_OPENAI_API_KEY={openAIKey[0]}" >> .env
293+
262294
```
263295

264-
You now have the secrets to set the following .env variables in your local file. Copy the values to your `.env`:
265-
- ***AZURE_OPENAI_ENDPOINT*** = Use the value of `$openAIEndpoint` or `openAIEndpoint`.
266-
- ***AZURE_OPENAI_KEY*** = Use the value of `$openAIKey` or `openAIKey`.
296+
```powershell
297+
cat .env
298+
```
299+
300+
<!-- #region -->
301+
You now have the secrets and variables set in a .env. If you run into any errors you can also copy them to your .env file using the info below:
267302
- ***AZURE_GPT_DEPLOYMENT*** = Use the value of `gpt-4o-mini`.
268303
- ***AZURE_EMBEDDINGS_DEPLOYMENT*** = Use the value of `text-embedding-3-small`.
304+
- ***AZURE_OPENAI_ENDPOINT*** = Use the value of `$openAIEndpoint` or `openAIEndpoint`.
305+
- ***AZURE_OPENAI_KEY*** = Use the value of `$openAIKey` or `openAIKey`.
306+
269307

270308
**Note**: To find the ***API version (Azure_OPENAI_VERSION)*** for your resource in the Azure OpenAI playground, follow these steps:
271309
1. **Navigate to Deployments**: In the left side panel of the Azure OpenAI playground, click on “Deployments.”
272310
2. **Select the Model Deployment**: Click on the specific model deployment you are working with.
273311
3. **Locate the Endpoint Section**: In the endpoint section, you will see the Target URI.
274-
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.
312+
4. **Find the API Version**: Look for the part of the URL that looks similar to `api-version=2025-01-01-preview`. This will be your API version. This may differ between models
275313

276314
Your final local `.env` file should look something like this:
277-
```sh
278-
AZURE_OPENAI_VERSION = "Your Azure OpenAI API version"
279-
AZURE_OPENAI_ENDPOINT = "Your Azure OpenAI API endpoint"
280-
AZURE_OPENAI_KEY = "Your Azure OpenAI API key"
281-
AZURE_GPT_DEPLOYMENT = "Your Azure OpenAI deployed GPT model name"
282-
AZURE_EMBEDDINGS_DEPLOYMENT = "Your Azure OpenAI deployed ADA model name"
283-
AZURE_SEARCH_ENDPOINT = "Your Azure AI Search API endpoint"
284-
AZURE_SEARCH_ADMIN_KEY = "Your Azure AI Search API key"
285-
BLOB_CONTAINER_NAME = "Your Azure Blob Container name hosting files from /search_documents"
286-
BLOB_CONNECTION_STRING = "Your Azure Blob connection string"
315+
<!-- #endregion -->
316+
```powershell
317+
!cat .env
287318
```
319+
288320
## Conclusion <a name="conclusion"></a>
289321

290322
Congratulations on completing the Azure setup! During this process, we established a new resource group dedicated to the NIH Cloud Lab environment and
@@ -299,4 +331,4 @@ Additionally, we configured `.env` variables in your local `.env` file, which is
299331
You are now ready to proceed with the GenAI tutorials!
300332

301333
## Clean Up <a name="clean_up"></a>
302-
No clean up neccessary, as the created resources will be used for tutorials found in [GenAI](../).
334+
No clean up neccessary, as the created resources will be used for tutorials found in [GenAI](../) folder, specifically [embeddings demos](../embedding_demos/readme.md) and [AI Search RAG chatbot](../notebooks/AISearch_RAG_chatbot.ipynb) tutorial .

notebooks/GenAI/azure_infra_setup/arm_resources.json

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@
1313
"accounts_cloudlabaoai_name": {
1414
"defaultValue": "cloudlabaoai5",
1515
"type": "String"
16+
},
17+
"model_name": {
18+
"defaultValue": "gpt-4o-mini",
19+
"type": "String"
20+
},
21+
"embeddingModel_name": {
22+
"defaultValue": "text-embedding-3-small",
23+
"type": "String"
1624
}
1725
},
1826
"variables": {},
1927
"resources": [
2028
{
2129
"type": "Microsoft.CognitiveServices/accounts",
22-
"apiVersion": "2024-06-01-preview",
30+
"apiVersion": "2025-04-01-preview",
2331
"name": "[parameters('accounts_cloudlabaoai_name')]",
2432
"location": "eastus2",
2533
"sku": {
@@ -39,7 +47,7 @@
3947
},
4048
{
4149
"type": "Microsoft.Search/searchServices",
42-
"apiVersion": "2024-06-01-preview",
50+
"apiVersion": "2025-02-01-preview",
4351
"name": "[parameters('searchServices_cloudlabsearch_name')]",
4452
"location": "East US 2",
4553
"sku": {
@@ -67,7 +75,7 @@
6775
},
6876
{
6977
"type": "Microsoft.Storage/storageAccounts",
70-
"apiVersion": "2023-05-01",
78+
"apiVersion": "2024-01-01",
7179
"name": "[parameters('storageAccounts_genaicloudlab_name')]",
7280
"location": "eastus2",
7381
"sku": {
@@ -110,19 +118,19 @@
110118
},
111119
{
112120
"type": "Microsoft.CognitiveServices/accounts/deployments",
113-
"apiVersion": "2024-06-01-preview",
114-
"name": "[concat(parameters('accounts_cloudlabaoai_name'), '/gpt-4o-mini')]",
121+
"apiVersion": "2025-04-01-preview",
122+
"name": "[concat(parameters('accounts_cloudlabaoai_name'),'/', (parameters('model_name')))]",
115123
"dependsOn": [
116124
"[resourceId('Microsoft.CognitiveServices/accounts', parameters('accounts_cloudlabaoai_name'))]"
117125
],
118126
"sku": {
119-
"name": "GlobalStandard",
127+
"name": "Standard",
120128
"capacity": 10
121129
},
122130
"properties": {
123131
"model": {
124132
"format": "OpenAI",
125-
"name": "gpt-4o-mini",
133+
"name": "(parameters('model_name')",
126134
"version": "2024-07-18"
127135
},
128136
"versionUpgradeOption": "OnceNewDefaultVersionAvailable",
@@ -132,8 +140,8 @@
132140
},
133141
{
134142
"type": "Microsoft.CognitiveServices/accounts/deployments",
135-
"apiVersion": "2024-06-01-preview",
136-
"name": "[concat(parameters('accounts_cloudlabaoai_name'), '/text-embedding-3-small')]",
143+
"apiVersion": "2025-04-01-preview",
144+
"name": "[concat(parameters('accounts_cloudlabaoai_name'), '/', (parameters('embeddingModel_name')))]",
137145
"dependsOn": [
138146
"[resourceId('Microsoft.CognitiveServices/accounts', parameters('accounts_cloudlabaoai_name'))]"
139147
],
@@ -144,7 +152,7 @@
144152
"properties": {
145153
"model": {
146154
"format": "OpenAI",
147-
"name": "text-embedding-3-small",
155+
"name": "parameters('embeddingModel_name')",
148156
"version": "1"
149157
},
150158
"versionUpgradeOption": "OnceNewDefaultVersionAvailable",
@@ -154,7 +162,7 @@
154162
},
155163
{
156164
"type": "Microsoft.Storage/storageAccounts/blobServices",
157-
"apiVersion": "2023-05-01",
165+
"apiVersion": "2024-01-01",
158166
"name": "[concat(parameters('storageAccounts_genaicloudlab_name'), '/default')]",
159167
"dependsOn": [
160168
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts_genaicloudlab_name'))]"
@@ -180,7 +188,7 @@
180188
},
181189
{
182190
"type": "Microsoft.Storage/storageAccounts/fileServices",
183-
"apiVersion": "2023-05-01",
191+
"apiVersion": "2024-01-01",
184192
"name": "[concat(parameters('storageAccounts_genaicloudlab_name'), '/default')]",
185193
"dependsOn": [
186194
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts_genaicloudlab_name'))]"
@@ -204,7 +212,7 @@
204212
},
205213
{
206214
"type": "Microsoft.Storage/storageAccounts/queueServices",
207-
"apiVersion": "2023-05-01",
215+
"apiVersion": "2024-01-01",
208216
"name": "[concat(parameters('storageAccounts_genaicloudlab_name'), '/default')]",
209217
"dependsOn": [
210218
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts_genaicloudlab_name'))]"
@@ -217,7 +225,7 @@
217225
},
218226
{
219227
"type": "Microsoft.Storage/storageAccounts/tableServices",
220-
"apiVersion": "2023-05-01",
228+
"apiVersion": "2024-01-01",
221229
"name": "[concat(parameters('storageAccounts_genaicloudlab_name'), '/default')]",
222230
"dependsOn": [
223231
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts_genaicloudlab_name'))]"
@@ -230,7 +238,7 @@
230238
},
231239
{
232240
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
233-
"apiVersion": "2023-05-01",
241+
"apiVersion": "2024-01-01",
234242
"name": "[concat(parameters('storageAccounts_genaicloudlab_name'), '/default/cloudlabdocuments')]",
235243
"dependsOn": [
236244
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', parameters('storageAccounts_genaicloudlab_name'), 'default')]",

0 commit comments

Comments
 (0)