From d271c15c3f376c8f71b0ed6205cfbbf7d99ed216 Mon Sep 17 00:00:00 2001 From: greg pereira Date: Tue, 9 Apr 2024 07:19:03 -0700 Subject: [PATCH] fixing chatbot tests, chatbot makefile and common makefile Signed-off-by: greg pereira --- .github/workflows/chatbot.yaml | 4 +++ recipes/common/Makefile.common | 35 +++++++++++++++++-- .../chatbot/Makefile | 23 +++++++----- .../chatbot/tests/functional/conftest.py | 24 ++++++++++--- 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/.github/workflows/chatbot.yaml b/.github/workflows/chatbot.yaml index cce8f1b1..2bc7223a 100644 --- a/.github/workflows/chatbot.yaml +++ b/.github/workflows/chatbot.yaml @@ -58,6 +58,10 @@ jobs: working-directory: ./recipes/natural_language_processing/${{ env.IMAGE_NAME }} run: make install + - name: Download model + working-directory: ./model_servers/llamacpp_python + run: make mistral + - name: Run Functional Tests shell: bash run: make functional-tests diff --git a/recipes/common/Makefile.common b/recipes/common/Makefile.common index abb898d1..61e61ed3 100644 --- a/recipes/common/Makefile.common +++ b/recipes/common/Makefile.common @@ -30,6 +30,7 @@ CHROMEDRIVER_VERSION := 103.0.5060.53 CHROMEDRIVER_MIRROR := https://chromedriver.storage.googleapis.com CHROMEDRIVER_DOWNLOAD_PATH := CHROMEDRIVER_INSTALLATION_PATH ?= +CHROME_DOWNLOAD_PATH ?= OS := $(shell uname -s) ARCH := $(shell uname -m) @@ -40,11 +41,14 @@ ifeq ($(OS),Darwin) # This structure may vary if we upgrade chromedriver, see in else ifeq ($(ARCH),arm64) CHROMEDRIVER_DOWNLOAD_PATH := chromedriver_mac64_m1.zip endif + CHROME_DOWNLOAD_PATH := googlechrome.dmg else ifeq ($(OS),Linux) CHROMEDRIVER_DOWNLOAD_PATH := chromedriver_linux64.zip + CHROME_DOWNLOAD_PATH := google-chrome-stable_current_amd64.deb endif -CHROMEDRIVER_EXISTS ?= $(shell command -v chromedriver) +CHROME_MIRROR := https://www.slimjet.com/chrome/files/$(CHROMEDRIVER_VERSION)/$(CHROME_DOWNLOAD_PATH) + LOCAL_CHROMEDRIVER_EXISTS ?= $(shell command -v $(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver) UNZIP_EXISTS ?= $(shell command -v unzip) @@ -75,7 +79,7 @@ bootc: quadlet .PHONY: install-chromedriver install-chromedriver: - @if [[ -z "$(CHROMEDRIVER_EXISTS)" ]] && [[ -z "$(LOCAL_CHROMEDRIVER_EXISTS)" ]]; then \ + @if [[ -z "$(LOCAL_CHROMEDRIVER_EXISTS)" ]]; then \ if [[ -n "$(UNZIP_EXISTS)" ]]; then \ curl -sLO $(CHROMEDRIVER_MIRROR)/$(CHROMEDRIVER_VERSION)/$(CHROMEDRIVER_DOWNLOAD_PATH); \ unzip $(CHROMEDRIVER_DOWNLOAD_PATH); \ @@ -83,9 +87,22 @@ install-chromedriver: rm ./$(CHROMEDRIVER_DOWNLOAD_PATH); \ elif [[ -z "$(UNZIP_EXISTS)" ]]; then \ echo "Install make target requires unizp binary."; \ + exit 1; \ fi; \ fi; +.PHONY: install-chrome +install-chrome: + curl -sLO $(CHROME_MIRROR) + @if [[ "$(OS)" == "Linux" ]]; then \ + sudo dpkg -i $(CHROME_DOWNLOAD_PATH); \ + elif [[ "$(OS)" == "Darwin" ]]; then \ + open $(CHROME_DOWNLOAD_PATH); \ + rm $(CHROME_DOWNLOAD_PATH); \ + mv /Volumes/Google\ Chrome/Google\ Chrome.app $(CHROMEDRIVER_INSTALLATION_PATH); \ + diskutil unmount /Volumes/Google\ Chrome; \ + fi; + .PHONY: quadlet quadlet: # Modify quadlet files to match the server, model and app image @@ -110,5 +127,17 @@ run: .PHONY: clean clean: - rm -rf build + -rm -rf build -rm -rf tests/__pycache__ + -rm ./$(MODEL_NAME) &> /dev/null + +.PHONY: check-model-in-path +check-model-in-path: + @if [ ! -f "../../../models/$(MODEL_NAME)" ]; then \ + echo "Model file -- $(MODEL_NAME) -- not present in the models directory."; \ + exit 1; \ + else \ + if [ ! -f "./$(MODEL_NAME)" ]; then \ + ln -s ../../../models/$(MODEL_NAME) ./$(MODEL_NAME); \ + fi; \ + fi; diff --git a/recipes/natural_language_processing/chatbot/Makefile b/recipes/natural_language_processing/chatbot/Makefile index 0fe43f4f..7ab842df 100644 --- a/recipes/natural_language_processing/chatbot/Makefile +++ b/recipes/natural_language_processing/chatbot/Makefile @@ -5,33 +5,40 @@ PORT ?= 8501 include ../../common/Makefile.common CHROMEDRIVER_INSTALLATION_PATH := $(shell realpath ../..) +RELATIVE_MODELS_PATH := ../../../models + +MISTRAL_MODEL_NAME := mistral-7b-instruct-v0.1.Q4_K_M.gguf +MISTRAL_MODEL_URL := https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf + +MODEL_NAME ?= $(MISTRAL_MODEL_NAME) + +.PHONY: download-model-mistral +download-model-mistral: + curl -H "Cache-Control: no-cache" -s -S -L -f $(MISTRAL_MODEL_URL) -z $(RELATIVE_MODELS_PATH)/$(MISTRAL_MODEL_NAME) -o $(RELATIVE_MODELS_PATH)/$(MISTRAL_MODEL_NAME).tmp && mv -f $(RELATIVE_MODELS_PATH)/$(MISTRAL_MODEL_NAME).tmp $(RELATIVE_MODELS_PATH)/$(MISTRAL_MODEL_NAME) 2>/dev/null || rm -f $(RELATIVE_MODELS_PATH)/$(MISTRAL_MODEL_NAME).tmp $(RELATIVE_MODELS_PATH)/$(MISTRAL_MODEL_NAME) .PHONY: install install: $(MAKE) install-chromedriver CHROMEDRIVER_INSTALLATION_PATH=${CHROMEDRIVER_INSTALLATION_PATH} + $(MAKE) install-chrome CHROMEDRIVER_INSTALLATION_PATH=${CHROMEDRIVER_INSTALLATION_PATH} pip install -q -r tests/requirements.txt .PHONY: functional-tests functional-tests: + $(MAKE) MODEL_NAME=$(MODEL_NAME) check-model-in-path @if [[ -n "$(LOCAL_CHROMEDRIVER_EXISTS)" ]]; then \ - IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver tests/functional; \ - elif [[ -n "$(CHROMEDRIVER_EXISTS)" ]] && [[ -z "$(LOCAL_CHROMEDRIVER_EXISTS)" ]]; then \ - IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_EXISTS) tests/functional; \ + IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} MODEL_NAME=${MODEL_NAME} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver tests/functional; \ else \ echo "fetching chromedriver"; \ make install; \ - IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver tests/functional; \ + IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} MODEL_NAME=${MODEL_NAME} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver tests/functional; \ fi; .PHONY: integration-tests integration-tests: @if [[ -n "$(LOCAL_CHROMEDRIVER_EXISTS)" ]]; then \ URL=${URL} IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver tests/integration; \ - elif [[ -n "$(CHROMEDRIVER_EXISTS)" ]] && [[ -z "$(LOCAL_CHROMEDRIVER_EXISTS)" ]]; then \ - URL=${URL} IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_EXISTS) tests/integration; \ else \ echo "fetching chromedriver"; \ make install; \ - URL=${URL} IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_EXISTS) tests/integration + URL=${URL} IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} pytest -vvv --driver=Chrome --driver-path=$(CHROMEDRIVER_INSTALLATION_PATH)/chromedriver tests/integration; \ fi; - diff --git a/recipes/natural_language_processing/chatbot/tests/functional/conftest.py b/recipes/natural_language_processing/chatbot/tests/functional/conftest.py index eb576868..b7e2ff68 100644 --- a/recipes/natural_language_processing/chatbot/tests/functional/conftest.py +++ b/recipes/natural_language_processing/chatbot/tests/functional/conftest.py @@ -1,18 +1,32 @@ import pytest_container import os +import logging + +REGISTRY=os.environ['REGISTRY'] +IMAGE_NAME=os.environ['IMAGE_NAME'] +MODEL_NAME=os.environ['MODEL_NAME'] + +logging.info(""" +Starting pytest with the following ENV vars: + REGISTRY: {REGISTRY} + IMAGE_NAME: {IMAGE_NAME} + MODEL_NAME: {MODEL_NAME} +For: + model_server: whispercpp +""".format(REGISTRY=REGISTRY, IMAGE_NAME=IMAGE_NAME, MODEL_NAME=MODEL_NAME)) MS = pytest_container.Container( - url=f"containers-storage:{os.environ['REGISTRY']}/containers/llamacpp_python", + url=f"containers-storage:{REGISTRY}/{IMAGE_NAME}", volume_mounts=[ pytest_container.container.BindMount( - container_path="/locallm/models", - host_path="./", + container_path=f"/locallm/models/${MODEL_NAME}", + host_path=f"./{MODEL_NAME}", flags=["ro"] ) ], extra_environment_variables={ - "MODEL_PATH": "models/mistral-7b-instruct-v0.1.Q4_K_M.gguf", + "MODEL_PATH": f"/locall/models/{MODEL_NAME}", "HOST": "0.0.0.0", "PORT": "8001" }, @@ -22,7 +36,7 @@ host_port=8001 ) ], - extra_launch_args=["--net=host"] + extra_launch_args=["--network=host"] ) CB = pytest_container.Container(