Dockerfile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 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. #### Other models #########################################################
  44. ## whisper TTS model settings ##
  45. ENV WHISPER_MODEL="base" \
  46. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  47. ## RAG Embedding model settings ##
  48. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  49. RAG_EMBEDDING_MODEL_DIR="/app/backend/data/cache/embedding/models" \
  50. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  51. #### Other models ##########################################################
  52. WORKDIR /app/backend
  53. # install python dependencies
  54. COPY ./backend/requirements.txt ./requirements.txt
  55. RUN if [ "$USE_CUDA" = "true" ]; then \
  56. # If you use CUDA the whisper and embedding modell will be downloaded on first use
  57. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  58. pip3 install -r requirements.txt --no-cache-dir && \
  59. 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'])"; \
  60. else \
  61. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  62. pip3 install -r requirements.txt --no-cache-dir && \
  63. 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'])" && \
  64. 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')"; \
  65. fi
  66. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  67. apt-get update && \
  68. # Install pandoc and netcat
  69. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  70. # for RAG OCR
  71. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  72. # install helper tools
  73. apt-get install -y --no-install-recommends curl && \
  74. # install ollama
  75. curl -fsSL https://ollama.com/install.sh | sh && \
  76. # cleanup
  77. rm -rf /var/lib/apt/lists/*; \
  78. else \
  79. apt-get update && \
  80. # Install pandoc and netcat
  81. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  82. # for RAG OCR
  83. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  84. # cleanup
  85. rm -rf /var/lib/apt/lists/*; \
  86. fi
  87. # copy embedding weight from build
  88. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  89. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  90. # copy built frontend files
  91. COPY --from=build /app/build /app/build
  92. COPY --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  93. COPY --from=build /app/package.json /app/package.json
  94. # copy backend files
  95. COPY ./backend .
  96. EXPOSE 8080
  97. CMD [ "bash", "start.sh"]