Skip to content

Commit

Permalink
Merge pull request #35 from meta-llama/stainless_sync_XPBkes
Browse files Browse the repository at this point in the history
sync sdk
  • Loading branch information
dineshyv authored Nov 15, 2024
2 parents 5eba7ad + de273ba commit 649e149
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 185 deletions.
39 changes: 26 additions & 13 deletions src/llama_stack_client/_client.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

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 @@ -86,11 +100,11 @@ def __init__(
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 provider_data is not None:
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 Expand Up @@ -277,11 +291,10 @@ def __init__(
if base_url is None:
base_url = f"http://any-hosted-llama-stack.com"

if provider_data:
if provider_data is not None:
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
7 changes: 4 additions & 3 deletions src/llama_stack_client/lib/agents/custom_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from typing import Dict, List, Union

from llama_stack_client.types import ToolResponseMessage, UserMessage
from llama_stack_client.types.agent_create_params import AgentConfigToolFunctionCallToolDefinition
from llama_stack_client.types.shared_params.function_call_tool_definition import FunctionCallToolDefinition


from llama_stack_client.types.tool_param_definition_param import ToolParamDefinitionParam

Expand Down Expand Up @@ -53,8 +54,8 @@ def parameters_for_system_prompt(self) -> str:
}
)

def get_tool_definition(self) -> AgentConfigToolFunctionCallToolDefinition:
return AgentConfigToolFunctionCallToolDefinition(
def get_tool_definition(self) -> FunctionCallToolDefinition:
return FunctionCallToolDefinition(
type="function_call",
function_name=self.get_name(),
description=self.get_description(),
Expand Down
2 changes: 2 additions & 0 deletions src/llama_stack_client/resources/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def completion(
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
extra_headers = {
**strip_not_given({"X-LlamaStack-ProviderData": x_llama_stack_provider_data}),
**(extra_headers or {}),
Expand Down Expand Up @@ -344,6 +345,7 @@ async def completion(
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
extra_headers = {
**strip_not_given({"X-LlamaStack-ProviderData": x_llama_stack_provider_data}),
**(extra_headers or {}),
Expand Down
94 changes: 93 additions & 1 deletion src/llama_stack_client/resources/memory_banks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

import httpx

from ..types import memory_bank_register_params, memory_bank_retrieve_params
from ..types import (
memory_bank_register_params,
memory_bank_retrieve_params,
memory_bank_unregister_params,
)
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
from .._utils import (
maybe_transform,
Expand Down Expand Up @@ -179,6 +183,44 @@ def register(
cast_to=NoneType,
)

def unregister(
self,
*,
memory_bank_id: str,
x_llama_stack_provider_data: str | NotGiven = NOT_GIVEN,
# 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:
"""
Args:
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
"""
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
extra_headers = {
**strip_not_given({"X-LlamaStack-ProviderData": x_llama_stack_provider_data}),
**(extra_headers or {}),
}
return self._post(
"/memory_banks/unregister",
body=maybe_transform(
{"memory_bank_id": memory_bank_id}, memory_bank_unregister_params.MemoryBankUnregisterParams
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=NoneType,
)


class AsyncMemoryBanksResource(AsyncAPIResource):
@cached_property
Expand Down Expand Up @@ -331,6 +373,44 @@ async def register(
cast_to=NoneType,
)

async def unregister(
self,
*,
memory_bank_id: str,
x_llama_stack_provider_data: str | NotGiven = NOT_GIVEN,
# 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:
"""
Args:
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
"""
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
extra_headers = {
**strip_not_given({"X-LlamaStack-ProviderData": x_llama_stack_provider_data}),
**(extra_headers or {}),
}
return await self._post(
"/memory_banks/unregister",
body=await async_maybe_transform(
{"memory_bank_id": memory_bank_id}, memory_bank_unregister_params.MemoryBankUnregisterParams
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=NoneType,
)


class MemoryBanksResourceWithRawResponse:
def __init__(self, memory_banks: MemoryBanksResource) -> None:
Expand All @@ -345,6 +425,9 @@ def __init__(self, memory_banks: MemoryBanksResource) -> None:
self.register = to_raw_response_wrapper(
memory_banks.register,
)
self.unregister = to_raw_response_wrapper(
memory_banks.unregister,
)


class AsyncMemoryBanksResourceWithRawResponse:
Expand All @@ -360,6 +443,9 @@ def __init__(self, memory_banks: AsyncMemoryBanksResource) -> None:
self.register = async_to_raw_response_wrapper(
memory_banks.register,
)
self.unregister = async_to_raw_response_wrapper(
memory_banks.unregister,
)


class MemoryBanksResourceWithStreamingResponse:
Expand All @@ -375,6 +461,9 @@ def __init__(self, memory_banks: MemoryBanksResource) -> None:
self.register = to_streamed_response_wrapper(
memory_banks.register,
)
self.unregister = to_streamed_response_wrapper(
memory_banks.unregister,
)


class AsyncMemoryBanksResourceWithStreamingResponse:
Expand All @@ -390,3 +479,6 @@ def __init__(self, memory_banks: AsyncMemoryBanksResource) -> None:
self.register = async_to_streamed_response_wrapper(
memory_banks.register,
)
self.unregister = async_to_streamed_response_wrapper(
memory_banks.unregister,
)
Loading

0 comments on commit 649e149

Please sign in to comment.