Skip to content

Commit

Permalink
Spin Model Server in chatbot recipe
Browse files Browse the repository at this point in the history
Signed-off-by: Liora Milbaum <[email protected]>
  • Loading branch information
lmilbaum committed Mar 31, 2024
1 parent 36c6389 commit 6fddae3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 13 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ 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
Expand Down Expand Up @@ -49,6 +43,8 @@ jobs:

- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.11'

- name: Install python dependencies
working-directory: ./recipes/natural_language_processing/chatbot
Expand All @@ -57,3 +53,10 @@ jobs:
- name: Run tests
working-directory: ./recipes/natural_language_processing/chatbot
run: make test

- name: Upload logs
uses: actions/[email protected]
if: always()
with:
name: test-logs
path: /tmp/driver.log
6 changes: 0 additions & 6 deletions .github/workflows/model_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ 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
Expand Down
9 changes: 8 additions & 1 deletion recipes/natural_language_processing/chatbot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ quadlet:

.PHONY: install
install:
wget -qO- https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz | tar xvz
sudo apt update
sudo apt upgrade
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
# wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
# unzip chromedriver_linux64.zip
pip install -r tests/requirements-test.txt

.PHONY: run
Expand All @@ -37,4 +44,4 @@ run:

.PHONY: test
test:
pytest --log-cli-level NOTSET
python3 -m pytest -vvv --driver=Chrome --driver-path=./chromedriver tests
48 changes: 48 additions & 0 deletions recipes/natural_language_processing/chatbot/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
import pytest_container
import os
import pytest
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager


MS = pytest_container.Container(
url=f"containers-storage:{os.environ['REGISTRY']}/model_servers",
volume_mounts=[
pytest_container.container.BindMount(
container_path="/locallm/models",
host_path="./",
flags=["ro"]
)
],
extra_environment_variables={
"MODEL_PATH": "models/mistral-7b-instruct-v0.1.Q4_K_M.gguf",
"HOST": "0.0.0.0",
"PORT": "8001"
},
forwarded_ports=[
pytest_container.PortForwarding(
container_port=8001,
host_port=8001
)
],
extra_launch_args=["--net=host"]
)

CB = pytest_container.Container(
url=f"containers-storage:{os.environ['REGISTRY']}/{os.environ['IMAGE_NAME']}",
extra_environment_variables={
Expand All @@ -21,3 +47,25 @@ def pytest_generate_tests(metafunc):

def pytest_addoption(parser):
pytest_container.add_logging_level_options(parser)

@pytest.fixture
def firefox_options(firefox_options):
firefox_options.headless = True
firefox_options.set_preference("webdriver.log.file", "/tmp/driver.log")
return firefox_options

@pytest.fixture
def custom_selenium(selenium, firefox_options):
selenium.webdriver = webdriver.Firefox(firefox_options=firefox_options)
yield selenium
selenium.webdriver.quit()

@pytest.fixture
def chrome_options(chrome_options):
chrome_options.add_argument("--headless")
return chrome_options


@pytest.fixture(scope="session", autouse=True)
def install_chromedriver(selenium):
selenium.webdriver = webdriver.Chrome(ChromeDriverManager().install())
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ def test_etc_os_release_present(auto_container: pytest_container.container.Conta
@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()

def test_title(auto_container: pytest_container.container.ContainerData, selenium):
selenium.get(f"http://localhost:{auto_container.forwarded_ports[0].host_port}")
assert selenium.title == "chatbot"

3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pip==24.0
pytest-container==0.4.0
pytest-selenium==4.1.0
pytest-testinfra==10.1.0
pytest==8.1.1
requests==2.31.0
selenium==4.19.0
tenacity==8.2.3
webdrivermanager==4.0.1

0 comments on commit 6fddae3

Please sign in to comment.