From ff7cde098b028fe43ee27ec4578645dffa7dd01f Mon Sep 17 00:00:00 2001 From: Liora Milbaum Date: Thu, 28 Mar 2024 22:46:22 +0200 Subject: [PATCH] chatbot tests Signed-off-by: Liora Milbaum --- .github/workflows/chatbot.yaml | 6 +++++ .github/workflows/model_servers.yaml | 8 ++++++- model_servers/llamacpp_python/Makefile | 4 ++-- .../llamacpp_python/tests/conftest.py | 2 +- .../chatbot/Makefile | 2 +- .../chatbot/tests/__init__.py | 0 .../chatbot/tests/conftest.py | 23 +++++++++++++++++++ .../chatbot/tests/test_alive.py | 14 +++++++++-- 8 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 recipes/natural_language_processing/chatbot/tests/__init__.py create mode 100644 recipes/natural_language_processing/chatbot/tests/conftest.py diff --git a/.github/workflows/chatbot.yaml b/.github/workflows/chatbot.yaml index 8a2865b3..23ed2a47 100644 --- a/.github/workflows/chatbot.yaml +++ b/.github/workflows/chatbot.yaml @@ -4,9 +4,15 @@ on: pull_request: branches: - main + paths: + - ./recipes/natural_language_processing/chatbot/** + - .github/workflows/chatbot.yaml push: branches: - main + paths: + - ./recipes/natural_language_processing/chatbot/** + - .github/workflows/chatbot.yaml env: REGISTRY: ghcr.io diff --git a/.github/workflows/model_servers.yaml b/.github/workflows/model_servers.yaml index d8603bdd..5968a8c7 100644 --- a/.github/workflows/model_servers.yaml +++ b/.github/workflows/model_servers.yaml @@ -4,9 +4,15 @@ on: pull_request: branches: - main + paths: + - ./model_servers/llamacpp_python/** + - .github/workflows/model_servers.yaml push: branches: - main + paths: + - ./model_servers/llamacpp_python/** + - .github/workflows/model_servers.yaml env: REGISTRY: ghcr.io @@ -43,7 +49,7 @@ jobs: - name: Download model working-directory: ./model_servers/llamacpp_python/ - run: make models/llama-2-7b-chat.Q5_K_S.gguf + run: make llama-2-7b-chat.Q5_K_S.gguf - name: Set up Python uses: actions/setup-python@v5.0.0 diff --git a/model_servers/llamacpp_python/Makefile b/model_servers/llamacpp_python/Makefile index 76748bb8..0e51b103 100644 --- a/model_servers/llamacpp_python/Makefile +++ b/model_servers/llamacpp_python/Makefile @@ -2,7 +2,7 @@ build: podman build -t ghcr.io/ai-lab-recipes/model_servers . -models/llama-2-7b-chat.Q5_K_S.gguf: +llama-2-7b-chat.Q5_K_S.gguf: curl -s -S -L -f https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf -z $@ -o $@.tmp && mv -f $@.tmp $@ 2>/dev/null || rm -f $@.tmp $@ .PHONY: install @@ -15,4 +15,4 @@ run: .PHONY: test test: - pytest --collect-only tests --log-cli-level NOTSET + pytest --log-cli-level NOTSET diff --git a/model_servers/llamacpp_python/tests/conftest.py b/model_servers/llamacpp_python/tests/conftest.py index 96deb7dd..a9af975b 100644 --- a/model_servers/llamacpp_python/tests/conftest.py +++ b/model_servers/llamacpp_python/tests/conftest.py @@ -7,7 +7,7 @@ volume_mounts=[ pytest_container.container.BindMount( container_path="/locallm/models", - host_path="./models", + host_path="./", flags=["ro"] ) ], diff --git a/recipes/natural_language_processing/chatbot/Makefile b/recipes/natural_language_processing/chatbot/Makefile index cee4949e..f6123eb3 100644 --- a/recipes/natural_language_processing/chatbot/Makefile +++ b/recipes/natural_language_processing/chatbot/Makefile @@ -12,4 +12,4 @@ run: .PHONY: test test: - pytest --collect-only tests --log-cli-level NOTSET + pytest --log-cli-level NOTSET diff --git a/recipes/natural_language_processing/chatbot/tests/__init__.py b/recipes/natural_language_processing/chatbot/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/recipes/natural_language_processing/chatbot/tests/conftest.py b/recipes/natural_language_processing/chatbot/tests/conftest.py new file mode 100644 index 00000000..6242ebbe --- /dev/null +++ b/recipes/natural_language_processing/chatbot/tests/conftest.py @@ -0,0 +1,23 @@ +import pytest_container +import os + + +CB = pytest_container.Container( + url=f"containers-storage:{os.environ['REGISTRY']}/{os.environ['IMAGE_NAME']}", + extra_environment_variables={ + "MODEL_SERVICE_ENDPOINT": "http://10.88.0.1:8001/v1" + }, + forwarded_ports=[ + pytest_container.PortForwarding( + container_port=8501, + host_port=8501 + ) + ], + extra_launch_args=["--net=host"] + ) + +def pytest_generate_tests(metafunc): + pytest_container.auto_container_parametrize(metafunc) + +def pytest_addoption(parser): + pytest_container.add_logging_level_options(parser) diff --git a/recipes/natural_language_processing/chatbot/tests/test_alive.py b/recipes/natural_language_processing/chatbot/tests/test_alive.py index ace0d424..a9a7e52b 100644 --- a/recipes/natural_language_processing/chatbot/tests/test_alive.py +++ b/recipes/natural_language_processing/chatbot/tests/test_alive.py @@ -1,2 +1,12 @@ -def test_placeholder(): - assert 1 == 1 +import pytest_container +from .conftest import CB +import tenacity + +CONTAINER_IMAGES = [CB] + +def test_etc_os_release_present(auto_container: pytest_container.container.ContainerData): + assert auto_container.connection.file("/etc/os-release").exists + +@tenacity.retry(stop=tenacity.stop_after_attempt(5), wait=tenacity.wait_exponential()) +def test_alive(auto_container: pytest_container.container.ContainerData, host): + host.run_expect([0],f"curl http://localhost:{auto_container.forwarded_ports[0].host_port}",).stdout.strip()