Easily deploy an Azure Open AI instance with Documents

  • Thread starter Thread starter wernerrall
  • Start date Start date
W

wernerrall

Introduction​


Deploying an Azure OpenAI instance integrated with a Search Index and a Storage Account can significantly enhance your applications' capabilities. In this guide, I will walk you through the process step-by-step.



Prerequisites​

  • An active Azure subscription
  • Azure CLI installed
  • Basic understanding of Azure services



Step 1: Setting Up the Azure OpenAI Instance​


Create a Resource Group. In our case I called it DeployOpenAI.


wernerrall_0-1722520695765.png





Next we will deploy the Open AI instance by going to All Services and Searching for Open AI


wernerrall_1-1722520779511.png



Create the Instance by placing it in your same resource Group. Accept all the defaults and press next until Resource is deployed.



wernerrall_0-1722520962870.png



wernerrall_1-1722521203205.png



Click "Go to resource" and Enable the System assigned Managed Identity. Copy the Object ID of the created managed identity for later use.


6.jpg

Step 2: Setting Up the Azure Search Index​


In All Services we are searching for AI Search

wernerrall_0-1722596660628.png




For this example we will be using the Basic pricing tier and a different region. We are using the basic pricing tier because it supports managed identities. We are using UK South region at time of posting this article because Semantic Ranker is only available in certain regions.


wernerrall_11-1722598573430.png



wernerrall_2-1722596843213.png



Click "Go to resource" and ensure Semantic Ranker shows "Selected Plan"

wernerrall_6-1722597420999.png



Enable the use of RBAC and API keys by setting the Keys to both.

wernerrall_7-1722597558488.png


Enable the System assigned Managed Identity. Copy the Object ID of the created managed identity for later use.

wernerrall_1-1722600466197.png



Step 3: Creating the Storage Account​


In All Services we search for Storage



wernerrall_8-1722597867511.png



We can technically create the storage account anywhere but I prefer it close to my search index so I will choose UK South as my region. I then adjust the Redundancy to LRS to save some costs. We can keep the default settings for the rest of the Storage Account and go next until my resource is created.



wernerrall_9-1722598070496.png



wernerrall_10-1722598471457.png



Go to Resource and click on Containers



wernerrall_12-1722598665324.png



Create a new container where we will be storing our knowledge documents or uploading our files









az ad signed-in-user show --query id -o tsv









wernerrall_13-1722598789048.png



Upload a file you want the Language model to be able to interpret for you later. I will be uploading the Microsoft Azure SLA Documentation in PDF format. Supported Formats are: "Txt, .md, .html, .docx, .pptx, and .pdf"



wernerrall_3-1722601190977.png



Step 4: Granting Permissions​


The permissions can sometimes be confusing, especially if you don't normally work in Azure. Copy the script from my GitHub Repository --> RallTheory/OpenAIBYODPermissions/OpenAIStudioPermissionsRequired.sh at main · WernerRall147/RallTheory (github.com)







Code:
# Variables
resourceGroup="#TODO"
userObjectId="#TODO"
managedIdentityObjectId1="#TODO"
managedIdentityObjectId2="#TODO"
subscriptionId="#TODO"

# Assign Cognitive Services OpenAI Contributor
az role assignment create --assignee $userObjectId --role "Cognitive Services OpenAI Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId1 --role "Cognitive Services OpenAI Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId2 --role "Cognitive Services OpenAI Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup

# Assign Cognitive Services Contributor
az role assignment create --assignee $userObjectId --role "Cognitive Services Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId1 --role "Cognitive Services Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId2 --role "Cognitive Services Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup

# Assign Search Index Data Reader
az role assignment create --assignee $userObjectId --role "Search Index Data Reader" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId1 --role "Search Index Data Reader" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId2 --role "Search Index Data Reader" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup

# Assign Storage Blob Data Contributor
az role assignment create --assignee $userObjectId --role "Storage Blob Data Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId1 --role "Storage Blob Data Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId2 --role "Storage Blob Data Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup

# Assign Search Service Contributor
az role assignment create --assignee $userObjectId --role "Search Service Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId1 --role "Search Service Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup
az role assignment create --assignee $managedIdentityObjectId2 --role "Search Service Contributor" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroup









Only replace the Variables Section with the #TODO labels. The 2 Managed Identity Objects we copied from earlier steps. To get your own user Object Id you can run the below script by launching the Azure Cloud Shell.



wernerrall_0-1722599423381.png







az ad signed-in-user show --query id -o tsv









Our variables should now look something like this (I have hidden some of the characters)









Code:
# Variables
resourceGroup="DeployOpenAI"
userObjectId="6167fxxxxxxxxxxxxxxxxxx"
managedIdentityObjectId1="f24cbcxxxxxxxxxxxxxxxxxxx"
managedIdentityObjectId2="542bxxxxxxxxxxxxxxxxxxxxxx"
subscriptionId="2910xxxxxxxxxxxxxxxxxxxxxxxxx"









Now we are ready to apply the permissions. Copy the entire script including the variables section and paste it as is in the Azure Cloud Shell. Then press Enter. Your output should look similar to below.



wernerrall_2-1722600829768.png



If all permissions applied successfully, we should have no problem in the Open AI Studio.



Step 5: Open AI Studio Deployment​


Head over to our Open AI deployment and click "Go to Azure OpenAI Studio"



wernerrall_5-1722776864361.png



On the landing page click on Deployments and Deploy Model



wernerrall_6-1722601456854.png



We will be deploying 2 models. The Base "text-embedding-ada-002" and the "gpt-4o" models. Let's start with text-embedding-ada-002.



image.png





wernerrall_15-1722602842388.png



Next we deploy the GPT-4o model



wernerrall_9-1722601834303.png



wernerrall_10-1722601889392.png



You should now see both your deployments



wernerrall_18-1722602973734.png



Now we need to load our data from the Storage Account into the AI Search Index. In Chat, we can click "Add your data".



wernerrall_14-1722602497433.png



wernerrall_19-1722603046983.png



We will use Hybrid + semantic search



wernerrall_20-1722603087865.png



Click next on System Assigned Managed Identity. If our permissions applied correctly, we shouldn't get any errors here and we can continue to Save and Close.



wernerrall_21-1722603138779.png



wernerrall_22-1722603199130.png



You will see your data getting processed and Indexed.



wernerrall_0-1722603321334.png



And lastly, we need to create a deployment to a Web App so we can interact with all of these pieces. Let's go to Chat and click "Deploy to a web app"



wernerrall_1-1722603377394.png



We can fill in all the details here. If this is the second or third time I am deploying I can also choose "Update an Existing Web App"



wernerrall_2-1722603468790.png



To see if my app is deploying, I can go back to the Azure Portal and take a look in the Resource Group under Deployments



wernerrall_3-1722603560137.png



Once my website is ready I can simply go to Web Apps or find my new Web App in the Resource Group.



wernerrall_4-1722776850654.pngwernerrall_0-1722604005450.png





Now we can finally enjoy our newly deployed Large Language Model.



wernerrall_0-1722776508865.png



wernerrall_1-1722776560091.png



wernerrall_2-1722776589889.png



You might get this from time to time



wernerrall_3-1722776692664.png



To fix this we can either:

1. Increase our models Rate Limits or request more Quota, this may require a redeploy to your existing web app. If we still encounter the error, we can deploy other models with more quota available out-of-the-box or we can request quota for our required model from Azure Support.




2. Decrease the size of our documents by converting them to easier formats like ".txt" or "md". Converting file formats like PDF to TXT can significantly help reduce token usage when working with Azure OpenAI or any other text-based AI model.



In this blog I chose to deploy gpt-4 as a different model to try assist in solving our problem



image.png

image.png



After adding some quota and redeploying the app with gpt-4 we are now getting better responses.

I hope this has been a helpful walkthrough!




Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts or Power BI Dashboards are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts or Power BI Dashboards be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages. This blog post was written with the help of generative AI.


Continue reading...
 
Back
Top