Dockerfile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. ANONYMIZED_TELEMETRY=false
  47. # Use locally bundled version of the LiteLLM cost map json
  48. # to avoid repetitive startup connections
  49. ENV LITELLM_LOCAL_MODEL_COST_MAP="True"
  50. #### Other models #########################################################
  51. ## whisper TTS model settings ##
  52. ENV WHISPER_MODEL="base" \
  53. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  54. ## RAG Embedding model settings ##
  55. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  56. RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
  57. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  58. ## Hugging Face download cache ##
  59. ENV HF_HOME="/app/backend/data/cache/embedding/models"
  60. #### Other models ##########################################################
  61. WORKDIR /app/backend
  62. ENV HOME /root
  63. RUN mkdir -p $HOME/.cache/chroma
  64. RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
  65. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  66. apt-get update && \
  67. # Install pandoc and netcat
  68. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  69. # for RAG OCR
  70. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  71. # install helper tools
  72. apt-get install -y --no-install-recommends curl && \
  73. # install ollama
  74. curl -fsSL https://ollama.com/install.sh | sh && \
  75. # cleanup
  76. rm -rf /var/lib/apt/lists/*; \
  77. else \
  78. apt-get update && \
  79. # Install pandoc and netcat
  80. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  81. # for RAG OCR
  82. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  83. # cleanup
  84. rm -rf /var/lib/apt/lists/*; \
  85. fi
  86. # install python dependencies
  87. COPY ./backend/requirements.txt ./requirements.txt
  88. RUN pip3 install uv && \
  89. if [ "$USE_CUDA" = "true" ]; then \
  90. # If you use CUDA the whisper and embedding model will be downloaded on first use
  91. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  92. uv pip install --system -r requirements.txt --no-cache-dir && \
  93. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  94. 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'])"; \
  95. else \
  96. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  97. uv pip install --system -r requirements.txt --no-cache-dir && \
  98. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  99. 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'])"; \
  100. fi
  101. # copy embedding weight from build
  102. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  103. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  104. # copy built frontend files
  105. COPY --from=build /app/build /app/build
  106. COPY --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  107. COPY --from=build /app/package.json /app/package.json
  108. # copy backend files
  109. COPY ./backend .
  110. EXPOSE 8080
  111. CMD [ "bash", "start.sh"]