Skip to content

Commit 66cc077

Browse files
authored
Merge pull request #1 from Azure-Samples/readme
Update readme
2 parents b202e7c + 3e42e82 commit 66cc077

28 files changed

+182
-140
lines changed

.devcontainer/devcontainer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
22
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
33
{
4-
"name": "RAG on database",
4+
"name": "rag-postgres-openai-python",
55
"dockerComposeFile": "docker-compose.yaml",
66
"service": "app",
77
"workspaceFolder": "/workspace",
@@ -29,7 +29,6 @@
2929
"ms-python.python",
3030
"ms-python.vscode-pylance",
3131
"charliermarsh.ruff",
32-
"ms-python.black-formatter",
3332
"mtxr.sqltools",
3433
"mtxr.sqltools-driver-pg",
3534
"ms-vscode.vscode-node-azure-pack",
@@ -45,7 +44,7 @@
4544
"editor.codeActionsOnSave": {
4645
"source.fixAll": "explicit"
4746
},
48-
"editor.defaultFormatter": "ms-python.black-formatter"
47+
"editor.defaultFormatter": "charliermarsh.ruff"
4948
},
5049
"files.exclude": {
5150
".ruff_cache": true,

.github/PULL_REQUEST_TEMPLATE.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ See [CONTRIBUTING.md](https://github.com/Azure-Samples/rag-postgres-openai-pytho
3232
- [ ] I added tests that prove my fix is effective or that my feature works
3333
- [ ] I ran `python -m pytest --cov` to verify 100% coverage of added lines
3434
- [ ] I ran `python -m mypy` to check for type errors
35-
- [ ] I either used the pre-commit hooks or ran `ruff` and `black` manually on my code.
36-
35+
- [ ] I either used the pre-commit hooks or ran `ruff` manually on my code.

.github/workflows/tests.yaml renamed to .github/workflows/app-tests.yaml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Python check
1+
name: App Tests
22

33
on:
44
push:
@@ -25,12 +25,19 @@ jobs:
2525
# needed because the postgres container does not provide a healthcheck
2626
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
2727
steps:
28-
- uses: actions/checkout@v3
28+
- uses: actions/checkout@v4
2929
- name: Setup python
30-
uses: actions/setup-python@v2
30+
uses: actions/setup-python@v5
3131
with:
3232
python-version: ${{ matrix.python_version }}
3333
architecture: x64
3434
- name: Install dependencies
3535
run: |
36-
python3 -m pip install -e src
36+
python -m pip install -r requirements-dev.txt
37+
- name: Install app as editable app
38+
run: |
39+
python -m pip install -e src
40+
- name: Setup local database with seed data
41+
cp .env.sample .env
42+
python ./src/fastapi_app/setup_postgres_database.py
43+
python ./src/fastapi_app/setup_postgres_seeddata.py

.github/workflows/bicep-audit.yaml

-34
This file was deleted.

.github/workflows/bicep-validation.yaml renamed to .github/workflows/bicep-security-scan.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Validate AZD template
1+
name: Bicep Security Scan
22
on:
33
push:
44
branches: [ main ]
@@ -10,7 +10,6 @@ on:
1010
- "infra/**"
1111
workflow_dispatch:
1212

13-
1413
jobs:
1514
build:
1615
runs-on: ubuntu-latest
@@ -21,19 +20,19 @@ jobs:
2120
uses: actions/checkout@v4
2221

2322
- name: Build Bicep for linting
24-
uses: azure/CLI@v1
23+
uses: azure/CLI@v2
2524
with:
2625
inlineScript: az config set bicep.use_binary_from_path=false && az bicep build -f infra/main.bicep --stdout
2726

2827
- name: Run Microsoft Security DevOps Analysis
29-
uses: microsoft/security-devops-action@v1
28+
uses: microsoft/security-devops-action@preview
3029
id: msdo
3130
continue-on-error: true
3231
with:
3332
tools: templateanalyzer
3433

3534
- name: Upload alerts to Security tab
3635
uses: github/codeql-action/upload-sarif@v3
37-
if: github.repository == 'Azure-Samples/langfuse-on-azure'
36+
if: github.repository == 'Azure-Samples/azure-search-openai-demo'
3837
with:
3938
sarif_file: ${{ steps.msdo.outputs.sarifFile }}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Python code quality
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python 3
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.12"
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install -r requirements-dev.txt
22+
- name: Lint with ruff
23+
run: ruff check .
24+
- name: Check formatting with ruff
25+
run: ruff format --check .

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ repos:
88
- repo: https://github.com/astral-sh/ruff-pre-commit
99
rev: v0.1.0
1010
hooks:
11-
- id: ruff
12-
- repo: https://github.com/psf/black
13-
rev: 23.9.1
14-
hooks:
15-
- id: black
11+
# Run the linter.
12+
- id: ruff
13+
args: [ --fix ]
14+
# Run the formatter.
15+
- id: ruff-format

CONTRIBUTING.md

+54-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to [project-title]
1+
# Contributing
22

33
This project welcomes contributions and suggestions. Most contributions require you to agree to a
44
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
@@ -15,7 +15,9 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
1515
- [Code of Conduct](#coc)
1616
- [Issues and Bugs](#issue)
1717
- [Feature Requests](#feature)
18-
- [Submission Guidelines](#submit)
18+
- [Submitting a PR](#submit-pr)
19+
- [Running Tests](#tests)
20+
- [Code Style](#style)
1921

2022
## <a name="coc"></a> Code of Conduct
2123
Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
@@ -51,26 +53,64 @@ chances of your issue being dealt with quickly:
5153
* **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
5254
causing the problem (line of code or commit)
5355

54-
You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/Azure-Samples/rag-postgres-openai-python/issues/new].
56+
You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/Azure-samples/rag-postgres-openai-python/issues/new].
5557

5658
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
5759
Before you submit your Pull Request (PR) consider the following guidelines:
5860

59-
* Search the repository (https://github.com/Azure-Samples/rag-postgres-openai-python/pulls) for an open or closed PR
61+
* Search the repository (https://github.com/Azure-samples/rag-postgres-openai-python/pulls) for an open or closed PR
6062
that relates to your submission. You don't want to duplicate effort.
61-
6263
* Make your changes in a new git fork
64+
* Follow [Code style conventions](#style)
65+
* [Run the tests](#tests) (and write new ones, if needed)
6366
* Commit your changes using a descriptive commit message
6467
* Push your fork to GitHub
65-
* In GitHub, create a pull request
66-
* If we suggest changes then:
67-
* Make the required updates.
68-
* Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
68+
* In GitHub, create a pull request to the `main` branch of the repository
69+
* Ask a maintainer to review your PR and address any comments they might have
70+
71+
## <a name="tests"></a> Setting up the development environment
72+
73+
Install the development dependencies:
74+
75+
```
76+
python3 -m pip install -r requirements-dev.txt
77+
```
78+
79+
Install the pre-commit hooks:
80+
81+
```
82+
pre-commit install
83+
```
84+
85+
Compile the JavaScript:
86+
87+
```
88+
( cd ./app/frontend ; npm install ; npm run build )
89+
```
90+
91+
## <a name="style"></a> Code Style
92+
93+
This codebase includes several languages: TypeScript, Python, Bicep, Powershell, and Bash.
94+
Code should follow the standard conventions of each language.
95+
96+
For Python, you can enforce the conventions using `ruff`.
97+
98+
Install the development dependencies:
99+
100+
```
101+
python3 -m pip install -r requirements-dev.txt
102+
```
103+
104+
Run `ruff` to lint a file:
105+
106+
```
107+
python3 -m ruff check <path-to-file>
108+
```
69109

70-
```shell
71-
git rebase master -i
72-
git push -f
73-
```
110+
Run `ruff` to format a file:
74111

75-
That's it! Thank you for your contribution!
112+
```
113+
python3 -m ruff format <path-to-file>
114+
```
76115

116+
If you followed the steps above to install the pre-commit hooks, then you can just wait for those hooks to run `ruff` for you.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RAG on PostgreSQL
22

3-
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](placeholder)
4-
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](placeholder)
3+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/rag-postgres-openai-python)
4+
[![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/rag-postgres-openai-python)
55

66
This project creates a web-based chat application with an API backend that can use OpenAI chat models to answer questions about the items in a PostgreSQL database table. The frontend is built with React and FluentUI, while the backend is written with Python and FastAPI.
77

@@ -42,7 +42,7 @@ You can run this template virtually by using GitHub Codespaces. The button will
4242
3. Sign in to your Azure account:
4343

4444
```shell
45-
azd auth login --use-device-code
45+
azd auth login
4646
```
4747

4848
4. Provision the resources and deploy the code:

infra/main.bicep

+9-10
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ module web 'web.bicep' = {
246246
}
247247
}
248248

249-
250249
resource openAiResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' existing =
251250
if (!empty(openAiResourceGroupName)) {
252251
name: !empty(openAiResourceGroupName) ? openAiResourceGroupName : resourceGroup.name
@@ -293,15 +292,16 @@ module openAi 'core/ai/cognitiveservices.bicep' = {
293292
}
294293

295294
// USER ROLES
296-
module openAiRoleUser 'core/security/role.bicep' = if (empty(runningOnGh)) {
297-
scope: openAiResourceGroup
298-
name: 'openai-role-user'
299-
params: {
300-
principalId: principalId
301-
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
302-
principalType: 'User'
295+
module openAiRoleUser 'core/security/role.bicep' =
296+
if (empty(runningOnGh)) {
297+
scope: openAiResourceGroup
298+
name: 'openai-role-user'
299+
params: {
300+
principalId: principalId
301+
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
302+
principalType: 'User'
303+
}
303304
}
304-
}
305305

306306
// Backend roles
307307
module openAiRoleBackend 'core/security/role.bicep' = {
@@ -314,7 +314,6 @@ module openAiRoleBackend 'core/security/role.bicep' = {
314314
}
315315
}
316316

317-
318317
output AZURE_LOCATION string = location
319318
output APPLICATIONINSIGHTS_NAME string = monitoring.outputs.applicationInsightsName
320319

infra/web.bicep

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ param identityName string
99
param serviceName string = 'web'
1010
param environmentVariables array = []
1111

12-
1312
resource webIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
1413
name: identityName
1514
location: location
1615
}
1716

18-
1917
module app 'core/host/container-app-upsert.bicep' = {
2018
name: '${serviceName}-container-app-module'
2119
params: {
@@ -26,7 +24,8 @@ module app 'core/host/container-app-upsert.bicep' = {
2624
exists: exists
2725
containerAppsEnvironmentName: containerAppsEnvironmentName
2826
containerRegistryName: containerRegistryName
29-
env: union(environmentVariables,
27+
env: union(
28+
environmentVariables,
3029
[
3130
{
3231
name: 'APP_IDENTITY_ID'

pyproject.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
[tool.ruff]
22
line-length = 120
33
target-version = "py311"
4+
5+
[tool.ruff.lint]
46
select = ["E", "F", "I", "UP"]
57
ignore = ["D203"]
6-
show-source = true
78

89
[tool.ruff.lint.isort]
910
known-first-party = ["fastapi_app"]
10-
11-
[tool.black]
12-
line-length = 120
13-
target-version = ["py311"]

requirements-dev.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
-r src/requirements.txt
22
ruff
3-
black
43
pre-commit
5-
pip-tools
4+
pip-tools

src/fastapi_app/api_routes.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
@router.post("/chat")
1313
async def chat_handler(chat_request: ChatRequest):
14-
1514
messages = [message.model_dump() for message in chat_request.messages]
1615
overrides = chat_request.context.get("overrides", {})
1716

src/fastapi_app/openai_clients.py

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async def create_openai_chat_client(azure_credential):
3838

3939

4040
async def create_openai_embed_client(azure_credential):
41-
4241
OPENAI_EMBED_HOST = os.getenv("OPENAI_EMBED_HOST")
4342
if OPENAI_EMBED_HOST == "azure":
4443
token_provider = azure.identity.aio.get_bearer_token_provider(

0 commit comments

Comments
 (0)