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

@ -10,3 +10,5 @@ terraform
tests
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
# 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
RUN pip install pipx
@ -6,36 +18,39 @@ RUN python3 -m pipx ensurepath
RUN pipx install poetry
ENV PATH="/root/.local/bin:$PATH"
ENV PATH=".venv/bin/:$PATH"
# https://python-poetry.org/docs/configuration/#virtualenvsin-project
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
FROM base as dependencies
WORKDIR /home/worker/app
COPY pyproject.toml poetry.lock ./
RUN poetry install --extras "ui vector-stores-qdrant llms-ollama embeddings-ollama"
FROM base as app
ENV PYTHONUNBUFFERED=1
ENV PORT=8080
EXPOSE 8080
ENV PORT=8000
# Prepare a non-root user
RUN adduser --system worker
WORKDIR /home/worker/app
RUN mkdir local_data; chown worker local_data
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 private_gpt/ private_gpt
COPY --chown=worker alembic/ alembic
COPY --chown=worker fern/ fern
COPY --chown=worker *.yaml *.md ./
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/"
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:
private-gpt:
build:
dockerfile: Dockerfile.external
volumes:
- ./local_data/:/home/worker/app/local_data
ports:
<<<<<<< HEAD
- 80:80
environment:
PORT: 80
PGPT_PROFILES: docker
PGPT_MODE: local
entrypoint: ./docker-entrypoint.sh
env_file:
- .env
=======
- 8001:8080
volumes:
- ./local_data/:/home/worker/app/local_data
ports:
- 8000:8000
depends_on:
- db
- ollama
environment:
PORT: 8080
PORT: 8000
PGPT_PROFILES: docker
PGPT_MODE: ollama
DATABASE_URL: postgresql+psycopg2://${DB_USER}:${DB_PASSWORD}@db:${DB_PORT}/${DB_NAME}
ollama:
image: ollama/ollama:latest
volumes:
- ./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
logger = logging.getLogger(__name__)
@singleton
class LLMComponent:
llm: LLM
@ -20,7 +22,9 @@ class LLMComponent:
@inject
def __init__(self, settings: Settings) -> None:
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:
set_global_tokenizer(
AutoTokenizer.from_pretrained(
@ -37,7 +41,6 @@ class LLMComponent:
e,
)
logger.info("Initializing the LLM in mode=%s", llm_mode)
match settings.llm.mode:
case "llamacpp":
@ -58,7 +61,8 @@ class LLMComponent:
"offload_kqv": True,
}
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,
max_new_tokens=settings.llm.max_new_tokens,
context_window=settings.llm.context_window,
@ -159,7 +163,8 @@ class LLMComponent:
Ollama.chat = add_keep_alive(Ollama.chat)
Ollama.stream_chat = add_keep_alive(Ollama.stream_chat)
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":
try:

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "private-gpt"
version = "0.5.0"
version = "0.4.0"
description = "Private GPT"
authors = ["Zylon <hi@zylon.ai>"]
@ -16,7 +16,7 @@ alembic = "^1.13.1"
sqlalchemy = "^2.0.28"
bcrypt = "4.0.1"
python-jose = "^3.3.0"
#psycopg2-binary = "^2.9.9"
psycopg2-binary = "^2.9.9"
passlib = "^1.7.4"
docx2txt = "^0.8"
ldap3 = "^2.9.1"
@ -25,7 +25,7 @@ python-doctr = "^0.8.1"
python-docx = "^1.1.0"
watchdog = "^4.0.0"
# 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"
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-like = {version ="^0.1.3", 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-huggingface = {version ="^0.1.4", 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-chroma = {version ="^0.1.4", 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
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
gradio = {version ="^4.19.2", optional = true}
aiofiles = "^23.2.1"
@ -78,17 +66,14 @@ llms-openai = ["llama-index-llms-openai"]
llms-openai-like = ["llama-index-llms-openai-like"]
llms-ollama = ["llama-index-llms-ollama"]
llms-sagemaker = ["boto3"]
llms-azopenai = ["llama-index-llms-azure-openai"]
embeddings-ollama = ["llama-index-embeddings-ollama"]
embeddings-huggingface = ["llama-index-embeddings-huggingface"]
embeddings-openai = ["llama-index-embeddings-openai"]
embeddings-sagemaker = ["boto3"]
embeddings-azopenai = ["llama-index-embeddings-azure-openai"]
vector-stores-qdrant = ["llama-index-vector-stores-qdrant"]
vector-stores-chroma = ["llama-index-vector-stores-chroma"]
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]
black = "^22"

View File

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