Skip to content

Commit bb0c3ed

Browse files
diberrypamelafox
andauthored
Fix samples browser (#1631)
* Fix samples browser * fix prepdocs * Update samples/data-ingestion/README.md Co-authored-by: Pamela Fox <[email protected]> * Update samples/private-endpoint/README.md Co-authored-by: Pamela Fox <[email protected]> * Update samples/document-security/README.md Co-authored-by: Pamela Fox <[email protected]> * updates as requested * Update samples/data-ingestion/README.md Co-authored-by: Pamela Fox <[email protected]> * Update samples/chat/README.md Co-authored-by: Pamela Fox <[email protected]> --------- Co-authored-by: Pamela Fox <[email protected]>
1 parent b31a95b commit bb0c3ed

File tree

5 files changed

+750
-17
lines changed

5 files changed

+750
-17
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
---
2-
name: ChatGPT + Enterprise data
3-
description: Chat with your data using OpenAI and AI Search.
4-
languages:
5-
- python
6-
- typescript
7-
- bicep
8-
- azdeveloper
9-
products:
10-
- azure-openai
11-
- azure-cognitive-search
12-
- azure-app-service
13-
- azure
14-
page_type: sample
15-
urlFragment: azure-search-openai-demo
16-
---
17-
181
# ChatGPT + Enterprise data with Azure OpenAI and AI Search
192

203
> [!IMPORTANT]

samples/chat/README.md

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
---
2+
name: ChatGPT + Enterprise data
3+
description: Chat with your data using OpenAI and AI Search.
4+
languages:
5+
- python
6+
- typescript
7+
- bicep
8+
- azdeveloper
9+
products:
10+
- azure-openai
11+
- azure-cognitive-search
12+
- azure-app-service
13+
- azure
14+
page_type: sample
15+
urlFragment: azure-search-openai-demo
16+
---
17+
<!-- Original document: /readme.md -->
18+
19+
# ChatGPT + Enterprise data with Azure OpenAI and AI Search
20+
21+
22+
> [!IMPORTANT]
23+
> As of November 15, 2023, Azure Cognitive Search has been renamed to Azure AI Search.
24+
25+
### Announcing [**JavaScript**](https://aka.ms/azai/js/code), [**.NET**](https://aka.ms/azai/net/code), and [**Java**](https://aka.ms/azai/java/code) samples based on this one ([**Python**](https://aka.ms/azai/py/code)). Learn more at https://aka.ms/azai.
26+
27+
## Table of Contents
28+
29+
- [Features](#features)
30+
- [Azure account requirements](#azure-account-requirements)
31+
- [Azure deployment](#azure-deployment)
32+
- [Cost estimation](#cost-estimation)
33+
- [Project setup](#project-setup)
34+
- [GitHub Codespaces](#github-codespaces)
35+
- [VS Code Dev Containers](#vs-code-dev-containers)
36+
- [Local environment](#local-environment)
37+
- [Deploying](#deploying)
38+
- [Deploying again](#deploying-again)
39+
- [Sharing environments](#sharing-environments)
40+
- [Using the app](#using-the-app)
41+
- [Running locally](#running-locally)
42+
- [Monitoring with Application Insights](#monitoring-with-application-insights)
43+
- [Customizing the UI and data](#customizing-the-ui-and-data)
44+
- [Productionizing](#productionizing)
45+
- [Clean up](#clean-up)
46+
- [Troubleshooting](#troubleshooting)
47+
- [Resources](#resources)
48+
49+
50+
[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=599293758&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
51+
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-search-openai-demo)
52+
53+
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 a GPT model (gpt-35-turbo), and Azure AI Search for data indexing and retrieval.
54+
55+
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.
56+
57+
![RAG Architecture](/docs/images/appcomponents.png)
58+
59+
## Features
60+
61+
* Chat and Q&A interfaces
62+
* Explores various options to help users evaluate the trustworthiness of responses with citations, tracking of source content, etc.
63+
* Shows possible approaches for data preparation, prompt construction, and orchestration of interaction between model (OpenAI) and retriever (AI Search)
64+
* Settings directly in the UX to tweak the behavior and experiment with options
65+
* Performance tracing and monitoring with Application Insights
66+
67+
![Chat screen](/docs/images/chatscreen.png)
68+
69+
[📺 Watch a video overview of the app.](https://youtu.be/3acB0OWmLvM)
70+
71+
## Azure account requirements
72+
73+
**IMPORTANT:** In order to deploy and run this example, you'll need:
74+
75+
* **Azure account**. If you're new to Azure, [get an Azure account for free](https://azure.microsoft.com/free/cognitive-search/) and you'll get some free Azure credits to get started. See [guide to deploying with the free trial](/docs/deploy_lowcost.md).
76+
* **Azure subscription with access enabled for the Azure OpenAI service**. You can request access with [this form](https://aka.ms/oaiapply). If your access request to Azure OpenAI service doesn't match the [acceptance criteria](https://learn.microsoft.com/legal/cognitive-services/openai/limited-access?context=%2Fazure%2Fcognitive-services%2Fopenai%2Fcontext%2Fcontext), you can use [OpenAI public API](https://platform.openai.com/docs/api-reference/introduction) instead. Learn [how to switch to an OpenAI instance](/docs/deploy_existing.md#openaicom-openai).
77+
* **Azure account permissions**:
78+
* Your Azure account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [Role Based Access Control Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview), [User Access Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#user-access-administrator), or [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner). If you don't have subscription-level permissions, you must be granted [RBAC](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview) for an existing resource group and [deploy to that existing group](/docs/deploy_existing.md#resource-group).
79+
* Your Azure account also needs `Microsoft.Resources/deployments/write` permissions on the subscription level.
80+
81+
## Azure deployment
82+
83+
### Cost estimation
84+
85+
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage.
86+
However, you can try the [Azure pricing calculator](https://azure.com/e/d18187516e9e421e925b3b311eec8aae) for the resources below.
87+
88+
- Azure App Service: Basic Tier with 1 CPU core, 1.75 GB RAM. Pricing per hour. [Pricing](https://azure.microsoft.com/pricing/details/app-service/linux/)
89+
- Azure OpenAI: Standard tier, GPT and Ada models. Pricing per 1K tokens used, and at least 1K tokens are used per question. [Pricing](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/)
90+
- Azure AI Document Intelligence: SO (Standard) tier using pre-built layout. Pricing per document page, sample documents have 261 pages total. [Pricing](https://azure.microsoft.com/pricing/details/form-recognizer/)
91+
- Azure AI Search: Standard tier, 1 replica, free level of semantic search. Pricing per hour. [Pricing](https://azure.microsoft.com/pricing/details/search/)
92+
- Azure Blob Storage: Standard tier with ZRS (Zone-redundant storage). Pricing per storage and read operations. [Pricing](https://azure.microsoft.com/pricing/details/storage/blobs/)
93+
- Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)
94+
95+
To reduce costs, you can switch to free SKUs for various services, but those SKUs have limitations.
96+
See this guide on [deploying with minimal costs](/docs/deploy_lowcost.md) for more details.
97+
98+
⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use,
99+
either by deleting the resource group in the Portal or running `azd down`.
100+
101+
### Project setup
102+
103+
You have a few options for setting up this project.
104+
The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you,
105+
but you can also [set it up locally](#local-environment) if desired.
106+
107+
#### GitHub Codespaces
108+
109+
You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:
110+
111+
[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=599293758&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
112+
113+
Once the codespace opens (this may take several minutes), open a terminal window.
114+
115+
#### VS Code Dev Containers
116+
117+
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers):
118+
119+
1. Start Docker Desktop (install it if not already installed)
120+
1. Open the project:
121+
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-search-openai-demo)
122+
1. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
123+
124+
#### Local environment
125+
126+
1. Install the required tools:
127+
128+
* [Azure Developer CLI](https://aka.ms/azure-dev/install)
129+
* [Python 3.9, 3.10, or 3.11](https://www.python.org/downloads/)
130+
* **Important**: Python and the pip package manager must be in the path in Windows for the setup scripts to work.
131+
* **Important**: Ensure you can run `python --version` from console. On Ubuntu, you might need to run `sudo apt install python-is-python3` to link `python` to `python3`.
132+
* [Node.js 14+](https://nodejs.org/en/download/)
133+
* [Git](https://git-scm.com/downloads)
134+
* [Powershell 7+ (pwsh)](https://github.com/powershell/powershell) - For Windows users only.
135+
* **Important**: Ensure you can run `pwsh.exe` from a PowerShell terminal. If this fails, you likely need to upgrade PowerShell.
136+
137+
2. Create a new folder and switch to it in the terminal.
138+
3. Run this command to download the project code:
139+
140+
```shell
141+
azd init -t azure-search-openai-demo
142+
```
143+
144+
Note that this command will initialize a git repository, so you do not need to clone this repository.
145+
146+
### Deploying
147+
148+
Follow these steps to provision Azure resources and deploy the application code:
149+
150+
1. Login to your Azure account:
151+
152+
```shell
153+
azd auth login
154+
```
155+
156+
1. Create a new azd environment:
157+
158+
```shell
159+
azd env new
160+
```
161+
162+
Enter a name that will be used for the resource group.
163+
This will create a new folder in the `.azure` folder, and set it as the active environment for any calls to `azd` going forward.
164+
1. (Optional) This is the point where you can customize the deployment by setting environment variables, in order to [use existing resources](/docs/deploy_existing.md), [enable optional features (such as auth or vision)](/docs/deploy_features.md), or [deploy to free tiers](/docs/deploy_lowcost.md).
165+
1. Run `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.
166+
* **Important**: Beware that the resources created by this command will incur immediate costs, primarily from the AI Search resource. These resources may accrue costs even if you interrupt the command before it is fully executed. You can run `azd down` or delete the resources manually to avoid unnecessary spending.
167+
* You will be prompted to select two locations, one for the majority of resources and one for the OpenAI resource, which is currently a short list. That location list is based on the [OpenAI model availability table](https://learn.microsoft.com/azure/cognitive-services/openai/concepts/models#model-summary-table-and-region-availability) and may become outdated as availability changes.
168+
1. After the application has been successfully deployed you will see a URL printed to the console. Click that URL to interact with the application in your browser.
169+
It will look like the following:
170+
171+
!['Output from running azd up'](/docs/images/endpoint.png)
172+
173+
> NOTE: It may take 5-10 minutes after you see 'SUCCESS' for the application to be fully deployed. If you see a "Python Developer" welcome screen or an error page, then wait a bit and refresh the page. See [guide on debugging App Service deployments](/docs/appservice.md).
174+
175+
### Deploying again
176+
177+
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:
178+
179+
```azd deploy```
180+
181+
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:
182+
183+
```azd up```
184+
185+
186+
## Sharing environments
187+
188+
To give someone else access to a completely deployed and existing environment,
189+
either you or they can follow these steps:
190+
191+
1. Install the [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli)
192+
1. Run `azd init -t azure-search-openai-demo` or clone this repository.
193+
1. Run `azd env refresh -e {environment name}`
194+
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.
195+
1. Set the environment variable `AZURE_PRINCIPAL_ID` either in that `.env` file or in the active shell to their Azure ID, which they can get with `az ad signed-in-user show`.
196+
1. Run `./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.
197+
198+
## Running locally
199+
200+
You can only run locally **after** having successfully run the `azd up` command. If you haven't yet, follow the steps in [Azure deployment](#azure-deployment) above.
201+
202+
1. Run `azd auth login`
203+
2. Change dir to `app`
204+
3. Run `./start.ps1` or `./start.sh` or run the "VS Code Task: Start App" to start the project locally.
205+
206+
See more tips in [the local development guide](/docs/localdev.md).
207+
208+
## Using the app
209+
210+
* In Azure: navigate to the Azure WebApp deployed by azd. The URL is printed out when azd completes (as "Endpoint"), or you can find it in the Azure portal.
211+
* Running locally: navigate to 127.0.0.1:50505
212+
213+
Once in the web app:
214+
215+
* Try different topics in chat or Q&A context. For chat, try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.
216+
* Explore citations and sources
217+
* Click on "settings" to try different options, tweak prompts, etc.
218+
219+
## Monitoring with Application Insights
220+
221+
By default, deployed apps use Application Insights for the tracing of each request, along with the logging of errors.
222+
223+
To see the performance data, go to the Application Insights resource in your resource group, click on the "Investigate -> Performance" blade and navigate to any HTTP request to see the timing data.
224+
To inspect the performance of chat requests, use the "Drill into Samples" button to see end-to-end traces of all the API calls made for any chat request:
225+
226+
![Tracing screenshot](/docs/images/transaction-tracing.png)
227+
228+
To see any exceptions and server errors, navigate to the "Investigate -> Failures" blade and use the filtering tools to locate a specific exception. You can see Python stack traces on the right-hand side.
229+
230+
You can also see chart summaries on a dashboard by running the following command:
231+
232+
```shell
233+
azd monitor
234+
```
235+
236+
## Customizing the UI and data
237+
238+
Once you successfully deploy the app, you can start customizing it for your needs: changing the text, tweaking the prompts, and replacing the data. Consult the [app customization guide](/docs/customization.md) as well as the [data ingestion guide](/docs/data_ingestion.md) for more details.
239+
240+
## Productionizing
241+
242+
This sample is designed to be a starting point for your own production application,
243+
but you should do a thorough review of the security and performance before deploying
244+
to production. Read through our [productionizing guide](/docs/productionizing.md) for more details.
245+
246+
## Clean up
247+
248+
To clean up all the resources created by this sample:
249+
250+
1. Run `azd down`
251+
2. When asked if you are sure you want to continue, enter `y`
252+
3. When asked if you want to permanently delete the resources, enter `y`
253+
254+
The resource group and all the resources will be deleted.
255+
256+
## Troubleshooting
257+
258+
Here are the most common failure scenarios and solutions:
259+
260+
1. 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](https://aka.ms/oai/access).
261+
262+
1. 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](https://aka.ms/oai/models).
263+
264+
1. You've exceeded a quota, most often number of resources per region. See [this article on quotas and limits](https://aka.ms/oai/quotas).
265+
266+
1. 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](https://learn.microsoft.com/azure/cognitive-services/manage-resources?tabs=azure-portal#purge-a-deleted-resource).
267+
268+
1. 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](https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3/43855394#43855394).
269+
270+
1. 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 the [guide on debugging App Service deployments](/docs/appservice.md). Please file an issue if the logs don't help you resolve the error.
271+
272+
## Resources
273+
274+
* [Additional documentation for this app](/docs/README.md)
275+
* [📖 Revolutionize your Enterprise Data with ChatGPT: Next-gen Apps w/ Azure OpenAI and AI Search](https://aka.ms/entgptsearchblog)
276+
* [📖 Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search)
277+
* [📖 Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/overview)
278+
* [📖 Comparing Azure OpenAI and OpenAI](https://learn.microsoft.com/azure/cognitive-services/openai/overview#comparing-azure-openai-and-openai/)
279+
* [📖 Access Control in Generative AI applications with Azure Cognitive Search](https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/access-control-in-generative-ai-applications-with-azure/ba-p/3956408)
280+
* [📺 Quickly build and deploy OpenAI apps on Azure, infused with your own data](https://www.youtube.com/watch?v=j8i-OM5kwiY)
281+
* [📺 AI Chat App Hack series](https://www.youtube.com/playlist?list=PL5lwDBUC0ag6_dGZst5m3G72ewfwXLcXV)
282+
283+
284+
### Getting help
285+
286+
This is a sample built to demonstrate the capabilities of modern Generative AI apps and how they can be built in Azure.
287+
For help with deploying this sample, please post in [GitHub Issues](/issues). If you're a Microsoft employee, you can also post in [our Teams channel](https://aka.ms/azai-python-help).
288+
289+
This repository is supported by the maintainers, _not_ by Microsoft Support,
290+
so please use the support mechanisms described above, and we will do our best to help you out.
291+
292+
### Note
293+
294+
>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.

0 commit comments

Comments
 (0)