Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenAI changes to allow it to run on Debian GNU/Linux unstable #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!pull_model.clj
!*.py
!requirements.txt
!images/*
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -37,6 +38,7 @@ services:

loader:
build:
context: .
dockerfile: loader.Dockerfile
volumes:
- $PWD/embedding_model:/embedding_model
Expand Down Expand Up @@ -74,6 +76,7 @@ services:

bot:
build:
context: .
dockerfile: bot.Dockerfile
volumes:
- $PWD/embedding_model:/embedding_model
Expand Down Expand Up @@ -110,6 +113,7 @@ services:

pdf_bot:
build:
context: .
dockerfile: pdf_bot.Dockerfile
environment:
- NEO4J_URI=${NEO4J_URI-neo4j://database:7687}
Expand Down Expand Up @@ -144,6 +148,7 @@ services:

api:
build:
context: .
dockerfile: api.Dockerfile
volumes:
- $PWD/embedding_model:/embedding_model
Expand Down Expand Up @@ -178,6 +183,7 @@ services:

front-end:
build:
context: .
dockerfile: front-end.Dockerfile
x-develop:
watch:
Expand Down
27 changes: 1 addition & 26 deletions pull_model.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF pull_model.clj
(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)))
EOF
COPY pull_model.clj pull_model.clj

ENTRYPOINT ["bb", "-f", "pull_model.clj"]

24 changes: 24 additions & 0 deletions pull_model.clj
Original file line number Diff line number Diff line change
@@ -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)))
6 changes: 3 additions & 3 deletions start.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't docker-compose deprecated for docker compose ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"docker compose" is the updated version from Docker, yes. However, in the latest version of Debian GNU/Linux and the Unstable branch, it is still a separate command for "docker" and "docker-compose". That is why I suggested, if possible, to create an extra profile, e.g. --profile debianunstable, rather than assume every Linux can use --profile linux. I do not know if this is possible, but it would be nice. As a general rule, "docker compose", with the space is the updated way. I hope this helps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is we should encourage the use of docker compose. But if it is available on Debian Unstable, why not use it ?

Anyway, the changes you made should work even when using docker compose (the context: . is implicit in docker compose, don't know for docker-compose). The only thing I would do differently is creating another start script for the old docker-compose instead of changing the actual one.

I would still be interested in what error you had before, maybe there is another workaround!