Updated docker compose

This commit is contained in:
Saurab-Shrestha 2024-04-29 20:08:06 +05:45
parent 3f99b0996f
commit f9a454861d
8 changed files with 2010 additions and 2632 deletions

View File

@ -9,4 +9,6 @@ local_data
terraform terraform
tests tests
Dockerfile Dockerfile
Dockerfile.* Dockerfile.*
private_gpt/static/unchecked
local_data/private_gpt

View File

@ -1,4 +1,16 @@
FROM python:3.11.6-slim-bookworm as base FROM python:3.11.6-slim-bookworm as base
# Set noninteractive mode
ENV DEBIAN_FRONTEND noninteractive
# Install necessary dependencies including CMake and g++
RUN apt-get update && apt-get install -y \
libopenblas-dev \
ninja-build \
build-essential \
pkg-config \
wget \
libgl1-mesa-glx \
python3-opencv \
&& apt-get clean
# Install poetry # Install poetry
RUN pip install pipx RUN pip install pipx
@ -6,36 +18,39 @@ RUN python3 -m pipx ensurepath
RUN pipx install poetry RUN pipx install poetry
ENV PATH="/root/.local/bin:$PATH" ENV PATH="/root/.local/bin:$PATH"
ENV PATH=".venv/bin/:$PATH" ENV PATH=".venv/bin/:$PATH"
# https://python-poetry.org/docs/configuration/#virtualenvsin-project # https://python-poetry.org/docs/configuration/#virtualenvsin-project
ENV POETRY_VIRTUALENVS_IN_PROJECT=true ENV POETRY_VIRTUALENVS_IN_PROJECT=true
FROM base as dependencies FROM base as dependencies
WORKDIR /home/worker/app WORKDIR /home/worker/app
COPY pyproject.toml poetry.lock ./ COPY pyproject.toml poetry.lock ./
RUN poetry install --extras "ui vector-stores-qdrant llms-ollama embeddings-ollama" RUN poetry install --extras "ui vector-stores-qdrant llms-ollama embeddings-ollama"
FROM base as app FROM base as app
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PORT=8080 ENV PORT=8000
EXPOSE 8080
# Prepare a non-root user # Prepare a non-root user
RUN adduser --system worker RUN adduser --system worker
WORKDIR /home/worker/app WORKDIR /home/worker/app
RUN mkdir local_data; chown worker local_data RUN mkdir local_data; chown worker local_data
RUN mkdir models; chown worker models RUN mkdir models; chown worker models
RUN mkdir tiktoken_cache; chown worker tiktoken_cache
COPY --chown=worker --from=dependencies /home/worker/app/.venv/ .venv COPY --chown=worker --from=dependencies /home/worker/app/.venv/ .venv
COPY --chown=worker private_gpt/ private_gpt COPY --chown=worker private_gpt/ private_gpt
COPY --chown=worker alembic/ alembic
COPY --chown=worker fern/ fern COPY --chown=worker fern/ fern
COPY --chown=worker *.yaml *.md ./ COPY --chown=worker *.yaml *.md ./
COPY --chown=worker scripts/ scripts COPY --chown=worker scripts/ scripts
RUN COPY --chown=worker *.ini ./
# Copy the docker-entrypoint.sh file
COPY docker-entrypoint.sh /home/worker/app/
RUN chmod +x /home/worker/app/docker-entrypoint.sh
ENV PYTHONPATH="$PYTHONPATH:/private_gpt/" ENV PYTHONPATH="$PYTHONPATH:/private_gpt/"
USER worker USER worker
ENTRYPOINT python -m private_gpt
EXPOSE 8000
# Copy the rest of the application code into the container
COPY . /home/worker/app
ENTRYPOINT [ "/home/worker/app/docker-entrypoint.sh" ]

View File

@ -1,28 +1,46 @@
version: '3.8'
services: services:
private-gpt: private-gpt:
build: build:
dockerfile: Dockerfile.external dockerfile: Dockerfile.external
volumes: entrypoint: ./docker-entrypoint.sh
- ./local_data/:/home/worker/app/local_data
ports:
<<<<<<< HEAD
- 80:80
environment:
PORT: 80
PGPT_PROFILES: docker
PGPT_MODE: local
env_file: env_file:
- .env - .env
volumes:
======= - ./local_data/:/home/worker/app/local_data
- 8001:8080 ports:
- 8000:8000
depends_on:
- db
- ollama
environment: environment:
PORT: 8080 PORT: 8000
PGPT_PROFILES: docker PGPT_PROFILES: docker
PGPT_MODE: ollama PGPT_MODE: ollama
DATABASE_URL: postgresql+psycopg2://${DB_USER}:${DB_PASSWORD}@db:${DB_PORT}/${DB_NAME}
ollama: ollama:
image: ollama/ollama:latest image: ollama/ollama:latest
volumes: volumes:
- ./models:/root/.ollama - ./models:/root/.ollama
>>>>>>> dev
db:
image: postgres:15-alpine
container_name: db
env_file:
- .env
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
# POSTGRES_HOST_AUTH_METHOD: trust
restart: always
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- 5433:${DB_PORT}
volumes:
postgres-data:

18
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
# Initialize alembic ini
# echo "Apply makemigrations "
# alembic init alembic
# Apply database migrations
echo "Apply makemigrations "
alembic revision --autogenerate
# Apply database migrations
echo "Apply database migrations"
alembic upgrade head
# Start server
echo "Starting server"
python -m private_gpt

4503
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,8 @@ from private_gpt.paths import models_cache_path, models_path
from private_gpt.settings.settings import Settings from private_gpt.settings.settings import Settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@singleton @singleton
class LLMComponent: class LLMComponent:
llm: LLM llm: LLM
@ -20,7 +22,9 @@ class LLMComponent:
@inject @inject
def __init__(self, settings: Settings) -> None: def __init__(self, settings: Settings) -> None:
llm_mode = settings.llm.mode llm_mode = settings.llm.mode
if settings.llm.tokenizer: if settings.llm.tokenizer and settings.llm.mode != "mock":
# Try to download the tokenizer. If it fails, the LLM will still work
# using the default one, which is less accurate.
try: try:
set_global_tokenizer( set_global_tokenizer(
AutoTokenizer.from_pretrained( AutoTokenizer.from_pretrained(
@ -37,7 +41,6 @@ class LLMComponent:
e, e,
) )
logger.info("Initializing the LLM in mode=%s", llm_mode) logger.info("Initializing the LLM in mode=%s", llm_mode)
match settings.llm.mode: match settings.llm.mode:
case "llamacpp": case "llamacpp":
@ -58,7 +61,8 @@ class LLMComponent:
"offload_kqv": True, "offload_kqv": True,
} }
self.llm = LlamaCPP( self.llm = LlamaCPP(
model_path=str(models_path / settings.llamacpp.llm_hf_model_file), model_path=str(
models_path / settings.llamacpp.llm_hf_model_file),
temperature=settings.llm.temperature, temperature=settings.llm.temperature,
max_new_tokens=settings.llm.max_new_tokens, max_new_tokens=settings.llm.max_new_tokens,
context_window=settings.llm.context_window, context_window=settings.llm.context_window,
@ -159,7 +163,8 @@ class LLMComponent:
Ollama.chat = add_keep_alive(Ollama.chat) Ollama.chat = add_keep_alive(Ollama.chat)
Ollama.stream_chat = add_keep_alive(Ollama.stream_chat) Ollama.stream_chat = add_keep_alive(Ollama.stream_chat)
Ollama.complete = add_keep_alive(Ollama.complete) Ollama.complete = add_keep_alive(Ollama.complete)
Ollama.stream_complete = add_keep_alive(Ollama.stream_complete) Ollama.stream_complete = add_keep_alive(
Ollama.stream_complete)
case "azopenai": case "azopenai":
try: try:

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "private-gpt" name = "private-gpt"
version = "0.5.0" version = "0.4.0"
description = "Private GPT" description = "Private GPT"
authors = ["Zylon <hi@zylon.ai>"] authors = ["Zylon <hi@zylon.ai>"]
@ -16,7 +16,7 @@ alembic = "^1.13.1"
sqlalchemy = "^2.0.28" sqlalchemy = "^2.0.28"
bcrypt = "4.0.1" bcrypt = "4.0.1"
python-jose = "^3.3.0" python-jose = "^3.3.0"
#psycopg2-binary = "^2.9.9" psycopg2-binary = "^2.9.9"
passlib = "^1.7.4" passlib = "^1.7.4"
docx2txt = "^0.8" docx2txt = "^0.8"
ldap3 = "^2.9.1" ldap3 = "^2.9.1"
@ -25,7 +25,7 @@ python-doctr = "^0.8.1"
python-docx = "^1.1.0" python-docx = "^1.1.0"
watchdog = "^4.0.0" watchdog = "^4.0.0"
# https://stackoverflow.com/questions/76327419/valueerror-libcublas-so-0-9-not-found-in-the-system-path # https://stackoverflow.com/questions/76327419/valueerror-libcublas-so-0-9-not-found-in-the-system-path
#torch = ">=2.0.0, !=2.0.1, !=2.1.0" torch = ">=2.0.0, !=2.0.1, !=2.1.0"
torchvision = "^0.17.1" torchvision = "^0.17.1"
transformers = "^4.38.2" transformers = "^4.38.2"
@ -38,28 +38,16 @@ llama-index-llms-llama-cpp = {version = "^0.1.3", optional = true}
llama-index-llms-openai = {version = "^0.1.6", optional = true} llama-index-llms-openai = {version = "^0.1.6", optional = true}
llama-index-llms-openai-like = {version ="^0.1.3", optional = true} llama-index-llms-openai-like = {version ="^0.1.3", optional = true}
llama-index-llms-ollama = {version ="^0.1.2", optional = true} llama-index-llms-ollama = {version ="^0.1.2", optional = true}
llama-index-llms-azure-openai = {version ="^0.1.5", optional = true}
llama-index-embeddings-ollama = {version ="^0.1.2", optional = true} llama-index-embeddings-ollama = {version ="^0.1.2", optional = true}
llama-index-embeddings-huggingface = {version ="^0.1.4", optional = true} llama-index-embeddings-huggingface = {version ="^0.1.4", optional = true}
llama-index-embeddings-openai = {version ="^0.1.6", optional = true} llama-index-embeddings-openai = {version ="^0.1.6", optional = true}
llama-index-embeddings-azure-openai = {version ="^0.1.6", optional = true}
llama-index-vector-stores-qdrant = {version ="^0.1.3", optional = true} llama-index-vector-stores-qdrant = {version ="^0.1.3", optional = true}
llama-index-vector-stores-chroma = {version ="^0.1.4", optional = true} llama-index-vector-stores-chroma = {version ="^0.1.4", optional = true}
llama-index-vector-stores-postgres = {version ="^0.1.2", optional = true} llama-index-vector-stores-postgres = {version ="^0.1.2", optional = true}
llama-index-storage-docstore-postgres = {version ="^0.1.2", optional = true}
llama-index-storage-index-store-postgres = {version ="^0.1.2", optional = true}
# Postgres
psycopg2-binary = {version ="^2.9.9", optional = false}
asyncpg = {version="^0.29.0", optional = true}
# Optional Sagemaker dependency # Optional Sagemaker dependency
boto3 = {version ="^1.34.51", optional = true} boto3 = {version ="^1.34.51", optional = true}
# Optional Reranker dependencies
torch = {version ="^2.1.2", optional = false}
sentence-transformers = {version ="^2.6.1", optional = true}
# Optional UI # Optional UI
gradio = {version ="^4.19.2", optional = true} gradio = {version ="^4.19.2", optional = true}
aiofiles = "^23.2.1" aiofiles = "^23.2.1"
@ -78,17 +66,14 @@ llms-openai = ["llama-index-llms-openai"]
llms-openai-like = ["llama-index-llms-openai-like"] llms-openai-like = ["llama-index-llms-openai-like"]
llms-ollama = ["llama-index-llms-ollama"] llms-ollama = ["llama-index-llms-ollama"]
llms-sagemaker = ["boto3"] llms-sagemaker = ["boto3"]
llms-azopenai = ["llama-index-llms-azure-openai"]
embeddings-ollama = ["llama-index-embeddings-ollama"] embeddings-ollama = ["llama-index-embeddings-ollama"]
embeddings-huggingface = ["llama-index-embeddings-huggingface"] embeddings-huggingface = ["llama-index-embeddings-huggingface"]
embeddings-openai = ["llama-index-embeddings-openai"] embeddings-openai = ["llama-index-embeddings-openai"]
embeddings-sagemaker = ["boto3"] embeddings-sagemaker = ["boto3"]
embeddings-azopenai = ["llama-index-embeddings-azure-openai"]
vector-stores-qdrant = ["llama-index-vector-stores-qdrant"] vector-stores-qdrant = ["llama-index-vector-stores-qdrant"]
vector-stores-chroma = ["llama-index-vector-stores-chroma"] vector-stores-chroma = ["llama-index-vector-stores-chroma"]
vector-stores-postgres = ["llama-index-vector-stores-postgres"] vector-stores-postgres = ["llama-index-vector-stores-postgres"]
storage-nodestore-postgres = ["llama-index-storage-docstore-postgres","llama-index-storage-index-store-postgres","psycopg2-binary","asyncpg"]
rerank-sentence-transformers = ["torch", "sentence-transformers"]
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
black = "^22" black = "^22"

View File

@ -99,7 +99,7 @@ openai:
model: gpt-3.5-turbo model: gpt-3.5-turbo
ollama: ollama:
llm_model: llama2 llm_model: llama3
embedding_model: nomic-embed-text embedding_model: nomic-embed-text
api_base: http://localhost:11434 api_base: http://localhost:11434
embedding_api_base: http://localhost:11434 # change if your embedding model runs on another ollama embedding_api_base: http://localhost:11434 # change if your embedding model runs on another ollama