From af9cde5d740bb65cba0cf03c6ad5fddddcc5c039 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Fri, 29 Mar 2024 14:10:49 -0400 Subject: [PATCH] Make it easier to substitute image names Signed-off-by: Daniel J Walsh --- models/Containerfile | 2 +- .../chatbot/Makefile | 26 ++++++++++++++++--- .../chatbot/bootc/Containerfile | 14 +++++++--- .../chatbot/quadlet/chatbot.image | 6 ++--- .../chatbot/quadlet/chatbot.kube | 2 +- .../chatbot/quadlet/chatbot.yaml | 10 +++---- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/models/Containerfile b/models/Containerfile index 50f0abec6..fefecb5be 100644 --- a/models/Containerfile +++ b/models/Containerfile @@ -6,4 +6,4 @@ FROM registry.access.redhat.com/ubi9/ubi-micro:9.3-13 ARG MODEL_URL=https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf WORKDIR /model -ADD $MODEL_URL . +ADD $MODEL_URL /model/model.file diff --git a/recipes/natural_language_processing/chatbot/Makefile b/recipes/natural_language_processing/chatbot/Makefile index e9a2312b1..043c09ab6 100644 --- a/recipes/natural_language_processing/chatbot/Makefile +++ b/recipes/natural_language_processing/chatbot/Makefile @@ -1,11 +1,31 @@ +APP=chatbot +MODELIMAGE=quay.io/ai-lab/mistral-7b-instruct:latest +APPIMAGE=quay.io/ai-lab/${APP}:latest +SERVERIMAGE=quay.io/ai-lab/llamacpp-python:latest SSHPUBKEY := $(shell cat ${HOME}/.ssh/id_rsa.pub;) .PHONY: build build: - podman build -f builds/Containerfile -t ghcr.io/ai-lab-recipes/chatbot . + podman build -f builds/Containerfile -t ghcr.io/ai-lab-recipes/${APP} . .PHONY: bootc bootc: - podman build --cap-add SYS_ADMIN --build-arg "SSHPUBKEY=$(SSHPUBKEY)" --build-arg MODEL-IMAGE=${MODEL-IMAGE} -f bootc/Containerfile -t ghcr.io/ai-lab-recipes/chatbot-bootc . + podman build --cap-add SYS_ADMIN --build-arg "SSHPUBKEY=$(SSHPUBKEY)" -f bootc/Containerfile -t ghcr.io/ai-lab-recipes/${APP}-bootc . + +.PHONY: quadlet +quadlet: + # Modify quadlet files to match the server, model and app image + sed -e "s|SERVERIMAGE|${SERVERIMAGE}|" \ + -e "s|APPIMAGE|${APPIMAGE}|g" \ + -e "s|MODELIMAGE|${MODELIMAGE}|g" \ + quadlet/${APP}.image \ + > /tmp/${APP}.image + sed -e "s|SERVERIMAGE|${SERVERIMAGE}|" \ + -e "s|APPIMAGE|${APPIMAGE}|g" \ + -e "s|MODELIMAGE|${MODELIMAGE}|g" \ + quadlet/${APP}.yaml \ + > /tmp/${APP}.yaml + cp quadlet/${APP}.kube /tmp/${APP}.kube + .PHONY: install install: @@ -13,7 +33,7 @@ install: .PHONY: run run: - podman run -it -p 8501:8501 -e MODEL_SERVICE_ENDPOINT=http://10.88.0.1:8001/v1 ghcr.io/ai-lab-recipes/chatbot + podman run -it -p 8501:8501 -e MODEL_SERVICE_ENDPOINT=http://10.88.0.1:8001/v1 ghcr.io/ai-lab-recipes/${APP} .PHONY: test test: diff --git a/recipes/natural_language_processing/chatbot/bootc/Containerfile b/recipes/natural_language_processing/chatbot/bootc/Containerfile index 688c90238..dec56f77a 100644 --- a/recipes/natural_language_processing/chatbot/bootc/Containerfile +++ b/recipes/natural_language_processing/chatbot/bootc/Containerfile @@ -15,9 +15,6 @@ RUN mkdir /usr/etc-system && \ RUN dnf -y update && (dnf install -y vim || true) && dnf clean all -# Add quadlet files to setup system to automatically run AI application on boot -COPY quadlet/chatbot.kube quadlet/chatbot.yaml quadlet/chatbot.image /usr/share/containers/systemd - # pre-pull workload images: # Comment the pull commands to keep bootc image smaller. # The quadlet .image file added above pulls following images on boot if not @@ -27,6 +24,17 @@ ARG MODELIMAGE=quay.io/ai-lab/mistral-7b-instruct:latest ARG APPIMAGE=quay.io/ai-lab/chatbot:latest ARG SERVERIMAGE=quay.io/ai-lab/llamacpp-python:latest +# Add quadlet files to setup system to automatically run AI application on boot +COPY quadlet/chatbot.kube quadlet/chatbot.yaml quadlet/chatbot.image /usr/share/containers/systemd + +# Modify quadlet files to match the server, model and app image +RUN sed -e "s|SERVERIMAGE|${SERVERIMAGE}|" \ + -e "s|APPIMAGE|${APPIMAGE}|g" \ + -e "s|MODELIMAGE|${MODELIMAGE}|g" \ + -i \ + /usr/share/containers/systemd/chatbot.image \ + /usr/share/containers/systemd/chatbot.yaml + RUN podman pull --root /usr/lib/containers/storage ${SERVERIMAGE} RUN podman pull --root /usr/lib/containers/storage ${APPIMAGE} RUN podman pull --root /usr/lib/containers/storage ${MODELIMAGE} diff --git a/recipes/natural_language_processing/chatbot/quadlet/chatbot.image b/recipes/natural_language_processing/chatbot/quadlet/chatbot.image index f871c909a..6c993f805 100644 --- a/recipes/natural_language_processing/chatbot/quadlet/chatbot.image +++ b/recipes/natural_language_processing/chatbot/quadlet/chatbot.image @@ -2,6 +2,6 @@ WantedBy=chatbot.service [Image] -Image=quay.io/ai-lab/llamacpp-python:latest -Image=quay.io/ai-lab/mistral-7b-instruct:latest -Image=quay.io/ai-lab/chatbot:latest +Image=APPIMAGE +Image=MODELIMAGE +Image=SERVERIMAGE diff --git a/recipes/natural_language_processing/chatbot/quadlet/chatbot.kube b/recipes/natural_language_processing/chatbot/quadlet/chatbot.kube index 66919229e..45069505f 100644 --- a/recipes/natural_language_processing/chatbot/quadlet/chatbot.kube +++ b/recipes/natural_language_processing/chatbot/quadlet/chatbot.kube @@ -1,5 +1,5 @@ [Unit] -Description=Python script to run against downloaded LLM +Description=Kubernetes YAML file used to do chatbot inferencing Documentation=man:podman-generate-systemd(1) Wants=network-online.target After=network-online.target diff --git a/recipes/natural_language_processing/chatbot/quadlet/chatbot.yaml b/recipes/natural_language_processing/chatbot/quadlet/chatbot.yaml index c7b479064..b488fa7e3 100644 --- a/recipes/natural_language_processing/chatbot/quadlet/chatbot.yaml +++ b/recipes/natural_language_processing/chatbot/quadlet/chatbot.yaml @@ -7,8 +7,8 @@ metadata: spec: initContainers: - name: model-file - image: quay.io/ai-lab/mistral-7b-instruct:latest - command: ['/usr/bin/install', "/model/mistral-7b-instruct-v0.1.Q4_K_M.gguf", "/shared/"] + image: MODELIMAGE + command: ['/usr/bin/install', "/model/model.file", "/shared/"] volumeMounts: - name: model-file mountPath: /shared @@ -16,7 +16,7 @@ spec: - env: - name: MODEL_SERVICE_ENDPOINT value: http://0.0.0.0:8001/v1 - image: quay.io/ai-lab/chatbot:latest + image: APPIMAGE name: chatbot-inference ports: - containerPort: 8501 @@ -29,8 +29,8 @@ spec: - name: PORT value: 8001 - name: MODEL_PATH - value: /model/mistral-7b-instruct-v0.1.Q4_K_M.gguf - image: quay.io/ai-lab/llamacpp-python:latest + value: /model/model.file + image: SERVERIMAGE name: chatbot-model-service ports: - containerPort: 8001