Skip to content

Update readme #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
{
"name": "RAG on database",
"name": "rag-postgres-openai-python",
"dockerComposeFile": "docker-compose.yaml",
"service": "app",
"workspaceFolder": "/workspace",
Expand Down Expand Up @@ -29,7 +29,6 @@
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"ms-python.black-formatter",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"ms-vscode.vscode-node-azure-pack",
Expand All @@ -45,7 +44,7 @@
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
"files.exclude": {
".ruff_cache": true,
Expand Down
3 changes: 1 addition & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ See [CONTRIBUTING.md](https://github.com/Azure-Samples/rag-postgres-openai-pytho
- [ ] I added tests that prove my fix is effective or that my feature works
- [ ] I ran `python -m pytest --cov` to verify 100% coverage of added lines
- [ ] I ran `python -m mypy` to check for type errors
- [ ] I either used the pre-commit hooks or ran `ruff` and `black` manually on my code.

- [ ] I either used the pre-commit hooks or ran `ruff` manually on my code.
15 changes: 11 additions & 4 deletions .github/workflows/tests.yaml → .github/workflows/app-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python check
name: App Tests

on:
push:
Expand All @@ -25,12 +25,19 @@ jobs:
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
architecture: x64
- name: Install dependencies
run: |
python3 -m pip install -e src
python -m pip install -r requirements-dev.txt
- name: Install app as editable app
run: |
python -m pip install -e src
- name: Setup local database with seed data
cp .env.sample .env
python ./src/fastapi_app/setup_postgres_database.py
python ./src/fastapi_app/setup_postgres_seeddata.py
34 changes: 0 additions & 34 deletions .github/workflows/bicep-audit.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Validate AZD template
name: Bicep Security Scan
on:
push:
branches: [ main ]
Expand All @@ -10,7 +10,6 @@ on:
- "infra/**"
workflow_dispatch:


jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,19 +20,19 @@ jobs:
uses: actions/checkout@v4

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

- name: Run Microsoft Security DevOps Analysis
uses: microsoft/security-devops-action@v1
uses: microsoft/security-devops-action@preview
id: msdo
continue-on-error: true
with:
tools: templateanalyzer

- name: Upload alerts to Security tab
uses: github/codeql-action/upload-sarif@v3
if: github.repository == 'Azure-Samples/langfuse-on-azure'
if: github.repository == 'Azure-Samples/azure-search-openai-demo'
with:
sarif_file: ${{ steps.msdo.outputs.sarifFile }}
25 changes: 25 additions & 0 deletions .github/workflows/python-code-quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Python code quality

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint with ruff
run: ruff check .
- name: Check formatting with ruff
run: ruff format --check .
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
68 changes: 54 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to [project-title]
# Contributing

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

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

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].
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].

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

* Search the repository (https://github.com/Azure-Samples/rag-postgres-openai-python/pulls) for an open or closed PR
* Search the repository (https://github.com/Azure-samples/rag-postgres-openai-python/pulls) for an open or closed PR
that relates to your submission. You don't want to duplicate effort.

* Make your changes in a new git fork
* Follow [Code style conventions](#style)
* [Run the tests](#tests) (and write new ones, if needed)
* Commit your changes using a descriptive commit message
* Push your fork to GitHub
* In GitHub, create a pull request
* If we suggest changes then:
* Make the required updates.
* Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
* In GitHub, create a pull request to the `main` branch of the repository
* Ask a maintainer to review your PR and address any comments they might have

## <a name="tests"></a> Setting up the development environment

Install the development dependencies:

```
python3 -m pip install -r requirements-dev.txt
```

Install the pre-commit hooks:

```
pre-commit install
```

Compile the JavaScript:

```
( cd ./app/frontend ; npm install ; npm run build )
```

## <a name="style"></a> Code Style

This codebase includes several languages: TypeScript, Python, Bicep, Powershell, and Bash.
Code should follow the standard conventions of each language.

For Python, you can enforce the conventions using `ruff`.

Install the development dependencies:

```
python3 -m pip install -r requirements-dev.txt
```

Run `ruff` to lint a file:

```
python3 -m ruff check <path-to-file>
```

```shell
git rebase master -i
git push -f
```
Run `ruff` to format a file:

That's it! Thank you for your contribution!
```
python3 -m ruff format <path-to-file>
```

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.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RAG on PostgreSQL

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

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.

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

```shell
azd auth login --use-device-code
azd auth login
```

4. Provision the resources and deploy the code:
Expand Down
19 changes: 9 additions & 10 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ module web 'web.bicep' = {
}
}


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

// USER ROLES
module openAiRoleUser 'core/security/role.bicep' = if (empty(runningOnGh)) {
scope: openAiResourceGroup
name: 'openai-role-user'
params: {
principalId: principalId
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
principalType: 'User'
module openAiRoleUser 'core/security/role.bicep' =
if (empty(runningOnGh)) {
scope: openAiResourceGroup
name: 'openai-role-user'
params: {
principalId: principalId
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
principalType: 'User'
}
}
}

// Backend roles
module openAiRoleBackend 'core/security/role.bicep' = {
Expand All @@ -314,7 +314,6 @@ module openAiRoleBackend 'core/security/role.bicep' = {
}
}


output AZURE_LOCATION string = location
output APPLICATIONINSIGHTS_NAME string = monitoring.outputs.applicationInsightsName

Expand Down
5 changes: 2 additions & 3 deletions infra/web.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ param identityName string
param serviceName string = 'web'
param environmentVariables array = []


resource webIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: identityName
location: location
}


module app 'core/host/container-app-upsert.bicep' = {
name: '${serviceName}-container-app-module'
params: {
Expand All @@ -26,7 +24,8 @@ module app 'core/host/container-app-upsert.bicep' = {
exists: exists
containerAppsEnvironmentName: containerAppsEnvironmentName
containerRegistryName: containerRegistryName
env: union(environmentVariables,
env: union(
environmentVariables,
[
{
name: 'APP_IDENTITY_ID'
Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[tool.ruff]
line-length = 120
target-version = "py311"

[tool.ruff.lint]
select = ["E", "F", "I", "UP"]
ignore = ["D203"]
show-source = true

[tool.ruff.lint.isort]
known-first-party = ["fastapi_app"]

[tool.black]
line-length = 120
target-version = ["py311"]
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-r src/requirements.txt
ruff
black
pre-commit
pip-tools
pip-tools
1 change: 0 additions & 1 deletion src/fastapi_app/api_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@router.post("/chat")
async def chat_handler(chat_request: ChatRequest):

messages = [message.model_dump() for message in chat_request.messages]
overrides = chat_request.context.get("overrides", {})

Expand Down
1 change: 0 additions & 1 deletion src/fastapi_app/openai_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async def create_openai_chat_client(azure_credential):


async def create_openai_embed_client(azure_credential):

OPENAI_EMBED_HOST = os.getenv("OPENAI_EMBED_HOST")
if OPENAI_EMBED_HOST == "azure":
token_provider = azure.identity.aio.get_bearer_token_provider(
Expand Down
Loading
Loading