From 0ed0612eaa8671b2b2b67c65039ebb1ede58a882 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 26 May 2025 10:50:48 +0200 Subject: [PATCH 1/3] Service configuration class --- src/models/config.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/models/config.py b/src/models/config.py index e82ebd81..b8dc15db 100644 --- a/src/models/config.py +++ b/src/models/config.py @@ -4,6 +4,27 @@ from typing_extensions import Self +class ServiceConfiguration(BaseModel): + """Service configuration.""" + + host: str = "localhost" + port: int = 8080 + auth_enabled: bool = False + workers: int = 1 + color_log: bool = True + access_log: bool = True + + @model_validator(mode="after") + def check_service_configuration(self) -> Self: + if self.port <= 0: + raise ValueError("Port value should not be negative") + if self.port > 65535: + raise ValueError("Port value should be less than 65536") + if self.workers < 1: + raise ValueError("Workers must be set to at least 1") + return self + + class LLamaStackConfiguration(BaseModel): """Llama stack configuration.""" @@ -37,4 +58,5 @@ class Configuration(BaseModel): """Global service configuration.""" name: str + service: ServiceConfiguration llama_stack: LLamaStackConfiguration From 012edc3b996395e33caeb9ec36d0a131ed8449bf Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 26 May 2025 10:51:08 +0200 Subject: [PATCH 2/3] Updated unit tests accordingly --- tests/unit/models/test_config.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/unit/models/test_config.py b/tests/unit/models/test_config.py index 12f54dfe..cbc814f5 100644 --- a/tests/unit/models/test_config.py +++ b/tests/unit/models/test_config.py @@ -2,7 +2,35 @@ import pytest -from models.config import Configuration, LLamaStackConfiguration +from models.config import Configuration, LLamaStackConfiguration, ServiceConfiguration + + +def test_service_configuration_constructor() -> None: + """Test the ServiceConfiguration constructor.""" + s = ServiceConfiguration() + assert s is not None + + assert s.host == "localhost" + assert s.port == 8080 + assert s.auth_enabled is False + assert s.workers == 1 + assert s.color_log is True + assert s.access_log is True + + +def test_service_configuration_port_value() -> None: + """Test the ServiceConfiguration port value validation.""" + with pytest.raises(ValueError, match="Port value should not be negative"): + ServiceConfiguration(port=-1) + + with pytest.raises(ValueError, match="Port value should be less than 65536"): + ServiceConfiguration(port=100000) + + +def test_service_configuration_workers_value() -> None: + """Test the ServiceConfiguration workers value validation.""" + with pytest.raises(ValueError, match="Workers must be set to at least 1"): + ServiceConfiguration(workers=-1) def test_llama_stack_configuration_constructor() -> None: From 9629de2516c0afecaf556637251c21ed30b3a73d Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 26 May 2025 10:51:17 +0200 Subject: [PATCH 3/3] New example configuration --- lightspeed-stack.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lightspeed-stack.yaml b/lightspeed-stack.yaml index ddbb8d1c..ea0729c4 100644 --- a/lightspeed-stack.yaml +++ b/lightspeed-stack.yaml @@ -1,4 +1,11 @@ name: foo bar baz +service: + host: localhost + port: 8080 + auth_enabled: false + workers: 1 + color_log: true + access_log: true llama_stack: # Uses a remote llama-stack service # The instance would have already been started with a llama-stack-run.yaml file