Skip to content
Open
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
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ Methods:
- <code title="get /v1/shields/{identifier}">client.shields.<a href="./src/llama_stack_client/resources/shields.py">retrieve</a>(identifier) -> <a href="./src/llama_stack_client/types/shield.py">Shield</a></code>
- <code title="get /v1/shields">client.shields.<a href="./src/llama_stack_client/resources/shields.py">list</a>() -> <a href="./src/llama_stack_client/types/shield_list_response.py">ShieldListResponse</a></code>
- <code title="post /v1/shields">client.shields.<a href="./src/llama_stack_client/resources/shields.py">register</a>(\*\*<a href="src/llama_stack_client/types/shield_register_params.py">params</a>) -> <a href="./src/llama_stack_client/types/shield.py">Shield</a></code>
- <code title="delete /v1/shields/{identifier}">client.shields.<a href="./src/llama_stack_client/resources/shields.py">unregister</a>(identifier) -> None</code>

# SyntheticDataGeneration

Expand Down
13 changes: 13 additions & 0 deletions src/llama_stack_client/lib/cli/shields/shields.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ def register(
click.echo(yaml.dump(response.dict()))


@shields.command()
@click.help_option("-h", "--help")
@click.argument("shield-id", required=True)
@click.pass_context
@handle_client_errors("unregister shield")
def unregister(ctx, shield_id: str):
"""Unregister a shield"""
client = ctx.obj["client"]
client.shields.unregister(identifier=shield_id)
click.echo(f"Successfully unregistered shield {shield_id}")


# Register subcommands
shields.add_command(list)
shields.add_command(register)
shields.add_command(unregister)
88 changes: 87 additions & 1 deletion src/llama_stack_client/resources/shields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import httpx

from ..types import shield_register_params
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
from .._utils import maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
Expand Down Expand Up @@ -151,6 +151,42 @@ def register(
),
cast_to=Shield,
)

def unregister(
self,
identifier: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> None:
"""
Unregister a shield.
Args:
identifier: The identifier of the shield to unregister.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not identifier:
raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}")
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return self._delete(
f"/v1/shields/{identifier}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=NoneType,
)


class AsyncShieldsResource(AsyncAPIResource):
Expand Down Expand Up @@ -279,6 +315,42 @@ async def register(
),
cast_to=Shield,
)

async def unregister(
self,
identifier: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> None:
"""
Unregister a shield.
Args:
identifier: The identifier of the shield to unregister.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not identifier:
raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}")
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return await self._delete(
f"/v1/shields/{identifier}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=NoneType,
)


class ShieldsResourceWithRawResponse:
Expand All @@ -295,6 +367,10 @@ def __init__(self, shields: ShieldsResource) -> None:
shields.register,
)

self.unregister = to_raw_response_wrapper(
shields.unregister,
)


class AsyncShieldsResourceWithRawResponse:
def __init__(self, shields: AsyncShieldsResource) -> None:
Expand All @@ -310,6 +386,10 @@ def __init__(self, shields: AsyncShieldsResource) -> None:
shields.register,
)

self.unregister = async_to_raw_response_wrapper(
shields.unregister,
)


class ShieldsResourceWithStreamingResponse:
def __init__(self, shields: ShieldsResource) -> None:
Expand All @@ -324,6 +404,9 @@ def __init__(self, shields: ShieldsResource) -> None:
self.register = to_streamed_response_wrapper(
shields.register,
)
self.unregister = to_streamed_response_wrapper(
shields.unregister,
)


class AsyncShieldsResourceWithStreamingResponse:
Expand All @@ -339,3 +422,6 @@ def __init__(self, shields: AsyncShieldsResource) -> None:
self.register = async_to_streamed_response_wrapper(
shields.register,
)
self.unregister = async_to_streamed_response_wrapper(
shields.unregister,
)
62 changes: 62 additions & 0 deletions tests/api_resources/test_shields.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ def test_streaming_response_register(self, client: LlamaStackClient) -> None:

assert cast(Any, response.is_closed) is True

@parametrize
def test_method_unregister(self, client: LlamaStackClient) -> None:
shield = client.shields.unregister(
identifier="identifier",
)
assert shield is None

@parametrize
def test_raw_response_unregister(self, client: LlamaStackClient) -> None:
response = client.shields.with_raw_response.unregister(
identifier="identifier",
)

assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
shield = response.parse()
assert shield is None

@parametrize
def test_streaming_response_unregister(self, client: LlamaStackClient) -> None:
with client.shields.with_streaming_response.unregister(
identifier="identifier",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

shield = response.parse()
assert shield is None

assert cast(Any, response.is_closed) is True


class TestAsyncShields:
parametrize = pytest.mark.parametrize(
Expand Down Expand Up @@ -230,3 +261,34 @@ async def test_streaming_response_register(self, async_client: AsyncLlamaStackCl
assert_matches_type(Shield, shield, path=["response"])

assert cast(Any, response.is_closed) is True

@parametrize
async def test_method_unregister(self, async_client: AsyncLlamaStackClient) -> None:
shield = await async_client.shields.unregister(
identifier="identifier",
)
assert shield is None

@parametrize
async def test_raw_response_unregister(self, async_client: AsyncLlamaStackClient) -> None:
response = await async_client.shields.with_raw_response.unregister(
identifier="identifier",
)

assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
shield = await response.parse()
assert shield is None

@parametrize
async def test_streaming_response_unregister(self, async_client: AsyncLlamaStackClient) -> None:
async with async_client.shields.with_streaming_response.unregister(
identifier="identifier",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

shield = await response.parse()
assert shield is None

assert cast(Any, response.is_closed) is True