From ff3cb032a69c61d027ba1f86f81a7f27dc39c967 Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Tue, 4 Feb 2025 12:52:48 -0500 Subject: [PATCH 1/2] fix stack trace when stack is not built. currently this is the output when you run a distribution locally without running `llama stack build`: ``` Traceback (most recent call last): File "/Users/charliedoern/Documents/llama-sdk.py", line 25, in models = client.models.list() ^^^^^^^^^^^^^^^^^^^^ File "/Users/charliedoern/Documents/llama-stack-client-python/src/llama_stack_client/resources/models.py", line 107, in list raise exc File "/Users/charliedoern/Documents/llama-stack-client-python/src/llama_stack_client/resources/models.py", line 95, in list return self._get( ^^^^^^^^^^ File "/Users/charliedoern/Documents/llama-stack-client-python/src/llama_stack_client/_base_client.py", line 1212, in get return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/charliedoern/Documents/llama-stack/llama_stack/distribution/library_client.py", line 168, in request return asyncio.run(self.async_client.request(*args, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/Users/charliedoern/Documents/llama-stack/llama_stack/distribution/library_client.py", line 258, in request if not self.endpoint_impls: ^^^^^^^^^^^^^^^^^^^ AttributeError: 'AsyncLlamaStackAsLibraryClient' object has no attribute 'endpoint_impls' ``` the intended exception is never raised, initialize endpoint_impls properly so it is `None` and the ValueError can be raised Signed-off-by: Charlie Doern --- docs/source/getting_started/index.md | 8 +++++++- llama_stack/distribution/library_client.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/source/getting_started/index.md b/docs/source/getting_started/index.md index 1ddc5ff543..cc82166cb0 100644 --- a/docs/source/getting_started/index.md +++ b/docs/source/getting_started/index.md @@ -134,7 +134,13 @@ client = ( ) # or create_http_client() depending on the environment you picked # List available models -models = client.models.list() + +try: + models = client.models.list() +except ValueError as e: + print(e) + sys.exit(1) + print("--- Available models: ---") for m in models: print(f"- {m.identifier}") diff --git a/llama_stack/distribution/library_client.py b/llama_stack/distribution/library_client.py index 13aa679563..d4a7cde7e9 100644 --- a/llama_stack/distribution/library_client.py +++ b/llama_stack/distribution/library_client.py @@ -198,6 +198,7 @@ def __init__( async def initialize(self) -> bool: try: + self.endpoint_impls = None self.impls = await construct_stack(self.config, self.custom_provider_registry) except ModuleNotFoundError as _e: cprint(_e.msg, "red") From 2493eb794f19c3fad567debfa335e19ea51e8bf5 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Fri, 7 Feb 2025 09:46:02 -0800 Subject: [PATCH 2/2] Avoid error catching --- docs/source/getting_started/index.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/docs/source/getting_started/index.md b/docs/source/getting_started/index.md index cc82166cb0..1ddc5ff543 100644 --- a/docs/source/getting_started/index.md +++ b/docs/source/getting_started/index.md @@ -134,13 +134,7 @@ client = ( ) # or create_http_client() depending on the environment you picked # List available models - -try: - models = client.models.list() -except ValueError as e: - print(e) - sys.exit(1) - +models = client.models.list() print("--- Available models: ---") for m in models: print(f"- {m.identifier}")