Skip to content

Commit

Permalink
Env vars and docker files review (#70)
Browse files Browse the repository at this point in the history
* refactor: update .env.sample

* chore: unused setting

* feat: update docker files

* feat: add docker build + push step

* chore: format file

* chore: reorder items in .env.sample

* feat: update docker files

* feat: add `:latest` docker tag in CI

* chore: default port
  • Loading branch information
stefanorosanelli authored Oct 7, 2024
1 parent c139ff7 commit 72e25f1
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 107 deletions.
154 changes: 73 additions & 81 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
## Secrets that must be available as environment variables
# Used by LLM API services (api keys or access tokens for instance)
# and by other third party services that need specific env variables
BREVIA_ENV_SECRETS='{
"OPENAI_API_KEY": "#########",
"COHERE_API_KEY": "#####"
}'

## QA vars
# QA completion LLM
QA_COMPLETION_LLM='{
"_type": "openai-chat",
"model_name": "gpt-4o-mini",
"temperature": 0,
"max_tokens": 200,
"verbose": true
}'

# QA followup LLM
QA_FOLLOWUP_LLM='{
"_type": "openai-chat",
"model_name": "gpt-4o-mini",
"temperature": 0,
"max_tokens": 200,
"verbose": true
}'

QA_FOLLOWUP_SIM_THRESHOLD=0.735
### Secrets that must be available as environment variables
# You can define here secrets used by LLM API services (api keys or access tokens for instance)
# and by other third party services that need specific env variables.
# If you don't set these variables, the services that depend on them may not work properly.
# By using BREVIA_ENV_SECRETS you make sure that these secrets will be available as environment variables.
# BREVIA_ENV_SECRETS='{"OPENAI_API_KEY": "#########", "COHERE_API_KEY": "#########"}'

## OpenAI, Cohere, and other API secrets
# If these vars are not available as environment variables you may want to add them to BREVIA_ENV_SECRETS (see above)
# OPENAI_API_KEY=#########
# COHERE_API_KEY=#########

## Tracing - Langsmith: if you have an account you need the env vars listed below, edit API_KEY and PROJECT vars
# If these vars are not available as environment variables you may want to add them to BREVIA_ENV_SECRETS (see above)
# LANGCHAIN_TRACING_V2=true
# LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
# LANGCHAIN_API_KEY="########"
# LANGCHAIN_PROJECT="My Project"

### QA vars
# Completion LLM configuration
# QA_COMPLETION_LLM='{"_type": "openai-chat", "model_name": "gpt-4o-mini", "temperature": 0, "max_tokens": 200, "verbose": true}'

# Followup LLM configuration
# QA_FOLLOWUP_LLM='{"_type": "openai-chat", "model_name": "gpt-4o-mini", "temperature": 0, "max_tokens": 200, "verbose": true}'

# Followup similarity threshold
# QA_FOLLOWUP_SIM_THRESHOLD=0.735

# Chat history - uncomment to disable session conversation, avoiding chat history loading
# QA_NO_CHAT_HISTORY=True

# Uncomment to use a custom QA retriever with custom arguments
# QA_RETRIEVER='{"retriever": "my_project.CustomSplitter", "some_var": "some_value"}'
# QA_RETRIEVER='{"retriever": "my_project.CustomRetriever", "some_var": "some_value"}'

### Security
# Access tokens secret - if missing no access token validity is checked
# Generate it with: openssl rand -hex 32
# TOKENS_SECRET=##########################
Expand All @@ -41,68 +44,57 @@ QA_FOLLOWUP_SIM_THRESHOLD=0.735
# Special token used by `GET /status` only
# STATUS_TOKEN=#############

## Search
### Search
# default number of documents to return in a vector search
SEARCH_DOCS_NUM=4
# SEARCH_DOCS_NUM=4

## Embedding
EMBEDDINGS='{"_type": "openai-embeddings"}'
### Embedding
# Embeddings engine configuration
# EMBEDDINGS='{"_type": "openai-embeddings"}'

## Index creation
TEXT_CHUNK_SIZE=2000
TEXT_CHUNK_OVERLAP=100
### Index creation
# TEXT_CHUNK_SIZE=2000
# TEXT_CHUNK_OVERLAP=100
# Uncomment to use a custom splitter with custom arguments
# TEXT_SPLITTER='{"splitter": "my_project.CustomSplitter", "some_var": "some_value"}'

## Summarize
### Summarize
# Summarization LLM
SUMMARIZE_LLM='{
"_type": "openai-chat",
"model_name": "gpt-4o-mini",
"temperature": 0,
"max_tokens": 2000
}'
SUMM_TOKEN_SPLITTER=4000
SUMM_TOKEN_OVERLAP=500
SUMM_DEFAULT_CHAIN=stuff

# General
VERBOSE_MODE=True

# OPENAPI
# SUMMARIZE_LLM='{"_type": "openai-chat", "model_name": "gpt-4o-mini", "temperature": 0, "max_tokens": 2000}'
# SUMM_TOKEN_SPLITTER=4000
# SUMM_TOKEN_OVERLAP=500
# SUMM_DEFAULT_CHAIN=stuff

### General
# VERBOSE_MODE=True

### OPENAPI
# Uncomment to block openapi urls - /docs, /redoc
# BLOCK_OPENAPI_URLS=True

## Feature flags
#
# Uncomment to detect question language with Spacy
# FEATURE_QA_LANG_DETECT=True

## DB vars
PGVECTOR_DRIVER=psycopg2
### Database connection
# PGVECTOR_DRIVER=psycopg2
# host var is used on local development
# but ignored by docker compose
PGVECTOR_HOST=localhost
PGVECTOR_PORT=5432
PGVECTOR_DATABASE=brevia
PGVECTOR_USER=postgres
PGVECTOR_PASSWORD=postgres
PGVECTOR_POOL_SIZE=10
# used by docker compose only
PGVECTOR_VOLUME_NAME=pgvector-data

## PG ADMIN vars
PGADMIN_DEFAULT_EMAIL=[email protected]
PGADMIN_DEFAULT_PASSWORD=admin
PGADMIN_PORT=4000
# used by docker compose only
PGADMIN_VOLUME_NAME=pgadmin-data

## Tracing - Langsmith
# if you have an account uncomment lines below and edit API_KEY and PROJECT vars
# NB: You may want to add these vars to BREVIA_ENV_SECRETS in a local development environment
# LANGCHAIN_TRACING_V2=true
# LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
# LANGCHAIN_API_KEY="########"
# LANGCHAIN_PROJECT="My Project"
# PGVECTOR_HOST=localhost
# PGVECTOR_PORT=5432
# PGVECTOR_DATABASE=brevia
# PGVECTOR_USER=postgres
# PGVECTOR_PASSWORD=postgres
# PGVECTOR_POOL_SIZE=10

### Docker compose
## Postgres pgvector
# PGVECTOR_VOLUME_NAME=pgdata
## PG ADMIN
# [email protected]
# PGADMIN_DEFAULT_PASSWORD=admin
# PGADMIN_PORT=4000
# PGADMIN_VOLUME_NAME=pgadmindata
## BREVIA API
# BREVIA_API_PORT=8000
# BREVIA_API_VOLUME_NAME=breviaapidata
## BREVIA APP
# BREVIA_APP_PORT=3000
# BREVIA_APP_VOLUME_NAME=breviaappdata

22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
- patch
- minor
- major
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
release_job:
Expand Down Expand Up @@ -55,3 +58,22 @@ jobs:
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}

- name: Log in to the Container registry
if: ${{ !contains(needs.release_job.outputs.version, 'undefined') }}
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
if: ${{ !contains(needs.release_job.outputs.version, 'undefined') }}
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository }}:${{ needs.release_job.outputs.version }}
${{ env.REGISTRY }}/${{ github.repository }}:latest
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# syntax=docker/dockerfile:1
FROM python:3.10-alpine
FROM python:3.12-alpine

RUN apk add g++

# Extra python env
ENV PYTHONDONTWRITEBYTECODE=0
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV POETRY_VIRTUALENVS_CREATE=false

RUN pip install poetry

WORKDIR /python-docker

COPY . /python-docker/

RUN poetry install
RUN poetry install --no-interaction --no-ansi

RUN apk del g++

EXPOSE 8000

CMD ["poetry", "run", "uvicorn", "--host", "0.0.0.0", "--port", "8000", "main:app"]
CMD poetry run db_upgrade && poetry run uvicorn --host 0.0.0.0 --port 8000 main:app
1 change: 0 additions & 1 deletion brevia/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class Settings(BaseSettings):
qa_no_chat_history: bool = False # don't load chat history
qa_followup_sim_threshold: float = 0.735 # similitude threshold in followup
qa_retriever: Json[dict[str, Any]] = '{}' # custom retriever settings
feature_qa_lang_detect: bool = False

# Summarization
summ_default_chain: str = 'stuff'
Expand Down
72 changes: 50 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
version: '3.9'
services:
pgdatabase:
image: pgvector/pgvector:0.7.4-pg16
environment:
- POSTGRES_USER=${PGVECTOR_USER}
- POSTGRES_PASSWORD=${PGVECTOR_PASSWORD}
- POSTGRES_DB=${PGVECTOR_DATABASE}
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "${PGVECTOR_PORT}:5432"
pgadmin:
image: dpage/pgadmin4
profiles: ["admin"]
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
ports:
- "${PGADMIN_PORT}:80"
volumes:
- pgadmindata:/var/lib/pgadmin
pgdatabase:
image: pgvector/pgvector:0.7.4-pg16
environment:
- POSTGRES_USER=${PGVECTOR_USER:-postgres}
- POSTGRES_PASSWORD=${PGVECTOR_PASSWORD:-postgres}
- POSTGRES_DB=${PGVECTOR_DATABASE:-brevia}
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 5433:${PGVECTOR_PORT:-5432}
pgadmin:
image: dpage/pgadmin4
profiles: ["admin"]
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL:[email protected]}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD:-admin}
ports:
- "${PGADMIN_PORT:-4000}:80"
volumes:
- pgadmindata:/var/lib/pgadmin
breviaapi:
image: ghcr.io/brevia-ai/brevia:latest
profiles: ["api"]
environment:
- PGVECTOR_HOST=pgdatabase
- PGVECTOR_PORT=${PGVECTOR_PORT:-5432}
- PGVECTOR_DATABASE=${PGVECTOR_DATABASE:-brevia}
- PGVECTOR_USER=${PGVECTOR_USER:-postgres}
- PGVECTOR_PASSWORD=${PGVECTOR_PASSWORD:-postgres}
- BREVIA_ENV_SECRETS=${BREVIA_ENV_SECRETS}
ports:
- "${BREVIA_API_PORT:-8000}:8000"
volumes:
- breviaapidata:/var/lib/breviaapi
breviaapp:
image: ghcr.io/brevia-ai/brevia-app:latest
profiles: ["admin", "api"]
environment:
- NUXT_API_BASE_URL=http://breviaapi:${BREVIA_API_PORT:-8000}
ports:
- "${BREVIA_APP_PORT:-3000}:3000"
volumes:
- breviaappdata:/var/lib/breviaapp

volumes:
pgdata:
name: ${PGVECTOR_VOLUME_NAME}
name: ${PGVECTOR_VOLUME_NAME:-pgdata}
pgadmindata:
name: ${PGADMIN_VOLUME_NAME}
name: ${PGADMIN_VOLUME_NAME:-pgadmindata}
breviaappdata:
name: ${BREVIA_APP_VOLUME_NAME:-breviaapp}
breviaapidata:
name: ${BREVIA_API_VOLUME_NAME:-breviaapi}

0 comments on commit 72e25f1

Please sign in to comment.