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
26 changes: 21 additions & 5 deletions docs/cli_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $ llama-stack-client providers list

#### `llama-stack-client models list`
```bash
llama-stack-client models list
$ llama-stack-client models list
```
```
+----------------------+----------------------+---------------+----------------------------------------------------------+
Expand All @@ -64,7 +64,7 @@ llama-stack-client models list

#### `llama-stack-client models get`
```bash
llama-stack-client models get Llama3.1-8B-Instruct
$ llama-stack-client models get Llama3.1-8B-Instruct
```

```
Expand All @@ -82,11 +82,27 @@ $ llama-stack-client models get Random-Model
Model RandomModel is not found at distribution endpoint host:port. Please ensure endpoint is serving specified model.
```

#### `llama-stack-client models register`

```bash
$ llama-stack-client models register <model_id> [--provider-id <provider_id>] [--provider-model-id <provider_model_id>] [--metadata <metadata>]
```

#### `llama-stack-client models update`

```bash
$ llama-stack-client models update <model_id> [--provider-id <provider_id>] [--provider-model-id <provider_model_id>] [--metadata <metadata>]
```

#### `llama-stack-client models delete`

```bash
$ llama-stack-client models delete <model_id>
```

#### `llama-stack-client memory_banks list`
```bash
llama-stack-client memory_banks list
$ llama-stack-client memory_banks list
```
```
+--------------+----------------+--------+-------------------+------------------------+--------------------------+
Expand All @@ -98,7 +114,7 @@ llama-stack-client memory_banks list

#### `llama-stack-client shields list`
```bash
llama-stack-client shields list
$ llama-stack-client shields list
```

```
Expand All @@ -107,4 +123,4 @@ llama-stack-client shields list
+==============+==========+================+=============+
| llama_guard | {} | meta-reference | llama_guard |
+--------------+----------+----------------+-------------+
```
```
44 changes: 23 additions & 21 deletions src/llama_stack_client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@

from __future__ import annotations

import json

import os
from typing import Any, Mapping, Union
from typing import Any, Union, Mapping
from typing_extensions import Self, override

import httpx
from typing_extensions import override, Self

from . import _exceptions, resources
from ._base_client import AsyncAPIClient, DEFAULT_MAX_RETRIES, SyncAPIClient
from ._exceptions import APIStatusError
from . import resources, _exceptions
from ._qs import Querystring
from ._streaming import AsyncStream as AsyncStream, Stream as Stream
from ._types import NOT_GIVEN, NotGiven, Omit, ProxiesTypes, RequestOptions, Timeout, Transport
from ._utils import get_async_library, is_given
from ._types import (
NOT_GIVEN,
Omit,
Timeout,
NotGiven,
Transport,
ProxiesTypes,
RequestOptions,
)
from ._utils import (
is_given,
get_async_library,
)
from ._version import __version__
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._exceptions import APIStatusError
from ._base_client import (
DEFAULT_MAX_RETRIES,
SyncAPIClient,
AsyncAPIClient,
)

__all__ = [
"Timeout",
Expand Down Expand Up @@ -79,17 +92,12 @@ def __init__(
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
_strict_response_validation: bool = False,
provider_data: Mapping[str, Any] | None = None,
) -> None:
"""Construct a new synchronous llama-stack-client client instance."""
if base_url is None:
base_url = os.environ.get("LLAMA_STACK_CLIENT_BASE_URL")
if base_url is None:
base_url = f"http://any-hosted-llama-stack.com"
if provider_data:
if default_headers is None:
default_headers = {}
default_headers["X-LlamaStack-ProviderData"] = json.dumps(provider_data)

super().__init__(
version=__version__,
Expand Down Expand Up @@ -269,19 +277,13 @@ def __init__(
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
_strict_response_validation: bool = False,
provider_data: Mapping[str, Any] | None = None,
) -> None:
"""Construct a new async llama-stack-client client instance."""
if base_url is None:
base_url = os.environ.get("LLAMA_STACK_CLIENT_BASE_URL")
if base_url is None:
base_url = f"http://any-hosted-llama-stack.com"

if provider_data:
if default_headers is None:
default_headers = {}
default_headers["X-LlamaStack-ProviderData"] = json.dumps(provider_data)

super().__init__(
version=__version__,
base_url=base_url,
Expand Down
2 changes: 1 addition & 1 deletion src/llama_stack_client/lib/.keep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File generated from our OpenAPI spec by Stainless.

This directory can be used to store custom files to expand the SDK.
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
39 changes: 39 additions & 0 deletions src/llama_stack_client/lib/cli/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,46 @@ def register_model(
click.echo(f"Failed to register model: {str(e)}")


@click.command(name="update", help="Update an existing model at distribution endpoint")
@click.argument("model_id")
@click.option("--provider-id", help="Provider ID for the model", default=None)
@click.option("--provider-model-id", help="Provider's model ID", default=None)
@click.option("--metadata", help="JSON metadata for the model", default=None)
@click.pass_context
def update_model(
ctx, model_id: str, provider_id: Optional[str], provider_model_id: Optional[str], metadata: Optional[str]
):
"""Update an existing model at distribution endpoint"""
client = ctx.obj["client"]

try:
response = client.models.update(
model_id=model_id, provider_id=provider_id, provider_model_id=provider_model_id, metadata=metadata
)
if response:
click.echo(f"Successfully updated model {model_id}")
except Exception as e:
click.echo(f"Failed to update model: {str(e)}")


@click.command(name="delete", help="Delete a model from distribution endpoint")
@click.argument("model_id")
@click.pass_context
def delete_model(ctx, model_id: str):
"""Delete a model from distribution endpoint"""
client = ctx.obj["client"]

try:
response = client.models.delete(model_id=model_id)
if response:
click.echo(f"Successfully deleted model {model_id}")
except Exception as e:
click.echo(f"Failed to delete model: {str(e)}")


# Register subcommands
models.add_command(list_models)
models.add_command(get_model)
models.add_command(register_model)
models.add_command(update_model)
models.add_command(delete_model)
Loading