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
440 changes: 207 additions & 233 deletions src/llama_stack_client/_base_client.py

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions src/llama_stack_client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
ProxiesTypes,
RequestOptions,
)
from ._utils import (
is_given,
get_async_library,
)
from ._utils import is_given, get_async_library
from ._version import __version__
from .resources import (
tools,
Expand All @@ -41,6 +38,7 @@
benchmarks,
toolgroups,
vector_dbs,
completions,
scoring_functions,
synthetic_data_generation,
)
Expand All @@ -51,6 +49,7 @@
SyncAPIClient,
AsyncAPIClient,
)
from .resources.chat import chat
from .resources.eval import eval
from .resources.agents import agents
from .resources.tool_runtime import tool_runtime
Expand All @@ -77,6 +76,8 @@ class LlamaStackClient(SyncAPIClient):
eval: eval.EvalResource
inspect: inspect.InspectResource
inference: inference.InferenceResource
chat: chat.ChatResource
completions: completions.CompletionsResource
vector_io: vector_io.VectorIoResource
vector_dbs: vector_dbs.VectorDBsResource
models: models.ModelsResource
Expand Down Expand Up @@ -157,6 +158,8 @@ def __init__(
self.eval = eval.EvalResource(self)
self.inspect = inspect.InspectResource(self)
self.inference = inference.InferenceResource(self)
self.chat = chat.ChatResource(self)
self.completions = completions.CompletionsResource(self)
self.vector_io = vector_io.VectorIoResource(self)
self.vector_dbs = vector_dbs.VectorDBsResource(self)
self.models = models.ModelsResource(self)
Expand Down Expand Up @@ -289,6 +292,8 @@ class AsyncLlamaStackClient(AsyncAPIClient):
eval: eval.AsyncEvalResource
inspect: inspect.AsyncInspectResource
inference: inference.AsyncInferenceResource
chat: chat.AsyncChatResource
completions: completions.AsyncCompletionsResource
vector_io: vector_io.AsyncVectorIoResource
vector_dbs: vector_dbs.AsyncVectorDBsResource
models: models.AsyncModelsResource
Expand Down Expand Up @@ -369,6 +374,8 @@ def __init__(
self.eval = eval.AsyncEvalResource(self)
self.inspect = inspect.AsyncInspectResource(self)
self.inference = inference.AsyncInferenceResource(self)
self.chat = chat.AsyncChatResource(self)
self.completions = completions.AsyncCompletionsResource(self)
self.vector_io = vector_io.AsyncVectorIoResource(self)
self.vector_dbs = vector_dbs.AsyncVectorDBsResource(self)
self.models = models.AsyncModelsResource(self)
Expand Down Expand Up @@ -502,6 +509,8 @@ def __init__(self, client: LlamaStackClient) -> None:
self.eval = eval.EvalResourceWithRawResponse(client.eval)
self.inspect = inspect.InspectResourceWithRawResponse(client.inspect)
self.inference = inference.InferenceResourceWithRawResponse(client.inference)
self.chat = chat.ChatResourceWithRawResponse(client.chat)
self.completions = completions.CompletionsResourceWithRawResponse(client.completions)
self.vector_io = vector_io.VectorIoResourceWithRawResponse(client.vector_io)
self.vector_dbs = vector_dbs.VectorDBsResourceWithRawResponse(client.vector_dbs)
self.models = models.ModelsResourceWithRawResponse(client.models)
Expand Down Expand Up @@ -529,6 +538,8 @@ def __init__(self, client: AsyncLlamaStackClient) -> None:
self.eval = eval.AsyncEvalResourceWithRawResponse(client.eval)
self.inspect = inspect.AsyncInspectResourceWithRawResponse(client.inspect)
self.inference = inference.AsyncInferenceResourceWithRawResponse(client.inference)
self.chat = chat.AsyncChatResourceWithRawResponse(client.chat)
self.completions = completions.AsyncCompletionsResourceWithRawResponse(client.completions)
self.vector_io = vector_io.AsyncVectorIoResourceWithRawResponse(client.vector_io)
self.vector_dbs = vector_dbs.AsyncVectorDBsResourceWithRawResponse(client.vector_dbs)
self.models = models.AsyncModelsResourceWithRawResponse(client.models)
Expand Down Expand Up @@ -558,6 +569,8 @@ def __init__(self, client: LlamaStackClient) -> None:
self.eval = eval.EvalResourceWithStreamingResponse(client.eval)
self.inspect = inspect.InspectResourceWithStreamingResponse(client.inspect)
self.inference = inference.InferenceResourceWithStreamingResponse(client.inference)
self.chat = chat.ChatResourceWithStreamingResponse(client.chat)
self.completions = completions.CompletionsResourceWithStreamingResponse(client.completions)
self.vector_io = vector_io.VectorIoResourceWithStreamingResponse(client.vector_io)
self.vector_dbs = vector_dbs.VectorDBsResourceWithStreamingResponse(client.vector_dbs)
self.models = models.ModelsResourceWithStreamingResponse(client.models)
Expand Down Expand Up @@ -587,6 +600,8 @@ def __init__(self, client: AsyncLlamaStackClient) -> None:
self.eval = eval.AsyncEvalResourceWithStreamingResponse(client.eval)
self.inspect = inspect.AsyncInspectResourceWithStreamingResponse(client.inspect)
self.inference = inference.AsyncInferenceResourceWithStreamingResponse(client.inference)
self.chat = chat.AsyncChatResourceWithStreamingResponse(client.chat)
self.completions = completions.AsyncCompletionsResourceWithStreamingResponse(client.completions)
self.vector_io = vector_io.AsyncVectorIoResourceWithStreamingResponse(client.vector_io)
self.vector_dbs = vector_dbs.AsyncVectorDBsResourceWithStreamingResponse(client.vector_dbs)
self.models = models.AsyncModelsResourceWithStreamingResponse(client.models)
Expand Down
5 changes: 2 additions & 3 deletions src/llama_stack_client/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

import pydantic
import pydantic.generics
from pydantic.fields import FieldInfo

from ._types import (
Expand Down Expand Up @@ -627,8 +626,8 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
# Note: if one variant defines an alias then they all should
discriminator_alias = field_info.alias

if field_info.annotation and is_literal_type(field_info.annotation):
for entry in get_args(field_info.annotation):
if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
for entry in get_args(annotation):
if isinstance(entry, str):
mapping[entry] = variant

Expand Down
2 changes: 1 addition & 1 deletion src/llama_stack_client/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
# split is required to handle cases where additional information is included
# in the response, e.g. application/json; charset=utf-8
content_type, *_ = response.headers.get("content-type", "*").split(";")
if content_type != "application/json":
if not content_type.endswith("json"):
if is_basemodel(cast_to):
try:
data = response.json()
Expand Down
2 changes: 1 addition & 1 deletion src/llama_stack_client/_utils/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MyResponse(Foo[_T]):
```
"""
cls = cast(object, get_origin(typ) or typ)
if cls in generic_bases:
if cls in generic_bases: # pyright: ignore[reportUnnecessaryContains]
# we're given the class directly
return extract_type_arg(typ, index)

Expand Down
10 changes: 9 additions & 1 deletion src/llama_stack_client/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ def _extract_items(
from .._files import assert_is_file_content

# We have exhausted the path, return the entry we found.
assert_is_file_content(obj, key=flattened_key)
assert flattened_key is not None

if is_list(obj):
files: list[tuple[str, FileTypes]] = []
for entry in obj:
assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "")
files.append((flattened_key + "[]", cast(FileTypes, entry)))
return files

assert_is_file_content(obj, key=flattened_key)
return [(flattened_key, cast(FileTypes, obj))]

index += 1
Expand Down
28 changes: 28 additions & 0 deletions src/llama_stack_client/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from .chat import (
ChatResource,
AsyncChatResource,
ChatResourceWithRawResponse,
AsyncChatResourceWithRawResponse,
ChatResourceWithStreamingResponse,
AsyncChatResourceWithStreamingResponse,
)
from .eval import (
EvalResource,
AsyncEvalResource,
Expand Down Expand Up @@ -136,6 +144,14 @@
VectorDBsResourceWithStreamingResponse,
AsyncVectorDBsResourceWithStreamingResponse,
)
from .completions import (
CompletionsResource,
AsyncCompletionsResource,
CompletionsResourceWithRawResponse,
AsyncCompletionsResourceWithRawResponse,
CompletionsResourceWithStreamingResponse,
AsyncCompletionsResourceWithStreamingResponse,
)
from .tool_runtime import (
ToolRuntimeResource,
AsyncToolRuntimeResource,
Expand Down Expand Up @@ -218,6 +234,18 @@
"AsyncInferenceResourceWithRawResponse",
"InferenceResourceWithStreamingResponse",
"AsyncInferenceResourceWithStreamingResponse",
"ChatResource",
"AsyncChatResource",
"ChatResourceWithRawResponse",
"AsyncChatResourceWithRawResponse",
"ChatResourceWithStreamingResponse",
"AsyncChatResourceWithStreamingResponse",
"CompletionsResource",
"AsyncCompletionsResource",
"CompletionsResourceWithRawResponse",
"AsyncCompletionsResourceWithRawResponse",
"CompletionsResourceWithStreamingResponse",
"AsyncCompletionsResourceWithStreamingResponse",
"VectorIoResource",
"AsyncVectorIoResource",
"VectorIoResourceWithRawResponse",
Expand Down
5 changes: 1 addition & 4 deletions src/llama_stack_client/resources/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
AsyncSessionResourceWithStreamingResponse,
)
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
from ..._utils import (
maybe_transform,
async_maybe_transform,
)
from ..._utils import maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
Expand Down
5 changes: 1 addition & 4 deletions src/llama_stack_client/resources/agents/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import httpx

from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
from ..._utils import (
maybe_transform,
async_maybe_transform,
)
from ..._utils import maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
Expand Down
6 changes: 1 addition & 5 deletions src/llama_stack_client/resources/agents/turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import httpx

from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..._utils import (
required_args,
maybe_transform,
async_maybe_transform,
)
from ..._utils import required_args, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
Expand Down
5 changes: 1 addition & 4 deletions src/llama_stack_client/resources/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

from ..types import benchmark_register_params
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
from .._utils import (
maybe_transform,
async_maybe_transform,
)
from .._utils import maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
Expand Down
33 changes: 33 additions & 0 deletions src/llama_stack_client/resources/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from .chat import (
ChatResource,
AsyncChatResource,
ChatResourceWithRawResponse,
AsyncChatResourceWithRawResponse,
ChatResourceWithStreamingResponse,
AsyncChatResourceWithStreamingResponse,
)
from .completions import (
CompletionsResource,
AsyncCompletionsResource,
CompletionsResourceWithRawResponse,
AsyncCompletionsResourceWithRawResponse,
CompletionsResourceWithStreamingResponse,
AsyncCompletionsResourceWithStreamingResponse,
)

__all__ = [
"CompletionsResource",
"AsyncCompletionsResource",
"CompletionsResourceWithRawResponse",
"AsyncCompletionsResourceWithRawResponse",
"CompletionsResourceWithStreamingResponse",
"AsyncCompletionsResourceWithStreamingResponse",
"ChatResource",
"AsyncChatResource",
"ChatResourceWithRawResponse",
"AsyncChatResourceWithRawResponse",
"ChatResourceWithStreamingResponse",
"AsyncChatResourceWithStreamingResponse",
]
102 changes: 102 additions & 0 deletions src/llama_stack_client/resources/chat/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from .completions import (
CompletionsResource,
AsyncCompletionsResource,
CompletionsResourceWithRawResponse,
AsyncCompletionsResourceWithRawResponse,
CompletionsResourceWithStreamingResponse,
AsyncCompletionsResourceWithStreamingResponse,
)

__all__ = ["ChatResource", "AsyncChatResource"]


class ChatResource(SyncAPIResource):
@cached_property
def completions(self) -> CompletionsResource:
return CompletionsResource(self._client)

@cached_property
def with_raw_response(self) -> ChatResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.

For more information, see https://www.github.com/stainless-sdks/llama-stack-python#accessing-raw-response-data-eg-headers
"""
return ChatResourceWithRawResponse(self)

@cached_property
def with_streaming_response(self) -> ChatResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.

For more information, see https://www.github.com/stainless-sdks/llama-stack-python#with_streaming_response
"""
return ChatResourceWithStreamingResponse(self)


class AsyncChatResource(AsyncAPIResource):
@cached_property
def completions(self) -> AsyncCompletionsResource:
return AsyncCompletionsResource(self._client)

@cached_property
def with_raw_response(self) -> AsyncChatResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.

For more information, see https://www.github.com/stainless-sdks/llama-stack-python#accessing-raw-response-data-eg-headers
"""
return AsyncChatResourceWithRawResponse(self)

@cached_property
def with_streaming_response(self) -> AsyncChatResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.

For more information, see https://www.github.com/stainless-sdks/llama-stack-python#with_streaming_response
"""
return AsyncChatResourceWithStreamingResponse(self)


class ChatResourceWithRawResponse:
def __init__(self, chat: ChatResource) -> None:
self._chat = chat

@cached_property
def completions(self) -> CompletionsResourceWithRawResponse:
return CompletionsResourceWithRawResponse(self._chat.completions)


class AsyncChatResourceWithRawResponse:
def __init__(self, chat: AsyncChatResource) -> None:
self._chat = chat

@cached_property
def completions(self) -> AsyncCompletionsResourceWithRawResponse:
return AsyncCompletionsResourceWithRawResponse(self._chat.completions)


class ChatResourceWithStreamingResponse:
def __init__(self, chat: ChatResource) -> None:
self._chat = chat

@cached_property
def completions(self) -> CompletionsResourceWithStreamingResponse:
return CompletionsResourceWithStreamingResponse(self._chat.completions)


class AsyncChatResourceWithStreamingResponse:
def __init__(self, chat: AsyncChatResource) -> None:
self._chat = chat

@cached_property
def completions(self) -> AsyncCompletionsResourceWithStreamingResponse:
return AsyncCompletionsResourceWithStreamingResponse(self._chat.completions)
Loading
Loading