From b5c55190668450dcf5d9b71ac3a2326d05755af1 Mon Sep 17 00:00:00 2001 From: Haakon Meland Eriksen Date: Sun, 15 Oct 2023 19:06:56 +0200 Subject: [PATCH] GenAI changes to allow it to run on Debian GNU/Linux unstable --- .dockerignore | 1 + docker-compose.yml | 6 ++++++ pull_model.Dockerfile | 27 +-------------------------- pull_model.clj | 24 ++++++++++++++++++++++++ start.sh | 6 +++--- 5 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 pull_model.clj diff --git a/.dockerignore b/.dockerignore index 3466d315..5cc15fa4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ * +!pull_model.clj !*.py !requirements.txt !images/* diff --git a/docker-compose.yml b/docker-compose.yml index c1a831f3..cdc91aee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: pull-model: image: genai-stack/pull-model:latest build: + context: . dockerfile: pull_model.Dockerfile environment: - OLLAMA_BASE_URL=${OLLAMA_BASE_URL-http://host.docker.internal:11434} @@ -37,6 +38,7 @@ services: loader: build: + context: . dockerfile: loader.Dockerfile volumes: - $PWD/embedding_model:/embedding_model @@ -74,6 +76,7 @@ services: bot: build: + context: . dockerfile: bot.Dockerfile volumes: - $PWD/embedding_model:/embedding_model @@ -110,6 +113,7 @@ services: pdf_bot: build: + context: . dockerfile: pdf_bot.Dockerfile environment: - NEO4J_URI=${NEO4J_URI-neo4j://database:7687} @@ -144,6 +148,7 @@ services: api: build: + context: . dockerfile: api.Dockerfile volumes: - $PWD/embedding_model:/embedding_model @@ -178,6 +183,7 @@ services: front-end: build: + context: . dockerfile: front-end.Dockerfile x-develop: watch: diff --git a/pull_model.Dockerfile b/pull_model.Dockerfile index 8cd788ad..1c422594 100644 --- a/pull_model.Dockerfile +++ b/pull_model.Dockerfile @@ -6,32 +6,7 @@ FROM babashka/babashka:latest # just using as a client - never as a server COPY --from=ollama /bin/ollama ./bin/ollama -COPY <!! done :stop)) - - (println "OLLAMA model only pulled if both LLM and OLLAMA_BASE_URL are set and the LLM model is not gpt"))) - (catch Throwable _ (System/exit 1))) -EOF +COPY pull_model.clj pull_model.clj ENTRYPOINT ["bb", "-f", "pull_model.clj"] diff --git a/pull_model.clj b/pull_model.clj new file mode 100644 index 00000000..3464b5be --- /dev/null +++ b/pull_model.clj @@ -0,0 +1,24 @@ +(ns pull-model + (:require [babashka.process :as process] + [clojure.core.async :as async])) + +(try + (let [llm (get (System/getenv) "LLM") + url (get (System/getenv) "OLLAMA_BASE_URL")] + (println (format "pulling ollama model %s using %s" llm url)) + (if (and llm url (not (#{"gpt-4" "gpt-3.5"} llm))) + + ;; ---------------------------------------------------------------------- + ;; just call `ollama pull` here - create OLLAMA_HOST from OLLAMA_BASE_URL + ;; ---------------------------------------------------------------------- + ;; TODO - this still doesn't show progress properly when run from docker compose + + (let [done (async/chan)] + (async/go-loop [n 0] + (let [[v _] (async/alts! [done (async/timeout 5000)])] + (if (= :stop v) :stopped (do (println (format "... pulling model (%ss) - will take several minutes" (* n 10))) (recur (inc n)))))) + (process/shell {:env {"OLLAMA_HOST" url} :out :inherit :err :inherit} (format "./bin/ollama pull %s" llm)) + (async/>!! done :stop)) + + (println "OLLAMA model only pulled if both LLM and OLLAMA_BASE_URL are set and the LLM model is not gpt"))) + (catch Throwable _ (System/exit 1))) diff --git a/start.sh b/start.sh index 0fe8f40d..98085417 100755 --- a/start.sh +++ b/start.sh @@ -1,4 +1,4 @@ -# docker run -d --name neo4j -e NEO4J_AUTH=neo4j/password -p 7687:7687 -p 7474:7474 neo4j:latest -# docker ps -qaf name=neo4j +docker run -d --name neo4j -e NEO4J_AUTH=neo4j/password -p 7687:7687 -p 7474:7474 neo4j:latest +docker ps -qaf name=neo4j -docker compose up --build --force-recreate +docker-compose up --build --force-recreate