Skip to content

Commit 400d313

Browse files
committed
Merge branch 'contentunderstanding' of https://github.com/pamelafox/azure-search-openai-demo into contentunderstanding
2 parents 0681755 + 109d7d4 commit 400d313

22 files changed

+304
-173
lines changed

.github/workflows/python-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
python-version: ${{ matrix.python_version }}
3737
architecture: x64
3838
- name: Install uv
39-
uses: astral-sh/setup-uv@v3
39+
uses: astral-sh/setup-uv@v4
4040
with:
4141
enable-cache: true
4242
version: "0.4.20"

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"env": {
1515
"QUART_APP": "main:app",
1616
"QUART_ENV": "development",
17-
"QUART_DEBUG": "0"
17+
"QUART_DEBUG": "0",
18+
// Set this to "no-override" if you want env vars here to override AZD env vars
19+
"LOADING_MODE_FOR_AZD_ENV_VARS": "override"
1820
},
1921
"args": [
2022
"run",

CONTRIBUTING.md

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,15 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
1212
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
1313
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
1414

15-
- [Code of Conduct](#code-of-conduct)
16-
- [Found an Issue?](#found-an-issue)
17-
- [Want a Feature?](#want-a-feature)
18-
- [Submission Guidelines](#submission-guidelines)
19-
- [Submitting an Issue](#submitting-an-issue)
20-
- [Submitting a Pull Request (PR)](#submitting-a-pull-request-pr)
15+
- [Submitting a Pull Request (PR)](#submitting-a-pull-request-pr)
2116
- [Setting up the development environment](#setting-up-the-development-environment)
2217
- [Running unit tests](#running-unit-tests)
2318
- [Running E2E tests](#running-e2e-tests)
24-
- [Code Style](#code-style)
19+
- [Code style](#code-style)
2520
- [Adding new azd environment variables](#adding-new-azd-environment-variables)
21+
- [Adding new UI strings](#adding-new-ui-strings)
2622

27-
## Code of Conduct
28-
29-
Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
30-
31-
## Found an Issue?
32-
33-
If you find a bug in the source code or a mistake in the documentation, you can help us by
34-
[submitting an issue](#submitting-an-issue) to the GitHub Repository. Even better, you can
35-
[submit a Pull Request](#submitting-a-pull-request-pr) with a fix.
36-
37-
## Want a Feature?
38-
39-
You can *request* a new feature by [submitting an issue](#submitting-an-issue) to the GitHub
40-
Repository. If you would like to *implement* a new feature, please submit an issue with
41-
a proposal for your work first, to be sure that we can use it.
42-
43-
- **Small Features** can be crafted and directly [submitted as a Pull Request](#submitting-a-pull-request-pr).
44-
45-
## Submission Guidelines
46-
47-
### Submitting an Issue
48-
49-
Before you submit an issue, search the archive, maybe your question was already answered.
50-
51-
If your issue appears to be a bug, and hasn't been reported, open a new issue.
52-
Help us to maximize the effort we can spend fixing issues and adding new
53-
features, by not reporting duplicate issues. Providing the following information will increase the
54-
chances of your issue being dealt with quickly:
55-
56-
- **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
57-
- **Version** - what version is affected (e.g. 0.1.2)
58-
- **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
59-
- **Browsers and Operating System** - is this a problem with all browsers?
60-
- **Reproduce the Error** - provide a live example or a unambiguous set of steps
61-
- **Related Issues** - has a similar issue been reported before?
62-
- **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
63-
causing the problem (line of code or commit)
64-
65-
You can file new issues by providing the above information at the corresponding repository's issues link: <https://github.com/[organization-name>]/[repository-name]/issues/new].
66-
67-
### Submitting a Pull Request (PR)
23+
## Submitting a Pull Request (PR)
6824

6925
Before you submit your Pull Request (PR) consider the following guidelines:
7026

@@ -135,7 +91,7 @@ playwright show-trace test-results/<trace-zip>
13591

13692
You can also use the online trace viewer at <https://trace.playwright.dev/>
13793

138-
## Code Style
94+
## Code style
13995

14096
This codebase includes several languages: TypeScript, Python, Bicep, Powershell, and Bash.
14197
Code should follow the standard conventions of each language.
@@ -171,3 +127,21 @@ When adding new azd environment variables, please remember to update:
171127
1. App Service's [azure.yaml](./azure.yaml)
172128
1. [ADO pipeline](.azdo/pipelines/azure-dev.yml).
173129
1. [Github workflows](.github/workflows/azure-dev.yml)
130+
131+
## Adding new UI strings
132+
133+
When adding new UI strings, please remember to update all translations.
134+
For any translations that you generate with an AI tool,
135+
please indicate in the PR description which language's strings were AI-generated.
136+
137+
Here are community contributors that can review translations:
138+
139+
| Language | Contributor |
140+
|----------|---------------------|
141+
| Danish | @EMjetrot |
142+
| French | @manekinekko |
143+
| Japanese | @bnodir |
144+
| Norwegian| @@jeannotdamoiseaux |
145+
| Portugese| @glaucia86 |
146+
| Spanish | @miguelmsft |
147+
| Turkish | @mertcakdogan |

README.md

Lines changed: 47 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ This solution's backend is written in Python. There are also [**JavaScript**](ht
2626
[![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)
2727
[![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)
2828

29+
## Important Security Notice
30+
31+
This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features. See our [productionizing guide](docs/productionizing.md) for tips, and consult the [Azure OpenAI Landing Zone reference architecture](https://techcommunity.microsoft.com/blog/azurearchitectureblog/azure-openai-landing-zone-reference-architecture/3882102) for more best practices.
32+
2933
## Table of Contents
3034

3135
- [Features](#features)
@@ -37,15 +41,10 @@ This solution's backend is written in Python. There are also [**JavaScript**](ht
3741
- [Local environment](#local-environment)
3842
- [Deploying](#deploying)
3943
- [Deploying again](#deploying-again)
40-
- [Sharing environments](#sharing-environments)
41-
- [Running locally](#running-locally)
44+
- [Running the development server](#running-the-development-server)
4245
- [Using the app](#using-the-app)
4346
- [Clean up](#clean-up)
4447
- [Guidance](#guidance)
45-
- [Customizing the UI and data](#customizing-the-ui-and-data)
46-
- [Monitoring with Application Insights](#monitoring-with-application-insights)
47-
- [Productionizing](#productionizing)
48-
- [Troubleshooting](#troubleshooting)
4948
- [Resources](#resources)
5049

5150
![Chat screen](docs/images/chatscreen.png)
@@ -198,26 +197,28 @@ If you've changed the infrastructure files (`infra` folder or `azure.yaml`), the
198197
azd up
199198
```
200199

201-
#### Sharing environments
200+
## Running the development server
201+
202+
You can only run a development server locally **after** having successfully run the `azd up` command. If you haven't yet, follow the [deploying](#deploying) steps above.
203+
204+
1. Run `azd auth login` if you have not logged in recently.
205+
2. Start the server:
202206
203-
To give someone else access to a completely deployed and existing environment,
204-
either you or they can follow these steps:
207+
Windows:
205208
206-
1. Install the [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli)
207-
1. Run `azd init -t azure-search-openai-demo` or clone this repository.
208-
1. Run `azd env refresh -e {environment name}`
209-
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.
210-
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`.
211-
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.
209+
```shell
210+
./app/start.ps1
211+
```
212212
213-
## Running locally
213+
Linux/Mac:
214214
215-
You can only run locally **after** having successfully run the `azd up` command. If you haven't yet, follow the [deploying](#deploying) steps above.
215+
```shell
216+
./app/start.sh
217+
```
216218
217-
1. Run `azd auth login`
218-
2. Change dir to `app`
219-
3. Run `./start.ps1` or `./start.sh` or run the "VS Code Task: Start App" to start the project locally.
219+
VS Code: Run the "VS Code Task: Start App" task.
220220
221+
It's also possible to enable hotloading or the VS Code debugger.
221222
See more tips in [the local development guide](docs/localdev.md).
222223

223224
## Using the app
@@ -243,61 +244,35 @@ The resource group and all the resources will be deleted.
243244

244245
## Guidance
245246

246-
Besides the tips below, you can find extensive documentation in the [docs](docs/README.md) folder.
247-
248-
### Customizing the UI and data
249-
250-
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.
251-
252-
### Monitoring with Application Insights
253-
254-
By default, deployed apps use Application Insights for the tracing of each request, along with the logging of errors.
255-
256-
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.
257-
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:
258-
259-
![Tracing screenshot](docs/images/transaction-tracing.png)
260-
261-
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.
262-
263-
You can also see chart summaries on a dashboard by running the following command:
264-
265-
```shell
266-
azd monitor
267-
```
268-
269-
### Productionizing
270-
271-
This sample is designed to be a starting point for your own production application,
272-
but you should do a thorough review of the security and performance before deploying
273-
to production. Read through our [productionizing guide](docs/productionizing.md) for more details.
274-
275-
### Troubleshooting
276-
277-
Here are the most common failure scenarios and solutions:
278-
279-
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).
280-
281-
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).
282-
283-
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).
284-
285-
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).
286-
287-
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).
288-
289-
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 and are deploying to App Service, 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.
247+
You can find extensive documentation in the [docs](docs/README.md) folder:
248+
249+
- Deploying:
250+
- [Troubleshooting deployment](docs/deploy_troubleshooting.md)
251+
- [Debugging the app on App Service](docs/appservice.md)
252+
- [Deploying with azd: deep dive and CI/CD](docs/azd.md)
253+
- [Deploying with existing Azure resources](docs/deploy_existing.md)
254+
- [Deploying from a free account](docs/deploy_lowcost.md)
255+
- [Enabling optional features](docs/deploy_features.md)
256+
- [Login and access control](docs/login_and_acl.md)
257+
- [GPT-4 Turbo with Vision](docs/gpt4v.md)
258+
- [Private endpoints](docs/deploy_private.md)
259+
- [Sharing deployment environments](docs/sharing_environments.md)
260+
- [Local development](docs/localdev.md)
261+
- [Customizing the app](docs/customization.md)
262+
- [Data ingestion](docs/data_ingestion.md)
263+
- [Monitoring with Application Insights](docs/monitoring.md)
264+
- [Productionizing](docs/productionizing.md)
265+
- [Alternative RAG chat samples](docs/other_samples.md)
290266

291267
### Resources
292268

293-
- [Additional documentation for this app](docs/README.md)
294-
- [📖 Revolutionize your Enterprise Data with ChatGPT: Next-gen Apps w/ Azure OpenAI and AI Search](https://techcommunity.microsoft.com/blog/azure-ai-services-blog/revolutionize-your-enterprise-data-with-chatgpt-next-gen-apps-w-azure-openai-and/3762087)
295-
- [📖 Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search)
296-
- [📖 Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/overview)
297-
- [📖 Comparing Azure OpenAI and OpenAI](https://learn.microsoft.com/azure/cognitive-services/openai/overview#comparing-azure-openai-and-openai/)
298-
- [📖 Access Control in Generative AI applications with Azure AI Search](https://techcommunity.microsoft.com/blog/azure-ai-services-blog/access-control-in-generative-ai-applications-with-azure-ai-search/3956408)
299-
- [📺 Quickly build and deploy OpenAI apps on Azure, infused with your own data](https://www.youtube.com/watch?v=j8i-OM5kwiY)
300-
- [📺 AI Chat App Hack series](https://www.youtube.com/playlist?list=PL5lwDBUC0ag6_dGZst5m3G72ewfwXLcXV)
269+
- [📖 Blog: Revolutionize your Enterprise Data with ChatGPT: Next-gen Apps w/ Azure OpenAI and AI Search](https://techcommunity.microsoft.com/blog/azure-ai-services-blog/revolutionize-your-enterprise-data-with-chatgpt-next-gen-apps-w-azure-openai-and/3762087)
270+
- [📖 Docs: Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search)
271+
- [📖 Docs: Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/overview)
272+
- [📖 Docs: Comparing Azure OpenAI and OpenAI](https://learn.microsoft.com/azure/cognitive-services/openai/overview#comparing-azure-openai-and-openai/)
273+
- [📖 Blog: Access Control in Generative AI applications with Azure AI Search](https://techcommunity.microsoft.com/blog/azure-ai-services-blog/access-control-in-generative-ai-applications-with-azure-ai-search/3956408)
274+
- [📺 Talk: Quickly build and deploy OpenAI apps on Azure, infused with your own data](https://www.youtube.com/watch?v=j8i-OM5kwiY)
275+
- [📺 Talks: AI Chat App Hack series](https://www.youtube.com/playlist?list=PL5lwDBUC0ag6_dGZst5m3G72ewfwXLcXV)
301276

302277
### Getting help
303278

app/backend/app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ def create_app():
753753
logging.getLogger("scripts").setLevel(app_level)
754754

755755
if allowed_origin := os.getenv("ALLOWED_ORIGIN"):
756-
app.logger.info("ALLOWED_ORIGIN is set, enabling CORS for %s", allowed_origin)
757-
cors(app, allow_origin=allowed_origin, allow_methods=["GET", "POST"])
756+
allowed_origins = allowed_origin.split(";")
757+
if len(allowed_origins) > 0:
758+
app.logger.info("CORS enabled for %s", allowed_origins)
759+
cors(app, allow_origin=allowed_origins, allow_methods=["GET", "POST"])
760+
758761
return app

app/backend/load_azd_env.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import os
34
import subprocess
45

56
from dotenv import load_dotenv
@@ -19,5 +20,10 @@ def load_azd_env():
1920
env_file_path = entry["DotEnvPath"]
2021
if not env_file_path:
2122
raise Exception("No default azd env file found")
22-
logger.info(f"Loading azd env from {env_file_path}")
23-
load_dotenv(env_file_path, override=True)
23+
loading_mode = os.getenv("LOADING_MODE_FOR_AZD_ENV_VARS") or "override"
24+
if loading_mode == "no-override":
25+
logger.info("Loading azd env from %s, but not overriding existing environment variables", env_file_path)
26+
load_dotenv(env_file_path, override=False)
27+
else:
28+
logger.info("Loading azd env from %s, which may override existing environment variables", env_file_path)
29+
load_dotenv(env_file_path, override=True)

app/backend/prepdocs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ async def main(strategy: Strategy, setup_index: bool = True):
306306

307307
load_azd_env()
308308

309+
if os.getenv("AZURE_PUBLIC_NETWORK_ACCESS") == "Disabled":
310+
logger.error("AZURE_PUBLIC_NETWORK_ACCESS is set to Disabled. Exiting.")
311+
exit(0)
312+
309313
use_int_vectorization = os.getenv("USE_FEATURE_INT_VECTORIZATION", "").lower() == "true"
310314
use_gptvision = os.getenv("USE_GPT4V", "").lower() == "true"
311315
use_acls = os.getenv("AZURE_ADLS_GEN2_STORAGE_ACCOUNT") is not None

app/frontend/src/components/QuestionInput/QuestionInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const QuestionInput = ({ onSend, disabled, placeholder, clearOnSend, init
6565
};
6666

6767
const disableRequiredAccessControl = requireLogin && !loggedIn;
68-
const sendQuestionDisabled = disabled || !question.trim() || requireLogin;
68+
const sendQuestionDisabled = disabled || !question.trim() || disableRequiredAccessControl;
6969

7070
if (disableRequiredAccessControl) {
7171
placeholder = "Please login to continue...";

app/frontend/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import react from "@vitejs/plugin-react";
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
resolve: {
8+
preserveSymlinks: true
9+
},
710
build: {
811
outDir: "../backend/static",
912
emptyOutDir: true,

0 commit comments

Comments
 (0)