This sample demonstrates a few approaches for creating ChatGPT-like experiences over your own data using the Retrieval Augmented Generation pattern. It uses Azure OpenAI Service to access the ChatGPT model (gpt-35-turbo), and Azure Cognitive Search for data indexing and retrieval.
The repo includes sample data so it's ready to try end to end. In this sample application we use a fictitious company called Contoso Electronics, and the experience allows its employees to ask questions about the benefits, internal policies, as well as job descriptions and roles.
IMPORTANT: In order to deploy and run this example, you'll need an Azure subscription with access enabled for the Azure OpenAI service. You can request access here. You can also visit here to get some free Azure credits to get you started.
AZURE RESOURCE COSTS by default this sample will create Azure App Service and Azure Cognitive Search resources that have a monthly cost, as well as Form Recognizer resource that has cost per document page. You can switch them to free versions of each of them if you want to avoid this cost by changing the parameters file under the infra folder (though there are some limits to consider; for example, you can have up to 1 free Cognitive Search resource per subscription, and the free Form Recognizer resource only analyzes the first 2 pages of each document.)
python --version
from console. On Ubuntu, you might need to run sudo apt install python-is-python3
to link python
to python3
.pwsh.exe
from a PowerShell command. If this fails, you likely need to upgrade PowerShell.NOTE: Your Azure Account must have
Microsoft.Authorization/roleAssignments/write
permissions, such as User Access Administrator or Owner.
You can run this repo virtually by using GitHub Codespaces or VS Code Remote Containers. Click on one of the buttons below to open this repo in one of those options.
azd auth login
azd init -t azure-search-openai-demo
Execute the following command, if you don't have any pre-existing Azure services and want to start from a fresh deployment.
azd up
- This will provision Azure resources and deploy this sample to those resources, including building the search index based on the files found in the ./data
folder.
It will look like the following:
NOTE: It may take a minute for the application to be fully deployed. If you see a "Python Developer" welcome screen, then wait a minute and refresh the page.
azd env set AZURE_OPENAI_SERVICE {Name of existing OpenAI service}
azd env set AZURE_OPENAI_RESOURCE_GROUP {Name of existing resource group that OpenAI service is provisioned to}
azd env set AZURE_OPENAI_CHATGPT_DEPLOYMENT {Name of existing ChatGPT deployment}
. Only needed if your ChatGPT deployment is not the default 'chat'.azd env set AZURE_OPENAI_GPT_DEPLOYMENT {Name of existing GPT deployment}
. Only needed if your ChatGPT deployment is not the default 'davinci'.azd env set AZURE_OPENAI_EMB_DEPLOYMENT {Name of existing GPT embedding deployment}
. Only needed if your embeddings deployment is not the default 'embedding'.azd up
NOTE: You can also use existing Search and Storage Accounts. See
./infra/main.parameters.json
for list of environment variables to pass toazd env set
to configure those existing resources.
If you've only changed the backend/frontend code in the app
folder, then you don't need to re-provision the Azure resources. You can just run:
azd deploy
If you've changed the infrastructure files (infra
folder or azure.yaml
), then you'll need to re-provision the Azure resources. You can do that by running:
azd up
azd login
app
./start.ps1
or ./start.sh
or run the "VS Code Task: Start App" to start the project locally.To give someone else access to a completely deployed and existing environment, either you or they can follow these steps:
azd init -t azure-search-openai-demo
or clone this repository.azd env refresh -e {environment name}
They will need the azd environment name, subscription ID, and location to run this command. You can find those values in your .azure/{env name}/.env
file. This will populate their azd environment's .env
file with all the settings needed to run the app locally.AZURE_PRINCIPAL_ID
either in that .env
file or in the active shell to their Azure ID, which they can get with az account show
../scripts/roles.ps1
or .scripts/roles.sh
to assign all of the necessary roles to the user. If they do not have the necessary permission to create roles in the subscription, then you may need to run this script for them. Once the script runs, they should be able to run the app locally.Once in the web app:
Note: The PDF documents used in this demo contain information generated using a language model (Azure OpenAI Service). The information contained in these documents is only for demonstration purposes and does not reflect the opinions or beliefs of Microsoft. Microsoft makes no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information contained in this document. All rights reserved to Microsoft.
Here are the most common failure scenarios and solutions:
The subscription (AZURE_SUBSCRIPTION_ID
) doesn't have access to the Azure OpenAI service. Please ensure AZURE_SUBSCRIPTION_ID
matches the ID specified in the OpenAI access request process.
You're attempting to create resources in regions not enabled for Azure OpenAI (e.g. East US 2 instead of East US), or where the model you're trying to use isn't enabled. See this matrix of model availability.
You've exceeded a quota, most often number of resources per region. See this article on quotas and limits.
You're getting "same resource name not allowed" conflicts. That's likely because you've run the sample multiple times and deleted the resources you've been creating each time, but are forgetting to purge them. Azure keeps resources for 48 hours unless you purge from soft delete. See this article on purging resources.
You see CERTIFICATE_VERIFY_FAILED
when the prepdocs.py
script runs. That's typically due to incorrect SSL certificates setup on your machine. Try the suggestions in this StackOverflow answer.
After running azd up
and visiting the website, you see a '404 Not Found' in the browser. Wait 10 minutes and try again, as it might be still starting up. Then try running azd deploy
and wait again. If you still encounter errors with the deployed app, consult these tips for debugging App Service app deployments
and file an issue if the error logs don't help you resolve the issue.