Skip to content

Commit d082700

Browse files
committed
Merge branch 'main' into otel
2 parents 4e76272 + 406eb24 commit d082700

Some content is hidden

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

65 files changed

+3262
-480
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 && cp .env.sample .env && python ./src/fastapi_app/setup_postgres_database.py && python ./src/fastapi_app/setup_postgres_seeddata.py",
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
}

.env.sample

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ OPENAI_EMBED_HOST=azure
1313
# You also need to `azd auth login` if running this locally
1414
AZURE_OPENAI_ENDPOINT=https://YOUR-AZURE-OPENAI-SERVICE-NAME.openai.azure.com
1515
AZURE_OPENAI_VERSION=2024-03-01-preview
16-
AZURE_OPENAI_CHAT_DEPLOYMENT=chat
16+
AZURE_OPENAI_CHAT_DEPLOYMENT=gpt-35-turbo
1717
AZURE_OPENAI_CHAT_MODEL=gpt-35-turbo
18-
AZURE_OPENAI_EMBED_DEPLOYMENT=embed
18+
AZURE_OPENAI_EMBED_DEPLOYMENT=text-embedding-ada-002
1919
AZURE_OPENAI_EMBED_MODEL=text-embedding-ada-002
2020
AZURE_OPENAI_EMBED_MODEL_DIMENSIONS=1536
21+
# Only needed when using key-based Azure authentication:
22+
AZURE_OPENAI_KEY=
2123
# Needed for OpenAI.com:
2224
OPENAICOM_KEY=YOUR-OPENAI-API-KEY
2325
OPENAICOM_CHAT_MODEL=gpt-3.5-turbo

.github/workflows/app-tests.yaml

Lines changed: 21 additions & 4 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,9 +55,22 @@ 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
64+
- name: Setup node
65+
uses: actions/setup-node@v4
66+
with:
67+
node-version: 18
68+
- name: Build frontend
69+
run: |
70+
cd ./src/frontend
71+
npm install
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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ A related option is VS Code Dev Containers, which will open the project in your
5858
1. Make sure the following tools are installed:
5959

6060
* [Azure Developer CLI (azd)](https://aka.ms/install-azd)
61+
* [Node.js 18+](https://nodejs.org/download/)
6162
* [Python 3.10+](https://www.python.org/downloads/)
6263
* [PostgreSQL 14+](https://www.postgresql.org/download/)
6364
* [pgvector](https://github.com/pgvector/pgvector)
@@ -99,6 +100,8 @@ Once you've opened the project in [Codespaces](#github-codespaces), [Dev Contain
99100
100101
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.
101102
103+
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.
104+
102105
3. Provision the resources and deploy the code:
103106
104107
```shell
@@ -128,24 +131,23 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
128131
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:
129132
130133
```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.p
134+
python3 -m pip install -e src/backend
135+
python ./src/backend/fastapi_app/setup_postgres_database.py
136+
python ./src/backend/fastapi_app/setup_postgres_seeddata.py
134137
```
135138
136-
If you opened the project in Codespaces or a Dev Container, these commands will already have been run for you.
137-
138139
2. Build the frontend:
139140
140141
```bash
141142
cd src/frontend
142143
npm install
143144
npm run build
145+
cd ../../
144146
```
145147
146148
There must be an initial build of static assets before running the backend, since the backend serves static files from the `src/static` directory.
147149
148-
3. Run the FastAPI backend (with hot reloading):
150+
3. Run the FastAPI backend (with hot reloading). This should be run from the root of the project:
149151
150152
```shell
151153
python3 -m uvicorn fastapi_app:create_app --factory --reload

azure.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ metadata:
44
template: rag-postgres-openai-python@0.0.1
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.

infra/core/host/container-app-upsert.bicep

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ param serviceBinds array = []
7575
@description('The target port for the container')
7676
param targetPort int = 80
7777

78-
// Service options
79-
@description('PostgreSQL service ID')
80-
param postgresServiceId string = ''
81-
8278
resource existingApp 'Microsoft.App/containerApps@2023-05-02-preview' existing = if (exists) {
8379
name: name
8480
}
@@ -103,7 +99,6 @@ module app 'container-app.bicep' = {
10399
daprEnabled: daprEnabled
104100
daprAppId: daprAppId
105101
daprAppProtocol: daprAppProtocol
106-
postgresServiceId: postgresServiceId
107102
secrets: secrets
108103
keyvaultIdentities: keyvaultIdentities
109104
external: external

infra/core/host/container-app.bicep

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ param containerRegistryName string = ''
3131
@description('Hostname suffix for container registry. Set when deploying to sovereign clouds')
3232
param containerRegistryHostSuffix string = 'azurecr.io'
3333

34-
// Service options
35-
@description('PostgreSQL service ID')
36-
param postgresServiceId string = ''
37-
3834
@description('The protocol used by Dapr to connect to the app, e.g., http or grpc')
3935
@allowed([ 'http', 'grpc' ])
4036
param daprAppProtocol string = 'http'
@@ -102,7 +98,7 @@ var keyvaultIdentitySecrets = [for secret in items(keyvaultIdentities): {
10298
name: secret.key
10399
keyVaultUrl: secret.value.keyVaultUrl
104100
identity: secret.value.identity
105-
}]
101+
}]
106102

107103
module containerRegistryAccess '../security/registry-access.bicep' = if (usePrivateRegistry) {
108104
name: '${deployment().name}-registry-access'
@@ -118,7 +114,7 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
118114
tags: tags
119115
// It is critical that the identity is granted ACR pull access before the app is created
120116
// otherwise the container app will throw a provision error
121-
// This also forces us to use an user assigned managed identity since there would no way to
117+
// This also forces us to use an user assigned managed identity since there would no way to
122118
// provide the system assigned identity with the ACR pull access before the app is created
123119
dependsOn: usePrivateRegistry ? [ containerRegistryAccess ] : []
124120
identity: {

0 commit comments

Comments
 (0)