From 140e6de0c409a262387b96ae1e7b73950be0be51 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 2 Dec 2024 19:36:40 +0100 Subject: [PATCH 1/4] Consistent Pytest fixture usage in tests Signed-off-by: Pavel Tisnovsky --- tests/benchmarks/test_redactor.py | 2 +- tests/unit/app/endpoints/test_feedback.py | 2 +- tests/unit/extra_certs/test_extra_certs.py | 2 +- tests/unit/llms/providers/test_azure_openai.py | 2 +- tests/unit/llms/providers/test_rhelai_vllm.py | 2 +- tests/unit/llms/providers/test_rhoai_vllm.py | 2 +- tests/unit/query_helpers/test_attachment_appender.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/benchmarks/test_redactor.py b/tests/benchmarks/test_redactor.py index a4a4b3b8..536f5cd3 100644 --- a/tests/benchmarks/test_redactor.py +++ b/tests/benchmarks/test_redactor.py @@ -10,7 +10,7 @@ from ols.utils.redactor import Redactor, RegexFilter -@pytest.fixture() +@pytest.fixture def config(): """Load configuration used for benchmarks.""" config = AppConfig() diff --git a/tests/unit/app/endpoints/test_feedback.py b/tests/unit/app/endpoints/test_feedback.py index da9b6067..a7a8a81b 100644 --- a/tests/unit/app/endpoints/test_feedback.py +++ b/tests/unit/app/endpoints/test_feedback.py @@ -11,7 +11,7 @@ from ols.app.models.config import UserDataCollection -@pytest.fixture() +@pytest.fixture def feedback_location(tmpdir): """Fixture sets feedback location to tmpdir and return the path.""" full_path = (tmpdir / "feedback").strpath diff --git a/tests/unit/extra_certs/test_extra_certs.py b/tests/unit/extra_certs/test_extra_certs.py index d6f4acba..3d9f4d83 100644 --- a/tests/unit/extra_certs/test_extra_certs.py +++ b/tests/unit/extra_certs/test_extra_certs.py @@ -17,7 +17,7 @@ extra_cert_path = "tests/unit/extra_certs/sample_cert_2.crt" -@pytest.fixture() +@pytest.fixture def fake_certifi_store(tmpdir): """Create a fake certifi store.""" cert_store_path = tmpdir / "cacerts.crt" diff --git a/tests/unit/llms/providers/test_azure_openai.py b/tests/unit/llms/providers/test_azure_openai.py index 96bfcab7..aa05f245 100644 --- a/tests/unit/llms/providers/test_azure_openai.py +++ b/tests/unit/llms/providers/test_azure_openai.py @@ -430,7 +430,7 @@ def get_token(self, url): raise Exception("Error getting token") -@pytest.fixture() +@pytest.fixture def mocked_token_cache(): """Fake token cache.""" diff --git a/tests/unit/llms/providers/test_rhelai_vllm.py b/tests/unit/llms/providers/test_rhelai_vllm.py index 4d6afd87..1c8d8e94 100644 --- a/tests/unit/llms/providers/test_rhelai_vllm.py +++ b/tests/unit/llms/providers/test_rhelai_vllm.py @@ -13,7 +13,7 @@ cert_in_certificates_store_path = "tests/unit/extra_certs/sample_cert_1.crt" -@pytest.fixture() +@pytest.fixture def fake_certifi_store(tmpdir): """Create a fake certifi store.""" cert_store_path = os.path.join( diff --git a/tests/unit/llms/providers/test_rhoai_vllm.py b/tests/unit/llms/providers/test_rhoai_vllm.py index ae6ecbf1..2a63a599 100644 --- a/tests/unit/llms/providers/test_rhoai_vllm.py +++ b/tests/unit/llms/providers/test_rhoai_vllm.py @@ -13,7 +13,7 @@ cert_in_certificates_store_path = "tests/unit/extra_certs/sample_cert_1.crt" -@pytest.fixture() +@pytest.fixture def fake_certifi_store(tmpdir): """Create a fake certifi store.""" cert_store_path = os.path.join( diff --git a/tests/unit/query_helpers/test_attachment_appender.py b/tests/unit/query_helpers/test_attachment_appender.py index 9f5ffe80..911545af 100644 --- a/tests/unit/query_helpers/test_attachment_appender.py +++ b/tests/unit/query_helpers/test_attachment_appender.py @@ -40,7 +40,7 @@ def yaml_without_name(): """ -@pytest.fixture() +@pytest.fixture def broken_yaml(): """Broken YAML file for testing.""" return """ From 288db42a38ede67bcf665204d618f4391a53b12e Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 2 Dec 2024 19:09:35 +0100 Subject: [PATCH 2/4] OLS-1262: use CVE-free virtualenv Signed-off-by: Pavel Tisnovsky --- pdm.lock | 10 +++++----- pyproject.toml | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pdm.lock b/pdm.lock index f41de072..74024964 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.4.2" -content_hash = "sha256:b9fc0555a8757b71893d99349328c636f8be7276a7ec15c5b46bb804345ce1ea" +content_hash = "sha256:c6b6a71ecda3f38f7902a675a491901f478208b62414c3f11c97314403baa034" [[package]] name = "absl-py" @@ -3716,8 +3716,8 @@ files = [ [[package]] name = "virtualenv" -version = "20.26.3" -requires_python = ">=3.7" +version = "20.28.0" +requires_python = ">=3.8" summary = "Virtual Python Environment builder" groups = ["default"] dependencies = [ @@ -3726,8 +3726,8 @@ dependencies = [ "platformdirs<5,>=3.9.1", ] files = [ - {file = "virtualenv-20.26.3-py3-none-any.whl", hash = "sha256:8cc4a31139e796e9a7de2cd5cf2489de1217193116a8fd42328f1bd65f434589"}, - {file = "virtualenv-20.26.3.tar.gz", hash = "sha256:4c43a2a236279d9ea36a0d76f98d84bd6ca94ac4e0f4a3b9d46d05e10fea542a"}, + {file = "virtualenv-20.28.0-py3-none-any.whl", hash = "sha256:23eae1b4516ecd610481eda647f3a7c09aea295055337331bb4e6892ecce47b0"}, + {file = "virtualenv-20.28.0.tar.gz", hash = "sha256:2c9c3262bb8e7b87ea801d715fae4495e6032450c71d2309be9550e7364049aa"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 8ea7a31e..841adcff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,6 +123,7 @@ dependencies = [ "findpython==0.6.2", "filelock==3.16.1", "ffmpy==0.4.0", + "virtualenv==20.28.0", ] requires-python = "==3.11.*" readme = "README.md" From e503147cf3a604d5faafe034fbe7113d33d891a0 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 2 Dec 2024 18:54:45 +0100 Subject: [PATCH 3/4] OLS-1273: proper fakelist LLM import Signed-off-by: Pavel Tisnovsky --- tests/unit/llms/providers/test_fake_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/llms/providers/test_fake_provider.py b/tests/unit/llms/providers/test_fake_provider.py index 910dc840..885aefb1 100644 --- a/tests/unit/llms/providers/test_fake_provider.py +++ b/tests/unit/llms/providers/test_fake_provider.py @@ -1,7 +1,7 @@ """Unit tests for BAM provider.""" import pytest -from langchain.llms.fake import FakeListLLM +from langchain_community.llms import FakeListLLM from ols.app.models.config import ProviderConfig from ols.src.llms.providers.fake_provider import FakeProvider From 7e36327f0b97d1cae64cac1718cbaec5290f5e5f Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 2 Dec 2024 18:53:07 +0100 Subject: [PATCH 4/4] OLS-1272: don't pass params via kwargs Signed-off-by: Pavel Tisnovsky --- ols/src/llms/providers/azure_openai.py | 6 ++---- ols/src/llms/providers/openai.py | 6 ++---- ols/src/llms/providers/rhelai_vllm.py | 6 ++---- ols/src/llms/providers/rhoai_vllm.py | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/ols/src/llms/providers/azure_openai.py b/ols/src/llms/providers/azure_openai.py index f03275c7..5971d4ff 100644 --- a/ols/src/llms/providers/azure_openai.py +++ b/ols/src/llms/providers/azure_openai.py @@ -64,10 +64,8 @@ def default_params(self) -> dict[str, Any]: "api_version": api_version, "deployment_name": deployment_name, "model": self.model, - "model_kwargs": { - "top_p": 0.95, - "frequency_penalty": 1.03, - }, + "top_p": 0.95, + "frequency_penalty": 1.03, "organization": None, "cache": None, "streaming": True, diff --git a/ols/src/llms/providers/openai.py b/ols/src/llms/providers/openai.py index d602be4d..ed11e9ba 100644 --- a/ols/src/llms/providers/openai.py +++ b/ols/src/llms/providers/openai.py @@ -36,10 +36,8 @@ def default_params(self) -> dict[str, Any]: "base_url": self.url, "openai_api_key": self.credentials, "model": self.model, - "model_kwargs": { - "top_p": 0.95, - "frequency_penalty": 1.03, - }, + "top_p": 0.95, + "frequency_penalty": 1.03, "organization": None, "cache": None, "streaming": True, diff --git a/ols/src/llms/providers/rhelai_vllm.py b/ols/src/llms/providers/rhelai_vllm.py index 7d837ed8..38b95166 100644 --- a/ols/src/llms/providers/rhelai_vllm.py +++ b/ols/src/llms/providers/rhelai_vllm.py @@ -37,10 +37,8 @@ def default_params(self) -> dict[str, Any]: "base_url": self.url, "openai_api_key": self.credentials, "model": self.model, - "model_kwargs": { - "top_p": 0.95, - "frequency_penalty": 1.03, - }, + "top_p": 0.95, + "frequency_penalty": 1.03, "organization": None, "cache": None, "streaming": True, diff --git a/ols/src/llms/providers/rhoai_vllm.py b/ols/src/llms/providers/rhoai_vllm.py index 6a02a348..4c70e305 100644 --- a/ols/src/llms/providers/rhoai_vllm.py +++ b/ols/src/llms/providers/rhoai_vllm.py @@ -37,10 +37,8 @@ def default_params(self) -> dict[str, Any]: "base_url": self.url, "openai_api_key": self.credentials, "model": self.model, - "model_kwargs": { - "top_p": 0.95, - "frequency_penalty": 1.03, - }, + "top_p": 0.95, + "frequency_penalty": 1.03, "organization": None, "cache": None, "streaming": True,