Skip to content

Commit 2f977e9

Browse files
authored
Merge branch 'main' into azdenvgetval
2 parents 7281d2b + c5ce017 commit 2f977e9

File tree

79 files changed

+4204
-1890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4204
-1890
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}
5555
},
5656
// Use 'postCreateCommand' to run commands after the container is created.
57-
"postCreateCommand": "pip install -r requirements-dev.txt && pip install -e src",
57+
"postCreateCommand": "pip install -r requirements-dev.txt && pip install -e src/backend",
5858
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
5959
"remoteUser": "vscode"
6060
}

.github/workflows/app-tests.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
812

913
jobs:
10-
test_package:
14+
test-package:
1115
name: Test ${{ matrix.os }} Python ${{ matrix.python_version }}
1216
runs-on: ${{ matrix.os }}
1317
strategy:
@@ -51,12 +55,12 @@ jobs:
5155
python -m pip install -r requirements-dev.txt
5256
- name: Install app as editable app
5357
run: |
54-
python -m pip install -e src
58+
python -m pip install -e src/backend
5559
- name: Setup local database with seed data
5660
run: |
5761
cp .env.sample .env
58-
python ./src/fastapi_app/setup_postgres_database.py
59-
python ./src/fastapi_app/setup_postgres_seeddata.py
62+
python ./src/backend/fastapi_app/setup_postgres_database.py
63+
python ./src/backend/fastapi_app/setup_postgres_seeddata.py
6064
- name: Setup node
6165
uses: actions/setup-node@v4
6266
with:
@@ -65,4 +69,8 @@ jobs:
6569
run: |
6670
cd ./src/frontend
6771
npm install
68-
npm run build
72+
npm run build
73+
- name: Run MyPy
74+
run: python3 -m mypy .
75+
- name: Run Pytest
76+
run: python3 -m pytest

.github/workflows/python-code-quality.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,34 @@ name: Python code quality
33
on:
44
push:
55
branches: [ main ]
6+
paths:
7+
- '**.py'
8+
69
pull_request:
710
branches: [ main ]
11+
paths:
12+
- '**.py'
13+
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
818

919
jobs:
10-
build:
20+
checks-format-and-lint:
1121
runs-on: ubuntu-latest
1222
steps:
1323
- uses: actions/checkout@v4
1424
- name: Set up Python 3
1525
uses: actions/setup-python@v5
1626
with:
1727
python-version: "3.12"
28+
cache: 'pip'
1829
- name: Install dependencies
1930
run: |
20-
python -m pip install --upgrade pip
21-
pip install -r requirements-dev.txt
31+
python3 -m pip install --upgrade pip
32+
python3 -m pip install ruff
2233
- name: Lint with ruff
2334
run: ruff check .
2435
- name: Check formatting with ruff
25-
run: ruff format --check .
36+
run: ruff format . --check

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project is designed for deployment to Azure using [the Azure Developer CLI]
1313
* [Local development](#local-development)
1414
* [Costs](#costs)
1515
* [Security guidelines](#security-guidelines)
16+
* [Guidance](#guidance)
1617
* [Resources](#resources)
1718

1819
## Features
@@ -58,6 +59,7 @@ A related option is VS Code Dev Containers, which will open the project in your
5859
1. Make sure the following tools are installed:
5960

6061
* [Azure Developer CLI (azd)](https://aka.ms/install-azd)
62+
* [Node.js 18+](https://nodejs.org/download/)
6163
* [Python 3.10+](https://www.python.org/downloads/)
6264
* [PostgreSQL 14+](https://www.postgresql.org/download/)
6365
* [pgvector](https://github.com/pgvector/pgvector)
@@ -99,6 +101,8 @@ Once you've opened the project in [Codespaces](#github-codespaces), [Dev Contain
99101
100102
This will create a folder under `.azure/` in your project to store the configuration for this deployment. You may have multiple azd environments if desired.
101103
104+
3. (Optional) If you would like to customize the deployment to [use existing Azure resources](docs/deploy_existing.md), you can set the values now.
105+
102106
3. Provision the resources and deploy the code:
103107
104108
```shell
@@ -128,9 +132,9 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
128132
1. Run these commands to install the web app as a local package (named `fastapi_app`), set up the local database, and seed it with test data:
129133
130134
```bash
131-
python3 -m pip install -e src
132-
python ./src/fastapi_app/setup_postgres_database.py
133-
python ./src/fastapi_app/setup_postgres_seeddata.py
135+
python3 -m pip install -e src/backend
136+
python ./src/backend/fastapi_app/setup_postgres_database.py
137+
python ./src/backend/fastapi_app/setup_postgres_seeddata.py
134138
```
135139
136140
2. Build the frontend:
@@ -139,7 +143,7 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
139143
cd src/frontend
140144
npm install
141145
npm run build
142-
cd ../..
146+
cd ../../
143147
```
144148
145149
There must be an initial build of static assets before running the backend, since the backend serves static files from the `src/static` directory.
@@ -173,12 +177,22 @@ You may try the [Azure pricing calculator](https://azure.microsoft.com/pricing/c
173177
* Azure PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. [Pricing](https://azure.microsoft.com/pricing/details/postgresql/flexible-server/)
174178
* Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)
175179
176-
## Security Guidelines
180+
## Security guidelines
177181
178182
This template uses [Managed Identity](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) for authenticating to the Azure services used (Azure OpenAI, Azure PostgreSQL Flexible Server).
179183
180184
Additionally, we have added a [GitHub Action](https://github.com/microsoft/security-devops-action) that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure continued best practices in your own repository, we recommend that anyone creating solutions based on our templates ensure that the [Github secret scanning](https://docs.github.com/code-security/secret-scanning/about-secret-scanning) setting is enabled.
181185
186+
## Guidance
187+
188+
Further documentation is available in the `docs/` folder:
189+
190+
* [Deploying with existing resources](docs/deploy_existing.md)
191+
* [Monitoring with Azure Monitor](docs/monitoring.md)
192+
* [Load testing](docs/loadtesting.md)
193+
194+
Please post in the issue tracker with any questions or issues.
195+
182196
## Resources
183197
184198
* [RAG chat with Azure AI Search + Python](https://github.com/Azure-Samples/azure-search-openai-demo/)

azure.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ metadata:
44
55
services:
66
web:
7-
project: ./src
7+
project: ./src/backend
88
language: py
99
module: web
1010
host: containerapp
1111
hooks:
12-
prepackage:
12+
prebuild:
1313
windows:
1414
shell: pwsh
15-
run: cd frontend;npm install;npm run build
15+
run: cd ../frontend;npm install;npm run build
1616
interactive: false
1717
continueOnError: false
1818
posix:
1919
shell: sh
20-
run: cd frontend;npm install;npm run build
20+
run: cd ../frontend;npm install;npm run build
2121
interactive: false
2222
continueOnError: false
2323
hooks:

docs/deploy_existing.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Deploying with existing Azure resources
2+
3+
If you already have existing Azure resources, or if you want to specify the exact name of new Azure Resource, you can do so by setting `azd` environment values.
4+
You should set these values before running `azd up`. Once you've set them, return to the [deployment steps](../README.md#deployment).
5+
6+
### Openai.com OpenAI account
7+
8+
1. Run `azd env set DEPLOY_AZURE_OPENAI false`
9+
1. Run `azd env set OPENAI_CHAT_HOST openaicom`
10+
2. Run `azd env set OPENAI_EMBED_HOST openaicom`
11+
3. Run `azd env set OPENAICOM_KEY {Your OpenAI API key}`
12+
4. Run `azd up`
13+
14+
You can retrieve your OpenAI key by checking [your user page](https://platform.openai.com/account/api-keys).
15+
Learn more about creating an OpenAI free trial at [this link](https://openai.com/pricing).
16+
Do *not* check your key into source control.
17+
18+
When you run `azd up` after and are prompted to select a value for `openAiResourceGroupLocation`, you can select any location as it will not be used.

docs/images/appinsights_trace.png

63.3 KB
Loading

docs/images/locust_loadtest.png

37.6 KB
Loading

docs/loadtesting.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Load testing
2+
3+
We recommend running a loadtest for your expected number of users.
4+
You can use the [locust tool](https://docs.locust.io/) with the `locustfile.py` in this sample
5+
or set up a loadtest with Azure Load Testing.
6+
7+
To use locust, first install the dev requirements that includes locust:
8+
9+
```shell
10+
python -m pip install -r requirements-dev.txt
11+
```
12+
13+
Or manually install locust:
14+
15+
```shell
16+
python -m pip install locust
17+
```
18+
19+
Then run the locust command, specifying the name of the User class to use from `locustfile.py` or using the default class. We've provided a `ChatUser` class that simulates a user asking questions and receiving answers.
20+
21+
```shell
22+
locust
23+
```
24+
25+
Open the locust UI at [http://localhost:8089/](http://localhost:8089/), the URI displayed in the terminal.
26+
27+
Start a new test with the URI of your website, e.g. `https://my-chat-app.containerapps.io`.
28+
Do *not* end the URI with a slash. You can start by pointing at your localhost if you're concerned
29+
more about load on OpenAI than on Azure Container Apps and PostgreSQL Flexible Server.
30+
31+
For the number of users and spawn rate, we recommend starting with 20 users and 1 users/second.
32+
From there, you can keep increasing the number of users to simulate your expected load.
33+
34+
Here's an example loadtest for 20 users and a spawn rate of 1 per second:
35+
36+
![Screenshot of Locust charts showing 5 requests per second](images/locust_loadtest.png)
37+
38+
After each test, check the local or App Service logs to see if there are any errors.

docs/monitoring.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Monitoring with Azure Monitor
3+
4+
By default, deployed apps use Application Insights for the tracing of each request, along with the logging of errors.
5+
6+
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.
7+
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:
8+
9+
![Tracing screenshot](images/appinsights_trace.png)
10+
11+
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.
12+
13+
You can also see chart summaries on a dashboard by running the following command:
14+
15+
```shell
16+
azd monitor
17+
```

0 commit comments

Comments
 (0)