CoolFace
Apppublic

jaothan/DockerGenAI_Streamlit

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
pull_model.Dockerfile46 linesDownload Raw Back to root
1#syntax = docker/dockerfile:1.4
2
3FROM ollama/ollama:latest AS ollama
4FROM babashka/babashka:latest
5
6# just using as a client - never as a server
7COPY --from=ollama /bin/ollama ./bin/ollama
8
9COPY <<EOF pull_model.clj
10(ns pull-model
11  (:require [babashka.process :as process]
12            [clojure.core.async :as async]))
13
14(try
15  (let [llm (get (System/getenv) "LLM")
16        url (get (System/getenv) "OLLAMA_BASE_URL")]
17    (println (format "pulling ollama model %s using %s" llm url))
18    (if (and llm 
19         url 
20         (not (#{"gpt-4" "gpt-3.5" "claudev2" "gpt-4o" "gpt-4-turbo"} llm))
21         (not (some #(.startsWith llm %) ["ai21.jamba-instruct-v1:0"
22                                          "amazon.titan"
23                                          "anthropic.claude"
24                                          "cohere.command"
25                                          "meta.llama"
26                                          "mistral.mi"])))
27
28      ;; ----------------------------------------------------------------------
29      ;; just call `ollama pull` here - create OLLAMA_HOST from OLLAMA_BASE_URL
30      ;; ----------------------------------------------------------------------
31      ;; TODO - this still doesn't show progress properly when run from docker compose
32
33      (let [done (async/chan)]
34        (async/go-loop [n 0]
35          (let [[v _] (async/alts! [done (async/timeout 5000)])]
36            (if (= :stop v) :stopped (do (println (format "... pulling model (%ss) - will take several minutes" (* n 10))) (recur (inc n))))))
37        (process/shell {:env {"OLLAMA_HOST" url "HOME" (System/getProperty "user.home")} :out :inherit :err :inherit} (format "bash -c './bin/ollama show %s --modelfile > /dev/null || ./bin/ollama pull %s'" llm llm))
38        (async/>!! done :stop))
39
40      (println "OLLAMA model only pulled if both LLM and OLLAMA_BASE_URL are set and the LLM model is not gpt")))
41  (catch Throwable _ (System/exit 1)))
42EOF
43
44ENTRYPOINT ["bb", "-f", "pull_model.clj"]
45
46