Skip to content
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
7 changes: 7 additions & 0 deletions lightspeed-stack.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -37,4 +58,5 @@ class Configuration(BaseModel):
"""Global service configuration."""

name: str
service: ServiceConfiguration
llama_stack: LLamaStackConfiguration
30 changes: 29 additions & 1 deletion tests/unit/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down