From 376a3bf7969d01fc2b4b1d9f991cf5e8426b40cc Mon Sep 17 00:00:00 2001 From: PrimalPimmy Date: Sat, 20 Jun 2026 01:15:49 +0530 Subject: [PATCH] hotfix for when config is not available then dont just crash, use defaults Signed-off-by: PrimalPimmy --- server/config.py | 2 +- server/tests/test_config.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 server/tests/test_config.py 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, + } -- 2.51.2