Skip to content

Commit 7e2f1c5

Browse files
Initial doc updates (#188)
## Purpose Fix documentation related issues. Tracked in #174 Fixes #133 Fixes #171 Fixes #173 Fixes #176 ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [x] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [x] Documentation content changes [ ] Other... Please describe: ``` ## How to Test * Get the code ``` git clone [repo-address] cd [repo-name] git checkout [branch-name] npm install ``` * Test the code <!-- Add steps to run the tests suite and/or manually test --> ``` ``` ## What to Check Verify that the following are valid * ... ## Other Information <!-- Add any other helpful information that may be needed here. --> --------- Co-authored-by: Aaron Powell <[email protected]>
1 parent e2290b0 commit 7e2f1c5

File tree

3 files changed

+117
-31
lines changed

3 files changed

+117
-31
lines changed

README.md

Lines changed: 117 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
# ChatGPT + Enterprise data with Azure OpenAI and Cognitive Search
1+
---
2+
page_type: sample
3+
languages:
4+
- csharp
5+
products:
6+
- ai-services
7+
- azure-blob-storage
8+
- azure-container-apps
9+
- azure-cognitive-search
10+
- azure-openai
11+
- aspnet-core
12+
- blazor
13+
- defender-for-cloud
14+
- azure-monitor
15+
---
16+
17+
# ChatGPT + Enterprise data with Azure OpenAI and Cognitive Search (.NET)
218

319
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Azure-Samples/azure-search-openai-demo-csharp/dotnet-build.yml?label=BUILD%20%26%20TEST&logo=github&style=for-the-badge)
420
[![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=624102171&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
@@ -8,7 +24,7 @@ This sample demonstrates a few approaches for creating ChatGPT-like experiences
824

925
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.
1026

11-
![RAG Architecture](docs/appcomponents-version-3.png)
27+
![RAG Architecture](docs/appcomponents-version-4.png)
1228

1329
For more details on how this application was built, check out:
1430

@@ -28,63 +44,90 @@ We want to hear from you! Are you interested in building or currently building i
2844

2945
![Chat screen](docs/chatscreen.png)
3046

47+
## Application architecture
48+
49+
- **User interface** - The application’s chat interface is a [Blazor WebAssembly](https://learn.microsoft.com/aspnet/core/blazor/) application. This interface is what accepts user queries, routes request to the application backend, and displays generated responses.
50+
- **Backend** - The application backend is an [ASP.NET Core Minimal API](https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/overview). The backend hosts the Blazor static web application and what orchestrates the interactions among the different services. Services used in this application include:
51+
- [**Azure Cognitive Search**](https://learn.microsoft.com/azure/search/search-what-is-azure-search) – indexes documents from the data stored in an Azure Storage Account. This makes the documents searchable using [vector search](https://learn.microsoft.com/azure/search/search-get-started-vector) capabilities.
52+
- [**Azure OpenAI Service**](https://learn.microsoft.com/azure/ai-services/openai/overview) – provides the Large Language Models to generate responses. [Semantic Kernel](https://learn.microsoft.com/semantic-kernel/whatissk) is used in conjunction with the Azure OpenAI Service to orchestrate the more complex AI workflows.
53+
3154
## Getting Started
3255

33-
> **Note**<br>
34-
> 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](https://aka.ms/oaiapply). You can also visit [here](https://azure.microsoft.com/free/cognitive-search/) to get some free Azure credits to get you started.
56+
### Account Requirements
57+
58+
In order to deploy and run this example, you'll need
59+
60+
- **Azure Account** - If you're new to Azure, get an [Azure account for free](https://aka.ms/free) and you'll get some free Azure credits to get started.
61+
- **Azure subscription with access enabled for the Azure OpenAI service** - [You can request access](https://aka.ms/oaiapply). You can also visit [the Cognitive Search docs](https://azure.microsoft.com/free/cognitive-search/) to get some free Azure credits to get you started.
62+
- **Azure account permissions** - Your Azure Account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [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).
63+
3564

3665
> **Warning**<br>
37-
> By default this sample will create an Azure App Service, Azure Static Web App, and Azure Cognitive Search resource 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.)
66+
> By default this sample will create an Azure Container App, and Azure Cognitive Search resource 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.)
67+
68+
### Cost estimation
69+
70+
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. However, you can try the [Azure pricing calculator](https://azure.microsoft.com/pricing/calculator/) for the resources below:
71+
72+
- [**Azure Container Apps**](https://azure.microsoft.com/pricing/details/container-apps/)
73+
- [**Azure OpenAI Service**](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/)
74+
- [**Azure Form Recognizer**](https://azure.microsoft.com/pricing/details/form-recognizer/)
75+
- [**Azure Cognitive Search**](https://azure.microsoft.com/pricing/details/search/)
76+
- [**Azure Blob Storage**](https://azure.microsoft.com/pricing/details/storage/blobs/)
77+
- [**Azure Monitor**](https://azure.microsoft.com/pricing/details/monitor/)
3878

39-
### Running the application
79+
### Project setup
4080

41-
#### GitHub Codespaces or VS Code Remote Containers
81+
You have a few options for setting up this project. The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up [locally](#local-environment) if desired.
4282

43-
You can run this repo virtually by using GitHub Codespaces or VS Code Remote Containers. When using GitHub Codespaces or VS Code Remote Containers all the required software will be installed in the container.
83+
#### GitHub Codespaces
4484

45-
Click on one of the buttons below to open this repo in one of those options.
85+
You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:
4686

4787
[![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=624102171&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)
48-
[![Open in Remote - Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Remote%20-%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-csharp)
4988

50-
##### Project Initialization
89+
#### VS Code Remote Containers
5190

52-
1. Run `azd auth login`
53-
1. Run `azd env new azure-search-openai-demo-csharp`
91+
A related option is VS Code Remote Containers, which will open the project in your local VS Code using the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension:
92+
93+
[![Open in Remote - Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Remote%20-%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-csharp)
5494

55-
#### Run Locally
95+
#### Local environment
5696

5797
Install the following prerequisites:
5898

5999
- [Azure Developer CLI](https://aka.ms/azure-dev/install)
60100
- [.NET 7](https://dotnet.microsoft.com/download)
61101
- [Git](https://git-scm.com/downloads)
62102
- [Powershell 7+ (pwsh)](https://github.com/powershell/powershell) - For Windows users only.
63-
- **Important**: Ensure you can run `pwsh.exe` from a PowerShell command. If this fails, you likely need to upgrade PowerShell.
103+
104+
> **Important**<br>
105+
> Ensure you can run `pwsh.exe` from a PowerShell command. If this fails, you likely need to upgrade PowerShell.
106+
64107
- [Docker](https://www.docker.com/products/docker-desktop/)
65-
- **Important**: Ensure Docker is running before running any `azd` provisioning / deployment commands.
66108

67-
##### Project Initialization
109+
> **Important**<br>
110+
> Ensure Docker is running before running any `azd` provisioning / deployment commands.
68111
69-
1. Create a new folder and switch to it in the terminal
70-
1. Run `azd auth login`
71-
1. Run `azd init -t azure-search-openai-demo-csharp`
112+
Then, run the following commands to get the project on your local environment:
72113

73-
> **Note**<br>
74-
> Your Azure Account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [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).
114+
1. Run `azd auth login`
115+
1. Clone the repository or run `azd init -t azure-search-openai-demo-csharp`
116+
1. Run `azd env new azure-search-openai-demo-csharp`
75117

76-
### Installation
118+
### Deploying from scratch
77119

78-
#### Starting from scratch
120+
> **Important**<br>
121+
> Ensure Docker is running before running any `azd` provisioning / deployment commands.
79122
80123
Execute the following command, if you don't have any pre-existing Azure services and want to start from a fresh deployment.
81124

82125
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.
83126
- For the target location, the regions that currently support the model used in this sample are **East US 2** , **East US** or **South Central US**. For an up-to-date list of regions and models, check [here](https://learn.microsoft.com/azure/cognitive-services/openai/concepts/models)
84127
- If you have access to multiple Azure subscriptions, you will be prompted to select the subscription you want to use. If you only have access to one subscription, it will be selected automatically.
85128

86-
> **Note**<br>
87-
> This application uses the `gpt-35-turbo` model. When choosing which region to deploy to, make sure they're available in that region (i.e. EastUS). For more information, see the [Azure OpenAI Service documentation](https://learn.microsoft.com/azure/cognitive-services/openai/concepts/models#gpt-35-models).
129+
> **Note**<br>
130+
> This application uses the `gpt-35-turbo` model. When choosing which region to deploy to, make sure they're available in that region (i.e. EastUS). For more information, see the [Azure OpenAI Service documentation](https://learn.microsoft.com/azure/cognitive-services/openai/concepts/models#gpt-35-models).
88131
89132
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.
90133

@@ -102,13 +145,17 @@ If you have existing resources in Azure that you wish to use, you can configure
102145
1. Run `azd env set AZURE_OPENAI_SERVICE {Name of existing OpenAI service}`
103146
1. Run `azd env set AZURE_OPENAI_RESOURCE_GROUP {Name of existing resource group that OpenAI service is provisioned to}`
104147
1. Run `azd env set AZURE_OPENAI_CHATGPT_DEPLOYMENT {Name of existing ChatGPT deployment}`. Only needed if your ChatGPT deployment is not the default 'chat'.
105-
1. Run `azd env set AZURE_OPENAI_GPT_DEPLOYMENT {Name of existing GPT deployment}`. Only needed if your ChatGPT deployment is not the default `davinci`.
148+
1. Run `azd env set AZURE_OPENAI_EMBEDDING_DEPLOYMENT {Name of existing embedding model deployment}`. Only needed if your embedding model deployment is not the default `embedding`.
106149
1. Run `azd up`
107150

108-
> NOTE: You can also use existing Search and Storage Accounts. See `./infra/main.parameters.json` for list of environment variables to pass to `azd env set` to configure those existing resources.
151+
> **Note**<br>
152+
> You can also use existing Search and Storage Accounts. See `./infra/main.parameters.json` for list of environment variables to pass to `azd env set` to configure those existing resources.
109153
110154
#### Deploying or re-deploying a local clone of the repo
111155

156+
> **Important**<br>
157+
> Ensure Docker is running before running any `azd` provisioning / deployment commands.
158+
112159
- Run `azd up`
113160

114161
#### Deploying your repo using App Spaces
@@ -149,6 +196,9 @@ If you have existing resources in Azure that you wish to use, you can configure
149196

150197
#### Running locally
151198

199+
> **Important**<br>
200+
> Ensure Docker is running before running any `azd` provisioning / deployment commands.
201+
152202
1. Run `azd auth login`
153203
1. After the application deploys, set the environment variable `AZURE_KEY_VAULT_ENDPOINT`. You can find the value in the _.azure/YOUR-ENVIRONMENT-NAME/.env_ file or the Azure portal.
154204
1. Run the following .NET CLI command to start the ASP.NET Core Minimal API server (client host):
@@ -172,19 +222,55 @@ Run the following if you want to give someone else access to the deployed and ex
172222

173223
Run `azd down`
174224

175-
### Quickstart
225+
### Using the app
176226

177-
- In Azure: navigate to the Azure Static Web App deployed by `azd`. The URL is printed out when `azd` completes (as "Endpoint"), or you can find it in the Azure portal.
227+
- In Azure: navigate to the Azure Container App deployed by `azd`. The URL is printed out when `azd` completes (as "Endpoint"), or you can find it in the Azure portal.
178228
- When running locally, navigate to <http://localhost:7181> for the client app and <http://localhost:7181/swagger> for the Open API server page.
179229

180230
Once in the web app:
181231

182232
- On the **Voice Chat** page, select the voice settings dialog and configure text-to-speech preferences.
183233
- You can either type messages to interact with Blazor Clippy, or select the Speak toggle button to use speech-to-text as your input.
184-
- Try different topics in **Chat** or **Ask Questions** context. For chat, try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.
234+
- Try different topics in **Chat** context. For chat, try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.
185235
- Explore citations and sources
186236
- Click on the "settings" icon to try different options, tweak prompts, etc.
187237

238+
## Enabling optional features
239+
240+
### Enabling Application Insights
241+
242+
To enable Application Insights and the tracing of each request, along with the logging of errors, set the `AZURE_USE_APPLICATION_INSIGHTS` variable to true before running `azd up`
243+
244+
1. Run `azd env set AZURE_USE_APPLICATION_INSIGHTS true`
245+
1. Run `azd up`
246+
247+
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.
248+
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:
249+
250+
![Tracing screenshot](docs/transaction-tracing.png)
251+
252+
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.
253+
254+
### Enabling authentication
255+
256+
By default, the deployed Azure container app will have no authentication or access restrictions enabled, meaning anyone with routable network access to the container app can chat with your indexed data. You can require authentication to your Azure Active Directory by following the [Add container app authentication](https://learn.microsoft.com/azure/container-apps/authentication-azure-active-directory) tutorial and set it up against the deployed container app.
257+
258+
To then limit access to a specific set of users or groups, you can follow the steps from [Restrict your Azure AD app to a set of users](https://learn.microsoft.com/azure/active-directory/develop/howto-restrict-your-app-to-a-set-of-users) by changing "Assignment Required?" option under the Enterprise Application, and then assigning users/groups access. Users not granted explicit access will receive the error message -AADSTS50105: Your administrator has configured the application <app_name> to block users unless they are specifically granted ('assigned') access to the application.-
259+
260+
## Productionizing
261+
262+
This sample is designed to be a starting point for your own production application,
263+
but you should do a thorough review of the security and performance before deploying
264+
to production. Here are some things to consider:
265+
266+
* **OpenAI Capacity**: The default TPM (tokens per minute) is set to 30K. That is equivalent to approximately 30 conversations per minute (assuming 1K per user message/response). You can increase the capacity by changing the `chatGptDeploymentCapacity` and `embeddingDeploymentCapacity` parameters in `infra/main.bicep` to your account's maximum capacity. You can also view the Quotas tab in [Azure OpenAI studio](https://oai.azure.com/) to understand how much capacity you have.
267+
* **Azure Storage**: The default storage account uses the `Standard_LRS` SKU. To improve your resiliency, we recommend using `Standard_ZRS` for production deployments, which you can specify using the `sku` property under the `storage` module in `infra/main.bicep`.
268+
* **Azure Cognitive Search**: If you see errors about search service capacity being exceeded, you may find it helpful to increase the number of replicas by changing `replicaCount` in `infra/core/search/search-services.bicep` or manually scaling it from the Azure Portal.
269+
* **Azure Container Apps**: By default, this application deploys containers with 0.5 CPU Cores and 1GB of memory. The minimum replicas is 1 and maximum 10. For this app, you can set values such as `containerCpuCoreCount`, `containerMaxReplicas `, `containerMemory`, `containerMinReplicas` in the `infra/core/host/container-app.bicep` file to fit your needs. You can use auto-scaling rules or scheduled scaling rules, and scale up the [maximum/minimum](https://learn.microsoft.com/azure/container-apps/scale-app) based on load.
270+
* **Authentication**: By default, the deployed app is publicly accessible. We recommend restricting access to authenticated users. See [Enabling authentication](#enabling-authentication) above for how to enable authentication.
271+
* **Networking**: We recommend deploying inside a Virtual Network. If the app is only for internal enterprise use, use a private DNS zone. Also consider using Azure API Management (APIM) for firewalls and other forms of protection. For more details, read [Azure OpenAI Landing Zone reference architecture](https://techcommunity.microsoft.com/t5/azure-architecture-blog/azure-openai-landing-zone-reference-architecture/ba-p/3882102).
272+
* **Loadtesting**: We recommend running a loadtest for your expected number of users.
273+
188274
## Resources
189275

190276
- [Revolutionize your Enterprise Data with ChatGPT: Next-gen Apps w/ Azure OpenAI and Cognitive Search](https://aka.ms/entgptsearchblog)

docs/appcomponents-version-4.png

53.2 KB
Loading

docs/transaction-tracing.png

734 KB
Loading

0 commit comments

Comments
 (0)