Skip to content

Commit

Permalink
Sync parity (#31)
Browse files Browse the repository at this point in the history
- Updates to Dockerfile & docker-compose. Relying on 1 single Dockerfile now.
- Multi-stage build in Dockerfile with different targets to mimic prod & staging env.
- Add more availability to openai and cohere endpoints
- front-end revamp with multi-chat and persistent chat models

Signed-off-by: Duc Nguyen <[email protected]>
  • Loading branch information
DucNgn authored Nov 30, 2023
1 parent dcac7be commit 546eb0d
Show file tree
Hide file tree
Showing 58 changed files with 2,451 additions and 635 deletions.
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Python
__pycache__
*.py[cod]
*.pyo
*.pyd
.Python
env/
venv/
*.log
*.csv
*.json
*.sqlite

# Node
/node_modules
/npm-debug.log
/yarn-error.log

# React
/build

# Docker
Dockerfile
.dockerignore

# Git
.git
.gitignore

# IDEs
.idea
.vscode
83 changes: 55 additions & 28 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,59 @@ concurrency:
cancel-in-progress: true

jobs:
check_modified_files:
name: Check modified files
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: dorny/paths-filter@v2
id: check-files
with:
filters: |
frontend_modified:
- "front_end/**"
backend_modified:
- "Dockerfile"
- 'llm_service/**'
- pyproject.toml
- poetry.lock
outputs:
frontend_modified: ${{ steps.check-files.outputs.frontend_modified }}
backend_modified: ${{ steps.check-files.outputs.backend_modified }}


frontend_test:
name: Tests & Lints LLM Gateway Frontend
if: needs.check_modified_files.outputs.frontend_modified == 'true'
runs-on: ubuntu-latest
needs:
- check_modified_files
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 16.13.1

- name: Install dependencies
run: |
npm install -g yarn
(cd front_end && yarn install)
- name: Check compatible licenses
run: (cd front_end && yarn check-license)

- name: Run linting
run: (cd front_end && yarn lint)

- name: Run Tests
run: (cd front_end && yarn test)


backend_tests:
name: Tests & Lints LLM Gateway Backend
runs-on: ubuntu-latest
Expand Down Expand Up @@ -36,31 +89,5 @@ jobs:
- name: Run Python Test Suite
run: poetry run pytest

frontend_tests:
name: Tests & Lints LLM Gateway Frontend
strategy:
matrix:
node-version: [16.13.1]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
npm install -g yarn
(cd front_end && yarn install)
- name: Check compatible licenses
run: (cd front_end && yarn check-license)

- name: Run linting
run: (cd front_end && yarn lint)

- name: Run Tests
run: (cd front_end && yarn test)
env:
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/llm_gateway"
38 changes: 31 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG BASE_LAYER=base
FROM python:3.11.3-slim-buster1 as base
FROM python:3.11.3-slim-buster as base
LABEL maintainer="Data Science & Engineering @ Wealthsimple <[email protected]>"

##############################################
Expand All @@ -14,7 +14,7 @@ FROM python:3.11-bullseye as base-dev

##############################################

FROM $BASE_LAYER as builder
FROM $BASE_LAYER as backend-builder

RUN pip install poetry==1.3.2

Expand All @@ -39,7 +39,7 @@ COPY --chown=nobody:nogroup ./alembic/ ./alembic/

##############################################

FROM builder as test-suite
FROM backend-builder as backend-test-suite

RUN poetry install --no-interaction --no-root

Expand All @@ -52,9 +52,33 @@ CMD ["pytest"]

##############################################

FROM builder as application
FROM node:16.13.1 as frontend-pre-builder

# fastapi server port
EXPOSE 5000 5000
WORKDIR /usr/src/app

# Install dependencies
COPY front_end/package.json front_end/yarn.lock front_end/.eslintrc.json front_end/tsconfig.json front_end/.env-cmdrc ./
RUN yarn install

##############################################

FROM frontend-pre-builder as frontend-builder-staging

# Build ready for Staging
COPY ./front_end ./
RUN yarn build-staging

##############################################

FROM frontend-pre-builder as frontend-builder-production

# Build ready for Production
COPY ./front_end ./
RUN yarn build-production

##############################################

CMD ["uvicorn", "--host", "0.0.0.0","--port", "5000", "llm_gateway.app:app"]
# Copy frontend build artifacts into the backend image
FROM backend-builder as application
COPY --from=frontend-builder-production /usr/src/app/build/ /usr/src/app/front_end/build-production/
COPY --from=frontend-builder-staging /usr/src/app/build/ /usr/src/app/front_end/build-staging/
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
docker-build:
docker buildx build \
--build-arg BASE_LAYER=base-dev \
-t llm-gateway-backend .
docker buildx build \
-t llm-gateway-frontend ./front_end
-t llm-gateway .

docker-test:
docker buildx build \
--build-arg BASE_LAYER=base-dev \
--target test-suite \
--target backend-test-suite \
-t llm-gateway-test .

docker run -ti llm-gateway-test pytest $(TEST_OPTIONS)

docker-run:
docker-compose -p llm-gateway -f docker-compose.yml up --detach

browse:
open http://localhost:3000

browse-api:
open http://localhost:5000/api/docs

clean:
up: docker-build
docker-compose -p llm-gateway -f docker-compose.yml up --detach

down:
docker-compose -p llm-gateway -f docker-compose.yml down
docker-compose rm # force postgres to execute docker-entrypoint-initdb.d/init.sql
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ poetry run pre-commit install
To run in Docker:

```
# build docker image
make docker-build
# spin up docker-compose
make docker-run
make up
# open frontend in browser
make browse
Expand All @@ -100,5 +97,5 @@ make browse
make browse-api
# delete docker-compose setup
make clean
make down
```
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ If you have a vulnerability to report about the Wealthsimple platform, please us

### General Support

For additional support, please open a [Github Discussion](https://github.com/wealthsimple/llm-gateway/discussions).
For additional support, please open a [Github Discussion](https://github.com/wealthsimple/llm-gateway/discussions).
2 changes: 1 addition & 1 deletion catalog-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
description: Gateway for secure & reliable communications with OpenAI and other LLM providers
tags:
- machine-learning
- open-source
- open-source
- python
spec:
type: website
Expand Down
30 changes: 14 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ services:
retries: 5

migration:
image: llm-gateway-backend
build:
context: .
dockerfile: Dockerfile
target: backend-builder
env_file:
- .envrc
command: alembic upgrade head
Expand All @@ -26,17 +29,12 @@ services:
condition: service_healthy

llm_gateway_backend:
image: llm-gateway-backend
build:
context: .
dockerfile: Dockerfile
target: backend-builder
container_name: llm-gateway-backend
command: [
"uvicorn",
"--host",
"0.0.0.0",
"--port",
"5000",
"llm_gateway.app:app",
"--reload"
]
command: uvicorn --host 0.0.0.0 --port 5000 llm_gateway.app:app --reload
env_file:
- .envrc
ports:
Expand All @@ -56,12 +54,12 @@ services:
- ./llm_gateway:/usr/src/app/llm_gateway

llm_gateway_frontend:
image: llm-gateway-frontend
build:
context: .
dockerfile: Dockerfile
target: frontend-pre-builder
container_name: llm-gateway-frontend
command: [
"yarn",
"start"
]
command: yarn start
ports:
- "3000:3000"
volumes:
Expand Down
1 change: 0 additions & 1 deletion front_end/.dockerignore

This file was deleted.

11 changes: 11 additions & 0 deletions front_end/.env-cmdrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"development": {
"REACT_APP_ENV": "development"
},
"staging": {
"REACT_APP_ENV": "staging"
},
"production": {
"REACT_APP_ENV": "production"
}
}
6 changes: 0 additions & 6 deletions front_end/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions front_end/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# LLM Gateway Front-end

### 🐳 Development with Docker

The guide to development with Docker is located in the main
[README.md](../README.md).

### 🚫🐳 Development without Docker

1. Install [fnm](https://github.com/Schniz/fnm) or
Expand Down
5 changes: 4 additions & 1 deletion front_end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/react": "^18.2.13",
"@types/react-dom": "^18.2.6",
"axios": "^1.4.0",
"env-cmd": "^10.1.0",
"highlight.js": "^11.8.0",
"markdown-to-jsx": "^7.2.1",
"nth-check": "^2.0.1",
Expand All @@ -24,7 +25,9 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "node_modules/.bin/env-cmd -e development react-scripts build",
"build-staging": "node_modules/.bin/env-cmd -e staging react-scripts build",
"build-production": "node_modules/.bin/env-cmd -e production react-scripts build",
"lint": "eslint .",
"test": "react-scripts test --watchAll=false",
"prettier": "prettier --write .",
Expand Down
5 changes: 3 additions & 2 deletions front_end/public/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-theme="light">
<head>
<meta charset="utf-8" />
<title>LLM Gateway</title>
<base href="/" />
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>

<body>
<div id="root"></div>
</body>
<!--Custom stylesheet is kept after body to override the plugin if necessary-->
<link rel="stylesheet" href="styles.css" />
</html>
4 changes: 2 additions & 2 deletions front_end/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "LLMGateway",
"name": "Framework for safe and secure LLM interactions",
"icons": [
{
"src": "favicon.ico",
Expand Down
Loading

0 comments on commit 546eb0d

Please sign in to comment.