Dockerfile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 default model (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=all-MiniLM-L6-v2
  13. ######## WebUI frontend ########
  14. FROM --platform=$BUILDPLATFORM node:21-alpine3.19 as build
  15. WORKDIR /app
  16. COPY package.json package-lock.json ./
  17. RUN npm ci
  18. COPY . .
  19. RUN npm run build
  20. ######## WebUI backend ########
  21. FROM python:3.11-slim-bookworm as base
  22. # Use args
  23. ARG USE_CUDA
  24. ARG USE_OLLAMA
  25. ARG USE_CUDA_VER
  26. ARG USE_EMBEDDING_MODEL
  27. ## Basis ##
  28. ENV ENV=prod \
  29. PORT=8080 \
  30. # pass build args to the build
  31. USE_OLLAMA_DOCKER=${USE_OLLAMA} \
  32. USE_CUDA_DOCKER=${USE_CUDA} \
  33. USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
  34. USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL}
  35. ## Basis URL Config ##
  36. ENV OLLAMA_BASE_URL="/ollama" \
  37. OPENAI_API_BASE_URL=""
  38. ## API Key and Security Config ##
  39. ENV OPENAI_API_KEY="" \
  40. WEBUI_SECRET_KEY="" \
  41. SCARF_NO_ANALYTICS=true \
  42. DO_NOT_TRACK=true
  43. # Use locally bundled version of the LiteLLM cost map json
  44. # to avoid repetitive startup connections
  45. ENV LITELLM_LOCAL_MODEL_COST_MAP="True"
  46. #### Other models #########################################################
  47. ## whisper TTS model settings ##
  48. ENV WHISPER_MODEL="base" \
  49. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  50. ## RAG Embedding model settings ##
  51. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  52. RAG_EMBEDDING_MODEL_DIR="/app/backend/data/cache/embedding/models" \
  53. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  54. #### Other models ##########################################################
  55. WORKDIR /app/backend
  56. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  57. apt-get update && \
  58. # Install pandoc and netcat
  59. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  60. # for RAG OCR
  61. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  62. # install helper tools
  63. apt-get install -y --no-install-recommends curl && \
  64. # install ollama
  65. curl -fsSL https://ollama.com/install.sh | sh && \
  66. # cleanup
  67. rm -rf /var/lib/apt/lists/*; \
  68. else \
  69. apt-get update && \
  70. # Install pandoc and netcat
  71. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  72. # for RAG OCR
  73. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  74. # cleanup
  75. rm -rf /var/lib/apt/lists/*; \
  76. fi
  77. # install python dependencies
  78. COPY ./backend/requirements.txt ./requirements.txt
  79. RUN pip3 install uv && \
  80. if [ "$USE_CUDA" = "true" ]; then \
  81. # If you use CUDA the whisper and embedding model will be downloaded on first use
  82. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  83. uv pip install --system -r requirements.txt --no-cache-dir && \
  84. 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'])" && \
  85. python -c "import os; from chromadb.utils import embedding_functions; sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(model_name=os.environ['RAG_EMBEDDING_MODEL'], device='cpu')"; \
  86. else \
  87. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  88. uv pip install --system -r requirements.txt --no-cache-dir && \
  89. 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'])" && \
  90. python -c "import os; from chromadb.utils import embedding_functions; sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(model_name=os.environ['RAG_EMBEDDING_MODEL'], device='cpu')"; \
  91. fi
  92. # copy embedding weight from build
  93. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  94. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  95. # copy built frontend files
  96. COPY --from=build /app/build /app/build
  97. COPY --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  98. COPY --from=build /app/package.json /app/package.json
  99. # copy backend files
  100. COPY ./backend .
  101. EXPOSE 8080
  102. CMD [ "bash", "start.sh"]