NOTE 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.
Before to jumping to the Azure OpenAI API, this guide will show how to have access to Azure OpenAI services in your Azure Subscription as well the step by step on how to setup this service. here
- Azure Developer CLI
- Python 3.9
- Node.js
- Git
- ODBC Driver 17 for SQL
- Azure Functions Extension for VSCode
- Azure Functions Core tools
- Powershell 7+ (pwsh) - For Windows users only. Important: Ensure you can run
pwsh.exe
from a PowerShell command. If this fails, you likely need to upgrade PowerShell.
Note Pre-built docker Images are required only if you want to run the application in docker container. You can skip this step if you want to run the application locally. Do note that you need to provision all the services in Azure to run the application locally or in container.
Configure your .env
as described in as described in Configuration. You can alternatively, copy .dockerenv.example to .env from api\Python folder
Then run:
docker run --env-file .env -p 7071:80 --name chataskapi -it akshata13/chataskapi:latest
Verify http://localhost:7071 to confirm the API is running locally.
Configure your .env
as described in as described in Configuration. You can alternatively, copy .dockerenv.example to .env from app\backend folder
Then run:
docker run --env-file .env --name chataskapp -it akshata13/chataskapp:latest
Verify http://localhost:5000 to confirm the App is running locally.
- Semi-Automated Installation
- Click to deploy following services
- Azure App Service Plan (Linux - B1 Tier)
- Cognitive Search Service (Standard Tier)
- Azure App Service (To Deploy backend service)
- Azure Function app (For all Python API)
- Storage Account (to store all your files) & Function storage account
- Azure Open AI Service
- Azure Application Insight
- Cognitive Services (Language and Speech Service)
- SQL Server and Database (Note - SQL Script - northwind.sql need to run manually once database is created)
- Note - Pinecone and Redis needs to be installed manually if you want vector database support.
- NOTE - Due to rapid change in the deployment model on Azure Open AI models, commenting out the code to deploy the model. You need to manually deploy the model using the Azure Open AI Studio. Ensure you create a gpt-3.5-turbo as deployment name "chat" and text-davinci-003 as "davinci".
- AWS Integration - None of the artifacts are deployed for AWS Integration. Scripts are available in Deployment\aws folder
- Fork the repo
- Note - Following information need to be performed only once
- Click on Actions and select "I understand my workflow, go ahead and enable them"
- Download the Publish Profile for the Azure Function App that is deployed
- Setup AZURE_FUNCTIONAPP_PUBLISH_PROFILE secret in your forked repository (Settings -> Secrets and Variables -> Actions -> New Repository Secret). Copy/Paste the content of the Publish profile
- Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
- Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. More Information
- Setup AZURE_FUNCTIONAPP_NAME secret in your forked repository as the name of your Function App
- Setup AZURE_WEBAPP_NAME secret in your forked repository as the name of your Azure App Service
- Setup DOCKER_HUB_USERNAME and DOCKER_HUB_ACCESS_TOKEN secret in your forked repository as the name of you docker user name and access token (Optional)
- Note You can disable the Docker Api and Docker App Actions if it's not required.
- Verify the Configuration settings are properly configured in Azure Function App and Azure App Service. THe default Upload and Admin password are P@ssw0rd. Make sure the right keys are configured for the set of the functionality.
- Successful execution of both workflow will deploy the Python API and Azure App Services (UI application)
- NOTE In case if you have FTP disabled due to policy on your subscription, you need to manually add following configuration and changes to YAML github action as deploy with Publish Profile will not work.
- Download Azure CLI from here, run az login to login with your Azure credentials.
- Select your subscription using az account set --subscription <subscription_name>
- Create Azure app registration and grant contributor access to Function app using az ad sp create-for-rbac --name "chatpdf" --role contributor --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{function-app-name} --sdk-auth
- Replace {subscription-id}, {resource-group}, {app-name} and {function-app-name} with the names of your subscription, resource group, Web app and Azure function app.
- Update Azure app registration and grant contributor access to Web app using az ad sp create-for-rbac --name "chatpdf" --role contributor --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/sites/{app-name} --sdk-auth
- The command should output a JSON object similar to this:
- { "clientId": "{GUID}", "clientSecret": "{GUID}", "subscriptionId": "{GUID}", "tenantId": "{GUID}", "activeDirectoryEndpointUrl": "https://login.microsoftonline.com", "resourceManagerEndpointUrl": "https://management.azure.com/", "activeDirectoryGraphResourceId": "https://graph.windows.net/", "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/", "galleryEndpointUrl": "https://gallery.azure.com/", "managementEndpointUrl": "https://management.core.windows.net/" }
- Copy and paste the json response from above Azure CLI to your GitHub Repository > Settings > Secrets > Add a new secret > AZURE_RBAC_CREDENTIALS
- Setup AZURE_FUNCTIONAPP_NAME secret in your forked repository as the name of your Function App
- Setup AZURE_WEBAPP_NAME secret in your forked repository as the name of your Azure App Service
- Replace pythonapi.yml file (stored in chatpdf/.github/workflows directory) with the content from here
- Trigger the workflow manually and verify the deployment is successful.
- Replace backendapp.yml file (stored in chatpdf/.github/workflows directory) with the content from here
- Trigger the workflow manually and verify the deployment is successful.
- Click to deploy following services
Note - To debug and troubleshoot issues after the deployment, you can view the log in Live Metrics in application insights or enable running the Logs for the specific Azure Function.
- Alternatively deploy the following services manually
- OpenAI service. Please be aware of the model & region availability documented [here]. Once the service is created, deploy the model for gpt35-turbo(chat), text-davinci-003 (davinci) and text-ada-embedding-002. (https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/models#model-summary-table-and-region-availability)
- Storage Account and a container (chatpdf)
- One of the Document Store
- Pinecone Starter. Note Make sure you create the index in Pincone with dimensions as 1536 and metric as cosine
- Cognitive Search
- Redis
- Create Function App
- Create SQL Server and SQL Database and run northwind.sql script
- Create Speech Cognitive Service
- Create Language/Text Analytics Cognitive Service
- Create Application Insight service
- Create Azure Web App and App Service Plan
- Git clone the repo
- Open the cloned repo folder in VSCode
- Open new terminal and go to /app/frontend directory
- Run
npm install
to install all the packages - Go to /api/Python directory
- Run
pip install -r requirements.txt
to install all required python packages - Copy sample.settings.json to local.settings.json
- Update the configuration (Minimally you need OpenAi, one of the document store, storage account)
- Deploy the Azure Python API to Function app
- Open new terminal and go to /app/frontend directory
- Run npm run build for production build and copying static files to app/backend/static directory
- Open new terminal and go to /app/backend directory
- Copy env.example to .env file and edit the file to enter the Python localhost API and the storage configuration
- Deploy the app/backend Azure web app.
- Verify the Configuration settings are properly configured in Azure Function App and Azure App Service
- Git clone the repo
- Open the cloned repo folder in VSCode
- Open new terminal and go to /app/frontend directory
- Run
npm install
to install all the packages - Go to /api/Python directory
- Run
pip install -r requirements.txt
to install all required python packages - Copy sample.settings.json to local.settings.json
- Update the configuration (Minimally you need OpenAi, one of the document store, storage account)
- Start the Python API by running
func host start
- Open new terminal and go to /app/backend directory
- Run
pip install -r requirements.txt
to install all required python packages - Copy env.example to .env file and edit the file to enter the Python localhost API and the storage configuration
- Run py app.py to start the backend locally (on port 5000)
- Open new terminal and go to /app/frontend directory
- Run npm run dev to start the local server (on port 5173) !5. Browse the localhost:5173 to open the web app.
Once in the web app:
- Try different topics in chat or Q&A context. For chat, try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.
- Explore citations and sources
- Click on "settings" to try different options, tweak prompts, etc.