Skip to content

Commit 0d1ebe1

Browse files
committed
add initial project setup
0 parents  commit 0d1ebe1

File tree

174 files changed

+250428
-0
lines changed

Some content is hidden

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

174 files changed

+250428
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ARG IMAGE=bullseye
2+
FROM mcr.microsoft.com/devcontainers/${IMAGE}
3+
4+
ENV PYTHONUNBUFFERED 1
5+
6+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
7+
&& apt-get -y install --no-install-recommends postgresql-client \
8+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

.devcontainer/devcontainer.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
3+
{
4+
"name": "rag-postgres-openai-python",
5+
"dockerComposeFile": "docker-compose.yaml",
6+
"service": "app",
7+
"workspaceFolder": "/workspace",
8+
"forwardPorts": [5432],
9+
"portsAttributes": {
10+
"5432": {"label": "PostgreSQL port", "onAutoForward": "silent"},
11+
"8000": {"label": "Backend port", "onAutoForward": "openBrowser"},
12+
"5173": {"label": "Frontend port", "onAutoForward": "openBrowser"}
13+
},
14+
"features": {
15+
"ghcr.io/devcontainers/features/node:1": {
16+
"version": "18",
17+
"nodeGypDependencies": false
18+
},
19+
"ghcr.io/azure/azure-dev/azd:latest": {
20+
"version": "1.11.0"
21+
},
22+
"ghcr.io/prulloac/devcontainer-features/ollama:1": {},
23+
// az CLI is helpful for being able to login correctly with DefaultAzureCredential:
24+
"ghcr.io/devcontainers/features/azure-cli": {}
25+
},
26+
// Configure tool-specific properties.
27+
"customizations": {
28+
// Configure properties specific to VS Code.
29+
"vscode": {
30+
// Add the IDs of extensions you want installed when the container is created.
31+
"extensions": [
32+
"ms-python.python",
33+
"ms-python.vscode-pylance",
34+
"charliermarsh.ruff",
35+
"mtxr.sqltools",
36+
"mtxr.sqltools-driver-pg",
37+
"ms-vscode.vscode-node-azure-pack",
38+
"esbenp.prettier-vscode"
39+
],
40+
// Set *default* container specific settings.json values on container create.
41+
"settings": {
42+
"python.defaultInterpreterPath": "/usr/local/bin/python",
43+
"python.testing.unittestEnabled": false,
44+
"python.testing.pytestEnabled": false,
45+
"[python]": {
46+
"editor.formatOnSave": true,
47+
"editor.codeActionsOnSave": {
48+
"source.fixAll": "explicit"
49+
},
50+
"editor.defaultFormatter": "charliermarsh.ruff"
51+
}
52+
}
53+
}
54+
},
55+
// Use 'postCreateCommand' to run commands after the container is created.
56+
"postCreateCommand": "pip install -r requirements-dev.txt && pip install -e src/backend",
57+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
58+
"remoteUser": "vscode"
59+
}

.devcontainer/docker-compose.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: "3"
2+
3+
services:
4+
app:
5+
build:
6+
context: ..
7+
dockerfile: .devcontainer/Dockerfile
8+
args:
9+
IMAGE: python:3.12
10+
11+
volumes:
12+
- ..:/workspace:cached
13+
14+
# Overrides default command so things don't shut down after the process ends.
15+
command: sleep infinity
16+
17+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
18+
network_mode: service:db
19+
20+
db:
21+
image: pgvector/pgvector:pg16
22+
restart: unless-stopped
23+
volumes:
24+
- postgres-data:/var/lib/postgresql/data
25+
environment:
26+
POSTGRES_DB: postgres
27+
POSTGRES_USER: admin
28+
POSTGRES_PASSWORD: postgres
29+
30+
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
31+
# (Adding the "ports" property to this file will not forward from a Codespace.)
32+
33+
volumes:
34+
postgres-data:

.env.sample

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use these values to connect to the local database from within the devcontainer
2+
POSTGRES_HOST=neon_hostname
3+
POSTGRES_USERNAME=neondb_owner
4+
POSTGRES_PASSWORD=neondb_password
5+
POSTGRES_DATABASE=neondb
6+
POSTGRES_SSL=require
7+
8+
# OPENAI_CHAT_HOST can be either azure, openai, or ollama:
9+
OPENAI_CHAT_HOST=azure
10+
# OPENAI_EMBED_HOST can be either azure or openai:
11+
OPENAI_EMBED_HOST=azure
12+
# Needed for Azure:
13+
# You also need to `azd auth login` if running this locally
14+
AZURE_OPENAI_ENDPOINT=https://YOUR-AZURE-OPENAI-SERVICE-NAME.openai.azure.com
15+
AZURE_OPENAI_VERSION=2024-03-01-preview
16+
AZURE_OPENAI_CHAT_DEPLOYMENT=gpt-4o-mini
17+
AZURE_OPENAI_CHAT_MODEL=gpt-4o-mini
18+
AZURE_OPENAI_EMBED_DEPLOYMENT=text-embedding-ada-002
19+
AZURE_OPENAI_EMBED_MODEL=text-embedding-ada-002
20+
AZURE_OPENAI_EMBED_DIMENSIONS=1536
21+
AZURE_OPENAI_EMBEDDING_COLUMN=embedding_ada002
22+
AZURE_OPENAI_EVAL_DEPLOYMENT=gpt-4
23+
AZURE_OPENAI_EVAL_MODEL=gpt-4
24+
# Only needed when using Managed Identity for authenticating to Azure OpenAI service:
25+
AZURE_TENANT_ID=
26+
# Only needed when using key-based Azure authentication:
27+
AZURE_OPENAI_KEY=
28+
# Needed for OpenAI.com:
29+
OPENAICOM_KEY=YOUR-OPENAI-API-KEY
30+
OPENAICOM_CHAT_MODEL=gpt-3.5-turbo
31+
OPENAICOM_EMBED_MODEL=text-embedding-ada-002
32+
OPENAICOM_EMBED_MODEL_DIMENSIONS=1536
33+
OPENAICOM_EMBEDDING_COLUMN=embedding_ada002
34+
# Needed for Ollama:
35+
OLLAMA_ENDPOINT=http://host.docker.internal:11434/v1
36+
OLLAMA_CHAT_MODEL=llama3.1
37+
OLLAMA_EMBED_MODEL=nomic-embed-text
38+
OLLAMA_EMBEDDING_COLUMN=embedding_nomic

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.sh text eol=lf
2+
*.jsonlines text eol=lf

.github/ISSUE_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Description
2+
3+
What is wrong or what would you like to see improved?
4+
5+
6+
### Environment
7+
8+
Describe your OS and dev environment (Codespaces, Dev Container, etc):
9+

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Purpose
2+
3+
<!-- Describe the intention of the changes being proposed. What problem does it solve or functionality does it add? -->
4+
5+
6+
## Does this introduce a breaking change?
7+
8+
When developers merge from main and run the server, azd up, or azd deploy, will this produce an error?
9+
If you're not sure, try it out on an old environment.
10+
11+
```
12+
[ ] Yes
13+
[ ] No
14+
```
15+
16+
## Type of change
17+
18+
```
19+
[ ] Bugfix
20+
[ ] Feature
21+
[ ] Code style update (formatting, local variables)
22+
[ ] Refactoring (no functional changes, no api changes)
23+
[ ] Documentation content changes
24+
[ ] Other... Please describe:
25+
```
26+
27+
## Code quality checklist
28+
29+
- [ ] The current tests all pass (`python -m pytest`).
30+
- [ ] I added tests that prove my fix is effective or that my feature works
31+
- [ ] I ran `python -m pytest --cov` to verify 100% coverage of added lines
32+
- [ ] I ran `python -m mypy` to check for type errors
33+
- [ ] I either used the pre-commit hooks or ran `ruff` manually on my code.

.github/dependabot.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
9+
- package-ecosystem: "pip"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"
13+
14+
- package-ecosystem: "github-actions"
15+
directory: "/"
16+
schedule:
17+
interval: "weekly"
18+
19+
- package-ecosystem: "npm"
20+
directory: "/app/frontend"
21+
schedule:
22+
interval: "weekly"

.github/workflows/app-tests.yaml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: App Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- "**.md"
8+
- ".azdo/**"
9+
- ".devcontainer/**"
10+
- ".github/**"
11+
pull_request:
12+
branches: [ main ]
13+
paths-ignore:
14+
- "**.md"
15+
- ".azdo/**"
16+
- ".devcontainer/**"
17+
- ".github/**"
18+
workflow_dispatch:
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
test-package:
25+
name: Test ${{ matrix.os }} Python ${{ matrix.python_version }}
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
os: ["ubuntu-latest", "macos-latest-xlarge", "macos-13", "windows-latest"]
31+
python_version: ["3.9", "3.10", "3.11", "3.12"]
32+
exclude:
33+
- os: macos-latest-xlarge
34+
python_version: "3.9"
35+
- os: macos-latest-xlarge
36+
python_version: "3.10"
37+
env:
38+
UV_SYSTEM_PYTHON: 1
39+
POSTGRES_HOST: localhost
40+
POSTGRES_USERNAME: postgres
41+
POSTGRES_PASSWORD: root
42+
POSTGRES_DATABASE: postgres
43+
POSTGRES_SSL: disable
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: (MacOS) Install postgreSQL and pgvector using brew
48+
if: matrix.os == 'macos-13' || matrix.os == 'macos-latest-xlarge'
49+
run: |
50+
brew install postgresql@14
51+
brew link --overwrite postgresql@14
52+
brew install pgvector
53+
brew services start postgresql@14 && sleep 1
54+
createuser -s ${{ env.POSTGRES_USERNAME }}
55+
psql -d postgres -c "ALTER USER ${{ env.POSTGRES_USERNAME }} WITH PASSWORD '${{ env.POSTGRES_PASSWORD }}'"
56+
psql -d postgres -c 'CREATE EXTENSION vector'
57+
58+
- name: Install pgvector
59+
if: matrix.os == 'windows-latest'
60+
shell: cmd
61+
run: |
62+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
63+
cd %TEMP%
64+
git clone --branch v0.7.4 https://github.com/pgvector/pgvector.git
65+
cd pgvector
66+
nmake /NOLOGO /F Makefile.win
67+
nmake /NOLOGO /F Makefile.win install
68+
sc config postgresql-x64-14 start=auto
69+
net start postgresql-x64-14
70+
"%PGBIN%/psql" -d postgres -c "CREATE EXTENSION vector"
71+
72+
- name: (Linux) Install pgvector and set password
73+
if: matrix.os == 'ubuntu-latest'
74+
run: |
75+
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
76+
sudo apt-get install postgresql-16-pgvector
77+
sudo systemctl start postgresql
78+
sudo -u postgres psql -c "ALTER USER ${{ env.POSTGRES_USERNAME }} PASSWORD '${{ env.POSTGRES_PASSWORD }}'"
79+
sudo -u postgres psql -c 'CREATE EXTENSION vector'
80+
81+
- name: Setup python
82+
uses: actions/setup-python@v5
83+
with:
84+
python-version: ${{ matrix.python_version }}
85+
architecture: x64
86+
87+
- name: Install uv
88+
uses: astral-sh/setup-uv@v5
89+
with:
90+
enable-cache: true
91+
version: "0.4.20"
92+
cache-dependency-glob: "requirements**.txt"
93+
94+
- name: Install dependencies
95+
run: |
96+
uv pip install -r requirements-dev.txt
97+
uv pip install -r evals/requirements.txt
98+
99+
- name: Install app as editable app
100+
run: |
101+
uv pip install -e src/backend
102+
103+
- name: Setup local database with seed data
104+
run: |
105+
python ./src/backend/fastapi_app/setup_postgres_database.py
106+
python ./src/backend/fastapi_app/setup_postgres_seeddata.py
107+
108+
- name: Setup node
109+
uses: actions/setup-node@v4
110+
with:
111+
node-version: 18
112+
113+
- name: Build frontend
114+
run: |
115+
cd ./src/frontend
116+
npm install
117+
npm run build
118+
119+
- name: Setup mypy cache
120+
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
121+
with:
122+
path: ./.mypy_cache
123+
key: mypy${{ matrix.os }}-${{ matrix.python_version }}-${{ hashFiles('requirements-dev.txt', 'src/backend/requirements.txt', 'src/backend/pyproject.toml') }}
124+
125+
- name: Run MyPy
126+
run: python3 -m mypy .
127+
128+
- name: Run Pytest
129+
run: python3 -m pytest -s -vv --cov --cov-fail-under=85
130+
131+
- name: Run E2E tests with Playwright
132+
id: e2e
133+
run: |
134+
playwright install chromium --with-deps
135+
python3 -m pytest tests/e2e.py --tracing=retain-on-failure
136+
137+
- name: Upload test artifacts
138+
if: ${{ failure() && steps.e2e.conclusion == 'failure' }}
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: playwright-traces${{ matrix.python_version }}
142+
path: test-results

0 commit comments

Comments
 (0)