From 98cb6c33f40d2d51e9a2b05dcb81e3433f453a65 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 | 15 +++++++++++- .../chatbot/Makefile | 12 ++++++++-- .../chatbot/tests/functional/conftest.py | 24 +++++++++++++++---- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/workflows/chatbot.yaml b/.github/workflows/chatbot.yaml index cce8f1b14..22b4c3e0f 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/${{ matrix.image_name }}/ + run: make download-model-mistral + - name: Run Functional Tests shell: bash run: make functional-tests diff --git a/recipes/common/Makefile.common b/recipes/common/Makefile.common index abb898d1e..1a8ee2d54 100644 --- a/recipes/common/Makefile.common +++ b/recipes/common/Makefile.common @@ -110,5 +110,18 @@ 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; + exit 0 diff --git a/recipes/natural_language_processing/chatbot/Makefile b/recipes/natural_language_processing/chatbot/Makefile index 0fe43f4f3..e6c3f30d3 100644 --- a/recipes/natural_language_processing/chatbot/Makefile +++ b/recipes/natural_language_processing/chatbot/Makefile @@ -5,6 +5,14 @@ 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 + +.PHONY: download-model-mistral +download-model-llama: + 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: @@ -13,6 +21,7 @@ install: .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 \ @@ -32,6 +41,5 @@ integration-tests: 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_EXISTS) 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 eb576868f..b7e2ff687 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(