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

fixing chatbot tests, chatbot makefile and common makefile #203

Merged
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions recipes/common/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -75,17 +79,30 @@ 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); \
mv chromedriver $(CHROMEDRIVER_INSTALLATION_PATH); \
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
Expand All @@ -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;
23 changes: 15 additions & 8 deletions recipes/natural_language_processing/chatbot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Original file line number Diff line number Diff line change
@@ -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"
},
Expand All @@ -22,7 +36,7 @@
host_port=8001
)
],
extra_launch_args=["--net=host"]
extra_launch_args=["--network=host"]
)

CB = pytest_container.Container(
Expand Down