diff --git a/server/config.py b/server/config.py index 781b59d..764fed6 100644 --- a/server/config.py +++ b/server/config.py @@ -25,4 +25,4 @@ def get_llama_config() -> dict: except httpx.HTTPError: return {} - return LlamaConfig(**config.get("llama", {})).model_dump(exclude_none=True) + return LlamaConfig(**(config.get("llama") or {})).model_dump(exclude_none=True) diff --git a/server/tests/test_config.py b/server/tests/test_config.py new file mode 100644 index 0000000..0b89c76 --- /dev/null +++ b/server/tests/test_config.py @@ -0,0 +1,31 @@ +from unittest.mock import Mock, patch + +from server.config import get_llama_config + + +def test_get_llama_config_handles_null_llama_config(): + response = Mock() + response.json.return_value = {"llama": None} + + with patch("server.config.httpx.get", return_value=response): + assert get_llama_config() == {} + + +def test_get_llama_config_returns_present_llama_values(): + response = Mock() + response.json.return_value = { + "llama": { + "context_length": 20000, + "gpu_layers": 12, + "offload_kqv": False, + "batch_size": 128, + } + } + + with patch("server.config.httpx.get", return_value=response): + assert get_llama_config() == { + "context_length": 20000, + "gpu_layers": 12, + "offload_kqv": False, + "batch_size": 128, + }