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
16 changes: 10 additions & 6 deletions src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)