From 574dfbef859a2f4e602274458e9c0e58260306ae Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 22 May 2025 08:39:39 +0200 Subject: [PATCH 1/2] [minor] Check if library_path is specified --- src/client.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/client.py b/src/client.py index e8f37cbe..de243124 100644 --- a/src/client.py +++ b/src/client.py @@ -13,12 +13,16 @@ def get_llama_stack_client( llama_stack_config: LLamaStackConfiguration, ) -> LlamaStackClient: if llama_stack_config.use_as_library_client is True: - logger.info("Using Llama stack as library client") - client = LlamaStackAsLibraryClient( - llama_stack_config.library_client_config_path - ) - client.initialize() - return client + if llama_stack_config.library_client_config_path is not None: + logger.info("Using Llama stack as library client") + client = LlamaStackAsLibraryClient( + llama_stack_config.library_client_config_path + ) + client.initialize() + return client + msg = "Configuration problem: library_client_config_path option is not set" + logger.error(msg) + raise Exception(msg) else: logger.info("Using Llama stack running as a service") return LlamaStackClient( From a8de42779ce416a5a7890ecc706455a8ed300aed Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 22 May 2025 08:40:01 +0200 Subject: [PATCH 2/2] Updated unit tests accordingly --- tests/unit/test_client.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 888abc2e..fc3c97e4 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -1,6 +1,7 @@ """Unit tests for functions defined in src/client.py.""" import os +import pytest from unittest.mock import patch from client import get_llama_stack_client @@ -29,3 +30,19 @@ def test_get_llama_stack_remote_client(): ) client = get_llama_stack_client(cfg) assert client is not None + + +@patch.dict(os.environ, {"INFERENCE_MODEL": "llama3.2:3b-instruct-fp16"}) +def test_get_llama_stack_wrong_configuration(): + cfg = LLamaStackConfiguration( + url=None, + api_key=None, + use_as_library_client=True, + library_client_config_path="ollama", + ) + cfg.library_client_config_path = None + with pytest.raises( + Exception, + match="Configuration problem: library_client_config_path option is not set", + ): + get_llama_stack_client(cfg)