Dockerfile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_MPS=false
  6. ARG INCLUDE_OLLAMA=false
  7. ######## WebUI frontend ########
  8. FROM node:21-alpine3.19 as build
  9. WORKDIR /app
  10. #RUN apt-get update \
  11. # && apt-get install -y --no-install-recommends wget \
  12. # # cleanup
  13. # && rm -rf /var/lib/apt/lists/*
  14. # wget embedding model weight from alpine (does not exist from slim-buster)
  15. #RUN wget "https://chroma-onnx-models.s3.amazonaws.com/all-MiniLM-L6-v2/onnx.tar.gz" -O - | \
  16. # tar -xzf - -C /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_MPS
  26. ARG INCLUDE_OLLAMA
  27. ## Basis ##
  28. ENV ENV=prod \
  29. PORT=8080 \
  30. # pass build args to the build
  31. INCLUDE_OLLAMA_DOCKER=${INCLUDE_OLLAMA} \
  32. USE_MPS_DOCKER=${USE_MPS} \
  33. USE_CUDA_DOCKER=${USE_CUDA}
  34. ## Basis URL Config ##
  35. ENV OLLAMA_BASE_URL="/ollama" \
  36. OPENAI_API_BASE_URL=""
  37. ## API Key and Security Config ##
  38. ENV OPENAI_API_KEY="" \
  39. WEBUI_SECRET_KEY="" \
  40. SCARF_NO_ANALYTICS=true \
  41. DO_NOT_TRACK=true
  42. #### Preloaded models #########################################################
  43. ## whisper TTS Settings ##
  44. ENV WHISPER_MODEL="base" \
  45. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  46. ## RAG Embedding Model Settings ##
  47. # any sentence transformer model; models to use can be found at https://huggingface.co/models?library=sentence-transformers
  48. # Leaderboard: https://huggingface.co/spaces/mteb/leaderboard
  49. # for better performance and multilangauge support use "intfloat/multilingual-e5-large" (~2.5GB) or "intfloat/multilingual-e5-base" (~1.5GB)
  50. # 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.
  51. ENV RAG_EMBEDDING_MODEL="all-MiniLM-L6-v2" \
  52. RAG_EMBEDDING_MODEL_DIR="/app/backend/data/cache/embedding/models" \
  53. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models" \
  54. # device type for whisper tts and embbeding models - "cpu" (default) or "mps" (apple silicon) - choosing this right can lead to better performance
  55. # Important:
  56. # If you want to use CUDA you need to install the nvidia-container-toolkit (https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
  57. # you can set this to "cuda" but its recomended to use --build-arg CUDA_ENABLED=true flag when building the image
  58. # RAG_EMBEDDING_MODEL_DEVICE_TYPE="cpu" \
  59. DEVICE_COMPUTE_TYPE="int8"
  60. # device type for whisper tts and embbeding models - "cpu" (default), "cuda" (nvidia gpu and CUDA required) or "mps" (apple silicon) - choosing this right can lead to better performance
  61. #### Preloaded models ##########################################################
  62. WORKDIR /app/backend
  63. # install python dependencies
  64. COPY ./backend/requirements.txt ./requirements.txt
  65. RUN if [ "$USE_CUDA" = "true" ]; then \
  66. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117 --no-cache-dir && \
  67. pip3 install -r requirements.txt --no-cache-dir; \
  68. elif [ "$USE_MPS" = "true" ]; then \
  69. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  70. pip3 install -r requirements.txt --no-cache-dir && \
  71. 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'])" && \
  72. python -c "import os; from chromadb.utils import embedding_functions; sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(model_name=os.environ['RAG_EMBEDDING_MODEL'], device='mps')"; \
  73. else \
  74. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  75. pip3 install -r requirements.txt --no-cache-dir && \
  76. 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'])" && \
  77. 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')"; \
  78. fi
  79. RUN if [ "$INCLUDE_OLLAMA" = "true" ]; then \
  80. apt-get update && \
  81. # Install pandoc and netcat
  82. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  83. # for RAG OCR
  84. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  85. # install helper tools
  86. apt-get install -y --no-install-recommends curl && \
  87. # install ollama
  88. curl -fsSL https://ollama.com/install.sh | sh && \
  89. # cleanup
  90. rm -rf /var/lib/apt/lists/*; \
  91. else \
  92. apt-get update && \
  93. # Install pandoc and netcat
  94. apt-get install -y --no-install-recommends pandoc netcat-openbsd && \
  95. # for RAG OCR
  96. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  97. # cleanup
  98. rm -rf /var/lib/apt/lists/*; \
  99. fi
  100. # copy embedding weight from build
  101. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  102. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  103. # copy built frontend files
  104. COPY --from=build /app/build /app/build
  105. COPY --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  106. COPY --from=build /app/package.json /app/package.json
  107. # copy backend files
  108. COPY ./backend .
  109. EXPOSE 8080
  110. CMD [ "bash", "start.sh"]