From 667e9e1a84999f3b1a214c41677c9c6ee2b7cdcc Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Mon, 8 Jan 2024 20:07:37 -0500 Subject: [PATCH 1/9] adding built-localGPT --- .github/workflows/build-loalGPT.yml | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/build-loalGPT.yml diff --git a/.github/workflows/build-loalGPT.yml b/.github/workflows/build-loalGPT.yml new file mode 100644 index 00000000..8abd7dc9 --- /dev/null +++ b/.github/workflows/build-loalGPT.yml @@ -0,0 +1,30 @@ +name: Docker Build and Run localGPT + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build-and-run: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build and Run Docker Image + run: | + docker build . --file Dockerfile --tag localgpt --build-arg device_type=cpu --load + docker run -it --mount src="$HOME/.cache",target=/root/.cache,type=bind --gpus=all localgpt From df2cd02a61fa109f5f11c181b6e3bfe9eb11a222 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 16:21:20 -0500 Subject: [PATCH 2/9] adding docker compose files --- Dockerfile | 2 +- Dockerfile.api | 23 +++++++++++++++++ Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 35 ++++++++++++++++++++++++++ docs/docker-compose.md | 10 ++++++++ localGPTUI/Dockerfile | 22 ++++++++++++++++ 6 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.api create mode 100644 Makefile create mode 100644 docker-compose.yaml create mode 100644 docs/docker-compose.md create mode 100644 localGPTUI/Dockerfile diff --git a/Dockerfile b/Dockerfile index f6517151..a47871ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ ARG device_type=cpu RUN --mount=type=cache,target=/root/.cache python ingest.py --device_type $device_type COPY . . ENV device_type=cuda -CMD python run_localGPT.py --device_type $device_type +CMD python run_localGPT.py --device_type $device_type \ No newline at end of file diff --git a/Dockerfile.api b/Dockerfile.api new file mode 100644 index 00000000..9ef60ae4 --- /dev/null +++ b/Dockerfile.api @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1 +# Build as `docker build . -t localgpt`, requires BuildKit. +# Run as `docker run -it --mount src="$HOME/.cache",target=/root/.cache,type=bind --gpus=all localgpt`, requires Nvidia container toolkit. + +FROM nvidia/cuda:11.7.1-runtime-ubuntu22.04 +RUN apt-get update && apt-get install -y software-properties-common +RUN apt-get install -y g++-11 make python3 python-is-python3 pip +# only copy what's needed at every step to optimize layer cache +COPY ./requirements.txt . +# use BuildKit cache mount to drastically reduce redownloading from pip on repeated builds +RUN --mount=type=cache,target=/root/.cache CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip install --timeout 100 -r requirements.txt llama-cpp-python==0.1.83 +#COPY SOURCE_DOCUMENTS ./SOURCE_DOCUMENTS +#RUN ls -lath . +RUN mkdir -p ./SOURCE_DOCUMENTS +COPY ingest.py constants.py ./ +# Docker BuildKit does not support GPU during *docker build* time right now, only during *docker run*. +# See . +# If this changes in the future you can `docker build --build-arg device_type=cuda . -t localgpt` (+GPU argument to be determined). +#ARG device_type=cpu +#RUN --mount=type=cache,target=/root/.cache python ingest.py --device_type $device_type +COPY . . +#ENV device_type=cuda +#CMD python run_localGPT.py --device_type $device_type \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..bb158cda --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +# Makefile for Docker Compose operations + +# Default values for environment variables +DEVICE_TYPE := cpu +SOURCE_DOCUMENTS := SOURCE_DOCUMENTS # Replace with your default source documents directory + +# Default target executed when no arguments are given to make. +.PHONY: all +all: build + +# Target for building the Docker image using Docker Compose +.PHONY: build +build: + @echo "Building Docker image with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." + @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose build + +# Target for running the Docker container using Docker Compose +.PHONY: run +run: + @echo "Running Docker container with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." + @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose up + +# Target to stop the running container using Docker Compose +.PHONY: stop +stop: + @echo "Stopping Docker container..." + @docker-compose down + +# Target for setting the device type to GPU (CUDA) +.PHONY: use-gpu +use-gpu: + $(eval DEVICE_TYPE := cuda) + +# Target for setting the device type to CPU +.PHONY: use-cpu +use-cpu: + $(eval DEVICE_TYPE := cpu) + +# Target to set the source documents directory +.PHONY: set-source-docs +set-source-docs: + $(eval SOURCE_DOCUMENTS := $(dir)) + +# Help target describing how to use the Makefile +.PHONY: help +help: + @echo "Makefile for Docker Compose operations" + @echo " make build - Builds the Docker image with the current DEVICE_TYPE and SOURCE_DOCUMENTS" + @echo " make run - Runs the Docker container with the current DEVICE_TYPE and SOURCE_DOCUMENTS" + @echo " make stop - Stops the running Docker container" + @echo " make use-gpu - Sets the DEVICE_TYPE to cuda (GPU)" + @echo " make use-cpu - Sets the DEVICE_TYPE to cpu" + @echo " make set-source-docs dir= - Sets the SOURCE_DOCUMENTS directory" + @echo " make help - Displays this help" + +# Use this command to set the source documents directory +# Example usage: make set-source-docs dir=MyDocuments diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..e3d45731 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + localgpt: + build: + context: . + dockerfile: Dockerfile.api + image: localgpt + environment: + - device_type=${DEVICE_TYPE} + - source_documents=${SOURCE_DOCUMENTS} + volumes: + - "$HOME/.cache:/root/.cache" + - "$HOME/${source_documents}:/SOURCE_DOCUMENTS" + runtime: nvidia + command: python run_localGPT.py --device_type ${device_type} + networks: + - localgpt-network + + localgpt-ui: + build: + context: localGPTUI/ + dockerfile: Dockerfile # Assuming the Dockerfile for Flask app is named Dockerfile + ports: + - "5111:5111" # Map port 5111 inside the container to port 5111 on the Docker host + environment: + API_HOST: http://localgpt:PORT # Replace PORT with the actual port localgpt service is listening on + depends_on: + - localgpt + networks: + - localgpt-network + +networks: + localgpt-network: + driver: bridge diff --git a/docs/docker-compose.md b/docs/docker-compose.md new file mode 100644 index 00000000..7ac764de --- /dev/null +++ b/docs/docker-compose.md @@ -0,0 +1,10 @@ +How to Use: +Set the Environment Variable: + +Before running Docker Compose, you need to set the DEVICE_TYPE environment variable on your host machine. You can do this by running export DEVICE_TYPE=cuda for GPU or export DEVICE_TYPE=cpu for CPU. +Build and Run: + +Use docker-compose up --build to build and start the container. +Stopping the Container: + +Use docker-compose down to stop and remove the container. \ No newline at end of file diff --git a/localGPTUI/Dockerfile b/localGPTUI/Dockerfile new file mode 100644 index 00000000..6c2375c1 --- /dev/null +++ b/localGPTUI/Dockerfile @@ -0,0 +1,22 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy the current directory contents into the container at /usr/src/app +COPY . . + +# Install any needed packages specified in requirements.txt +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 5111 available to the world outside this container +EXPOSE 5111 + +# Define environment variable +ENV FLASK_APP=app.py +ENV FLASK_RUN_HOST=0.0.0.0 + +# Run app.py when the container launches +CMD ["flask", "run", "--host=0.0.0.0", "--port=5111"] From 57c3e17f63bd52316131f6b5d64689d75943c0b4 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 16:23:22 -0500 Subject: [PATCH 3/9] adding requirements file --- localGPTUI/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 localGPTUI/requirements.txt diff --git a/localGPTUI/requirements.txt b/localGPTUI/requirements.txt new file mode 100644 index 00000000..073ce608 --- /dev/null +++ b/localGPTUI/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.1 +requests==2.25.1 From f7b7db5092f0c24e960279ee46f14f1f1ee81db9 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 17:02:29 -0500 Subject: [PATCH 4/9] adding new workglow --- .github/workflows/build-loalGPT.yml | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-loalGPT.yml b/.github/workflows/build-loalGPT.yml index 8abd7dc9..e28a2c67 100644 --- a/.github/workflows/build-loalGPT.yml +++ b/.github/workflows/build-loalGPT.yml @@ -1,30 +1,28 @@ -name: Docker Build and Run localGPT +name: Docker Compose Actions -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] +on: [push, pull_request] jobs: build-and-run: runs-on: ubuntu-latest + steps: - - name: Checkout Repository + - name: Checkout code uses: actions/checkout@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- + - name: Build Docker Images + run: | + docker-compose build + + - name: Run Docker Containers + run: | + docker-compose up -d + + # Add any additional steps like testing, if necessary - - name: Build and Run Docker Image + - name: Shutdown run: | - docker build . --file Dockerfile --tag localgpt --build-arg device_type=cpu --load - docker run -it --mount src="$HOME/.cache",target=/root/.cache,type=bind --gpus=all localgpt + docker-compose down From 62f3c154dca9ab442fcd3742c438ab396ff11f0b Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 17:02:43 -0500 Subject: [PATCH 5/9] med --- docker-compose.yaml | 7 +++---- localGPTUI/Dockerfile | 14 +++++--------- localGPTUI/requirements.txt | 5 +++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index e3d45731..935889ad 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,19 +12,18 @@ services: volumes: - "$HOME/.cache:/root/.cache" - "$HOME/${source_documents}:/SOURCE_DOCUMENTS" - runtime: nvidia - command: python run_localGPT.py --device_type ${device_type} + command: python run_localGPT_API.py --port 8080 --host 0.0.0.0 networks: - localgpt-network localgpt-ui: build: context: localGPTUI/ - dockerfile: Dockerfile # Assuming the Dockerfile for Flask app is named Dockerfile + dockerfile: Dockerfile ports: - "5111:5111" # Map port 5111 inside the container to port 5111 on the Docker host environment: - API_HOST: http://localgpt:PORT # Replace PORT with the actual port localgpt service is listening on + API_HOST: http://localgpt:8080/api depends_on: - localgpt networks: diff --git a/localGPTUI/Dockerfile b/localGPTUI/Dockerfile index 6c2375c1..18d84068 100644 --- a/localGPTUI/Dockerfile +++ b/localGPTUI/Dockerfile @@ -4,19 +4,15 @@ FROM python:3.9-slim # Set the working directory in the container WORKDIR /usr/src/app -# Copy the current directory contents into the container at /usr/src/app -COPY . . - # Install any needed packages specified in requirements.txt COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt +# Copy the current directory contents into the container at /usr/src/app +COPY . . + # Make port 5111 available to the world outside this container EXPOSE 5111 -# Define environment variable -ENV FLASK_APP=app.py -ENV FLASK_RUN_HOST=0.0.0.0 - -# Run app.py when the container launches -CMD ["flask", "run", "--host=0.0.0.0", "--port=5111"] +# Run localGPTUI.py when the container launches +CMD ["python", "localGPTUI.py", "--host=0.0.0.0", "--port=5111"] diff --git a/localGPTUI/requirements.txt b/localGPTUI/requirements.txt index 073ce608..3d80603b 100644 --- a/localGPTUI/requirements.txt +++ b/localGPTUI/requirements.txt @@ -1,2 +1,3 @@ -Flask==2.0.1 -requests==2.25.1 +Flask==2.0.1 +Werkzeug==2.0.1 +requests==2.25.1 \ No newline at end of file From 52f6ceddd0ba3bb124a64877515114d06f888e33 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 17:45:47 -0500 Subject: [PATCH 6/9] updating code --- docker-compose.yaml | 2 +- run_inject.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100755 run_inject.sh diff --git a/docker-compose.yaml b/docker-compose.yaml index 935889ad..2c921fd0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,7 +11,7 @@ services: - source_documents=${SOURCE_DOCUMENTS} volumes: - "$HOME/.cache:/root/.cache" - - "$HOME/${source_documents}:/SOURCE_DOCUMENTS" + - "$HOME/${SOURCE_DOCUMENTS}:/SOURCE_DOCUMENTS" command: python run_localGPT_API.py --port 8080 --host 0.0.0.0 networks: - localgpt-network diff --git a/run_inject.sh b/run_inject.sh new file mode 100755 index 00000000..fb6bf170 --- /dev/null +++ b/run_inject.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Check if enough arguments are passed +if [ $# -lt 3 ]; then + echo "Usage: $0 " + echo "device_type: cpu | mps" + echo "exec_env: machine | container" + echo "action: download | copy" + exit 1 +fi + +# Name of the Docker container +CONTAINER_NAME="localgpt_localgpt_1" + +# Set the device type (cpu or mps) +DEVICE_TYPE="$1" + +# Execution environment: "container" or "machine" +EXEC_ENV="$2" + +# Action: "download" or "copy" +ACTION="$3" + + +# PDF source - URL or local path +PDF_SOURCE="https://github.com/TatevKaren/free-resources-books-papers/blob/main/DataEngineering_HandBook.pdf" # URL of the PDF to download +LOCAL_PDF_PATH="$HOME/localGPT/SOURCE_DOCUMENTS/" # Local path of the PDF (if not downloading) + +# Destination path for the PDF +DESTINATION_PATH="$HOME/SOURCE_DOCUMENTS/" # Directory to save the PDF + +# Create destination directory if it doesn't exist +mkdir -p "$DESTINATION_PATH" + +# Function to download PDF +download_pdf() { + echo "Downloading PDF from $PDF_SOURCE..." + curl -o "$DESTINATION_PATH/downloaded_document.pdf" "$PDF_SOURCE" +} + +# Function to copy PDF +# Function to copy PDF files +copy_pdfs() { + echo "Copying PDF files from $LOCAL_PDF_PATH to $DESTINATION_PATH..." + for pdf_file in "$LOCAL_PDF_PATH"/*.pdf; do + if [ -f "$pdf_file" ]; then + pdf_filename=$(basename "$pdf_file") + cp "$pdf_file" "$DESTINATION_PATH/$pdf_filename" + echo "Copied: $pdf_filename" + fi + done +} + +# Uncomment the function you need: +# download_pdf +# copy_pdf + +# Run python script with device type +run_ingest() { + echo "Running ingest.py with device type $DEVICE_TYPE..." + if [ "$EXEC_ENV" = "container" ]; then + # Run in Docker container + docker exec "$CONTAINER_NAME" python ingest.py --device_type "$DEVICE_TYPE" + else + # Run on local machine + python ingest.py --device_type "$DEVICE_TYPE" + fi +} + +# Choose action based on the argument +case $ACTION in + download) + download_pdf + ;; + copy) + copy_pdfs + ;; + *) + echo "Invalid action: $ACTION" + exit 2 + ;; +esac + +run_ingest From 1c7151c018db14f8d4f2bb1be3ae2d9586b6b1d6 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 17:51:37 -0500 Subject: [PATCH 7/9] udpating docs --- docs/docker-compose.md | 92 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/docs/docker-compose.md b/docs/docker-compose.md index 7ac764de..0fb7bca7 100644 --- a/docs/docker-compose.md +++ b/docs/docker-compose.md @@ -1,10 +1,88 @@ -How to Use: -Set the Environment Variable: +Here is the Markdown documentation for the Makefile: -Before running Docker Compose, you need to set the DEVICE_TYPE environment variable on your host machine. You can do this by running export DEVICE_TYPE=cuda for GPU or export DEVICE_TYPE=cpu for CPU. -Build and Run: +# Makefile for Docker Compose operations -Use docker-compose up --build to build and start the container. -Stopping the Container: +## Default values for environment variables +```makefile +DEVICE_TYPE := cpu +SOURCE_DOCUMENTS := SOURCE_DOCUMENTS +``` +Replace `SOURCE_DOCUMENTS` with your default source documents directory -Use docker-compose down to stop and remove the container. \ No newline at end of file +## Default target +Executed when no arguments are given to make. +```makefile +.PHONY: all +all: build +``` + +## Build target +Builds the Docker image using Docker Compose +```makefile +.PHONY: build +build: + @echo "Building Docker image with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." + @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose build +``` + +## Run target +Runs the Docker container using Docker Compose +```makefile +.PHONY: run +run: + @echo "Running Docker container with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." + @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose up +``` + +## Stop target +Stops the running container using Docker Compose +```makefile +.PHONY: stop +stop: + @echo "Stopping Docker container..." + @docker-compose down +``` + +## GPU target +Sets the device type to GPU (CUDA) +```makefile +.PHONY: use-gpu +use-gpu: + $(eval DEVICE_TYPE := cuda) +``` + +## CPU target +Sets the device type to CPU +```makefile +.PHONY: use-cpu +use-cpu: + $(eval DEVICE_TYPE := cpu) +``` + +## Set source docs target +Sets the source documents directory +```makefile +.PHONY: set-source-docs +set-source-docs: + $(eval SOURCE_DOCUMENTS := $(dir)) +``` + +## Help target +Describes how to use the Makefile +```makefile +.PHONY: help +help: + @echo "Makefile for Docker Compose operations" + @echo " make build - Builds the Docker image with the current DEVICE_TYPE and SOURCE_DOCUMENTS" + @echo " make run - Runs the Docker container with the current DEVICE_TYPE and SOURCE_DOCUMENTS" + @echo " make stop - Stops the running Docker container" + @echo " make use-gpu - Sets the DEVICE_TYPE to cuda (GPU)" + @echo " make use-cpu - Sets the DEVICE_TYPE to cpu" + @echo " make set-source-docs dir= - Sets the SOURCE_DOCUMENTS directory" + @echo " make help - Displays this help" +``` + +To set the source documents directory: +``` +make set-source-docs dir=MyDocuments +``` From 3816056090d2685caedc0394d435d89416ababb8 Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 17:54:29 -0500 Subject: [PATCH 8/9] updating --- .github/workflows/build-loalGPT.yml | 28 ------- docs/docker-compose.md | 124 +++++++++++----------------- run_inject.sh | 4 - 3 files changed, 50 insertions(+), 106 deletions(-) delete mode 100644 .github/workflows/build-loalGPT.yml diff --git a/.github/workflows/build-loalGPT.yml b/.github/workflows/build-loalGPT.yml deleted file mode 100644 index e28a2c67..00000000 --- a/.github/workflows/build-loalGPT.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Docker Compose Actions - -on: [push, pull_request] - -jobs: - build-and-run: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Build Docker Images - run: | - docker-compose build - - - name: Run Docker Containers - run: | - docker-compose up -d - - # Add any additional steps like testing, if necessary - - - name: Shutdown - run: | - docker-compose down diff --git a/docs/docker-compose.md b/docs/docker-compose.md index 0fb7bca7..37692c1b 100644 --- a/docs/docker-compose.md +++ b/docs/docker-compose.md @@ -1,88 +1,64 @@ -Here is the Markdown documentation for the Makefile: +# Docker Compose file -# Makefile for Docker Compose operations +This Docker Compose file defines two services: -## Default values for environment variables -```makefile -DEVICE_TYPE := cpu -SOURCE_DOCUMENTS := SOURCE_DOCUMENTS -``` -Replace `SOURCE_DOCUMENTS` with your default source documents directory +## localgpt service -## Default target -Executed when no arguments are given to make. -```makefile -.PHONY: all -all: build -``` +This service builds the localgpt image and runs the localGPT API server. -## Build target -Builds the Docker image using Docker Compose -```makefile -.PHONY: build -build: - @echo "Building Docker image with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." - @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose build +```yaml +services: + localgpt: + build: + context: . + dockerfile: Dockerfile.api + image: localgpt + environment: + - device_type=${DEVICE_TYPE} + - source_documents=${SOURCE_DOCUMENTS} + volumes: + - "$HOME/.cache:/root/.cache" + - "$HOME/${SOURCE_DOCUMENTS}:/SOURCE_DOCUMENTS" + command: python run_localGPT_API.py --port 8080 --host 0.0.0.0 + networks: + - localgpt-network ``` -## Run target -Runs the Docker container using Docker Compose -```makefile -.PHONY: run -run: - @echo "Running Docker container with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." - @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose up -``` +- Builds Dockerfile.api +- Sets device_type and source_documents environment variables +- Mounts host cache and source documents +- Runs the API server on port 8080 -## Stop target -Stops the running container using Docker Compose -```makefile -.PHONY: stop -stop: - @echo "Stopping Docker container..." - @docker-compose down -``` +## localgpt-ui service -## GPU target -Sets the device type to GPU (CUDA) -```makefile -.PHONY: use-gpu -use-gpu: - $(eval DEVICE_TYPE := cuda) -``` +This service runs the localGPT UI frontend. -## CPU target -Sets the device type to CPU -```makefile -.PHONY: use-cpu -use-cpu: - $(eval DEVICE_TYPE := cpu) +```yaml + localgpt-ui: + build: + context: localGPTUI/ + dockerfile: Dockerfile + ports: + - "5111:5111" + environment: + API_HOST: http://localgpt:8080/api + depends_on: + - localgpt + networks: + - localgpt-network ``` -## Set source docs target -Sets the source documents directory -```makefile -.PHONY: set-source-docs -set-source-docs: - $(eval SOURCE_DOCUMENTS := $(dir)) -``` +- Builds the localGPTUI Dockerfile +- Exposes port 5111 +- Sets API_HOST env var pointing to localgpt API +- Depends on localgpt service -## Help target -Describes how to use the Makefile -```makefile -.PHONY: help -help: - @echo "Makefile for Docker Compose operations" - @echo " make build - Builds the Docker image with the current DEVICE_TYPE and SOURCE_DOCUMENTS" - @echo " make run - Runs the Docker container with the current DEVICE_TYPE and SOURCE_DOCUMENTS" - @echo " make stop - Stops the running Docker container" - @echo " make use-gpu - Sets the DEVICE_TYPE to cuda (GPU)" - @echo " make use-cpu - Sets the DEVICE_TYPE to cpu" - @echo " make set-source-docs dir= - Sets the SOURCE_DOCUMENTS directory" - @echo " make help - Displays this help" -``` +## Network -To set the source documents directory: -``` -make set-source-docs dir=MyDocuments +```yaml +networks: + localgpt-network: + driver: bridge ``` + +- Single network for communication between containers diff --git a/run_inject.sh b/run_inject.sh index fb6bf170..ebdb391e 100755 --- a/run_inject.sh +++ b/run_inject.sh @@ -51,10 +51,6 @@ copy_pdfs() { done } -# Uncomment the function you need: -# download_pdf -# copy_pdf - # Run python script with device type run_ingest() { echo "Running ingest.py with device type $DEVICE_TYPE..." From 6261ae439d05e9733bdd564f6e81c4d6094061fd Mon Sep 17 00:00:00 2001 From: Tosin Akinosho Date: Tue, 9 Jan 2024 17:54:49 -0500 Subject: [PATCH 9/9] updating --- docs/docker-compose-makefile.md | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 docs/docker-compose-makefile.md diff --git a/docs/docker-compose-makefile.md b/docs/docker-compose-makefile.md new file mode 100644 index 00000000..0fb7bca7 --- /dev/null +++ b/docs/docker-compose-makefile.md @@ -0,0 +1,88 @@ +Here is the Markdown documentation for the Makefile: + +# Makefile for Docker Compose operations + +## Default values for environment variables +```makefile +DEVICE_TYPE := cpu +SOURCE_DOCUMENTS := SOURCE_DOCUMENTS +``` +Replace `SOURCE_DOCUMENTS` with your default source documents directory + +## Default target +Executed when no arguments are given to make. +```makefile +.PHONY: all +all: build +``` + +## Build target +Builds the Docker image using Docker Compose +```makefile +.PHONY: build +build: + @echo "Building Docker image with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." + @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose build +``` + +## Run target +Runs the Docker container using Docker Compose +```makefile +.PHONY: run +run: + @echo "Running Docker container with DEVICE_TYPE=$(DEVICE_TYPE) and SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS)..." + @DEVICE_TYPE=$(DEVICE_TYPE) SOURCE_DOCUMENTS=$(SOURCE_DOCUMENTS) docker-compose up +``` + +## Stop target +Stops the running container using Docker Compose +```makefile +.PHONY: stop +stop: + @echo "Stopping Docker container..." + @docker-compose down +``` + +## GPU target +Sets the device type to GPU (CUDA) +```makefile +.PHONY: use-gpu +use-gpu: + $(eval DEVICE_TYPE := cuda) +``` + +## CPU target +Sets the device type to CPU +```makefile +.PHONY: use-cpu +use-cpu: + $(eval DEVICE_TYPE := cpu) +``` + +## Set source docs target +Sets the source documents directory +```makefile +.PHONY: set-source-docs +set-source-docs: + $(eval SOURCE_DOCUMENTS := $(dir)) +``` + +## Help target +Describes how to use the Makefile +```makefile +.PHONY: help +help: + @echo "Makefile for Docker Compose operations" + @echo " make build - Builds the Docker image with the current DEVICE_TYPE and SOURCE_DOCUMENTS" + @echo " make run - Runs the Docker container with the current DEVICE_TYPE and SOURCE_DOCUMENTS" + @echo " make stop - Stops the running Docker container" + @echo " make use-gpu - Sets the DEVICE_TYPE to cuda (GPU)" + @echo " make use-cpu - Sets the DEVICE_TYPE to cpu" + @echo " make set-source-docs dir= - Sets the SOURCE_DOCUMENTS directory" + @echo " make help - Displays this help" +``` + +To set the source documents directory: +``` +make set-source-docs dir=MyDocuments +```