Dockerfile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # syntax=docker/dockerfile:1
  2. # Initialize device type args
  3. # use build args in the docker build commmand with --build-arg="BUILDARG=true"
  4. ARG USE_CUDA=false
  5. ARG USE_OLLAMA=false
  6. # Tested with cu117 for CUDA 11 and cu121 for CUDA 12 (default)
  7. ARG USE_CUDA_VER=cu121
  8. # any sentence transformer model; models to use can be found at https://huggingface.co/models?library=sentence-transformers
  9. # Leaderboard: https://huggingface.co/spaces/mteb/leaderboard
  10. # for better performance and multilangauge support use "intfloat/multilingual-e5-large" (~2.5GB) or "intfloat/multilingual-e5-base" (~1.5GB)
  11. # IMPORTANT: If you change the embedding model (sentence-transformers/all-MiniLM-L6-v2) and vice versa, you aren't able to use RAG Chat with your previous documents loaded in the WebUI! You need to re-embed them.
  12. ARG USE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
  13. ARG USE_RERANKING_MODEL=""
  14. ######## WebUI frontend ########
  15. FROM --platform=$BUILDPLATFORM node:21-alpine3.19 as build
  16. WORKDIR /app
  17. COPY package.json package-lock.json ./
  18. RUN npm ci
  19. COPY . .
  20. RUN npm run build
  21. ######## WebUI backend ########
  22. FROM python:3.11-slim-bookworm as base
  23. # Use args
  24. ARG USE_CUDA
  25. ARG USE_OLLAMA
  26. ARG USE_CUDA_VER
  27. ARG USE_EMBEDDING_MODEL
  28. ARG USE_RERANKING_MODEL
  29. ## Basis ##
  30. ENV ENV=prod \
  31. PORT=8080 \
  32. # pass build args to the build
  33. USE_OLLAMA_DOCKER=${USE_OLLAMA} \
  34. USE_CUDA_DOCKER=${USE_CUDA} \
  35. USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
  36. USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \
  37. USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
  38. ## Basis URL Config ##
  39. ENV OLLAMA_BASE_URL="/ollama" \
  40. OPENAI_API_BASE_URL=""
  41. ## API Key and Security Config ##
  42. ENV OPENAI_API_KEY="" \
  43. WEBUI_SECRET_KEY="" \
  44. SCARF_NO_ANALYTICS=true \
  45. DO_NOT_TRACK=true
  46. # Use locally bundled version of the LiteLLM cost map json
  47. # to avoid repetitive startup connections
  48. ENV LITELLM_LOCAL_MODEL_COST_MAP="True"
  49. #### Other models #########################################################
  50. ## whisper TTS model settings ##
  51. ENV WHISPER_MODEL="base" \
  52. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  53. ## RAG Embedding model settings ##
  54. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  55. RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
  56. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  57. ## Hugging Face download cache ##
  58. ENV HF_HOME="/app/backend/data/cache/embedding/models"
  59. #### Other models ##########################################################
  60. WORKDIR /app/backend
  61. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  62. apt-get update && \
  63. # Install pandoc and netcat
  64. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  65. # for RAG OCR
  66. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  67. # install helper tools
  68. apt-get install -y --no-install-recommends curl && \
  69. # install ollama
  70. curl -fsSL https://ollama.com/install.sh | sh && \
  71. # cleanup
  72. rm -rf /var/lib/apt/lists/*; \
  73. else \
  74. apt-get update && \
  75. # Install pandoc and netcat
  76. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  77. # for RAG OCR
  78. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  79. # cleanup
  80. rm -rf /var/lib/apt/lists/*; \
  81. fi
  82. # install python dependencies
  83. COPY ./backend/requirements.txt ./requirements.txt
  84. RUN pip3 install uv && \
  85. if [ "$USE_CUDA" = "true" ]; then \
  86. # If you use CUDA the whisper and embedding model will be downloaded on first use
  87. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  88. uv pip install --system -r requirements.txt --no-cache-dir && \
  89. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  90. python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \
  91. else \
  92. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  93. uv pip install --system -r requirements.txt --no-cache-dir && \
  94. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  95. python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \
  96. fi
  97. # copy embedding weight from build
  98. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  99. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  100. # copy built frontend files
  101. COPY --from=build /app/build /app/build
  102. COPY --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  103. COPY --from=build /app/package.json /app/package.json
  104. # copy backend files
  105. COPY ./backend .
  106. EXPOSE 8080
  107. CMD [ "bash", "start.sh"]