Skip to content

Commit 4fc0ce6

Browse files
author
Eric Huang (AI Platform)
committed
Sync updates from stainless branch: ehhuang/dev
1 parent b183fb6 commit 4fc0ce6

36 files changed

+388
-46
lines changed

src/llama_stack_client/_base_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,17 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
418418
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
419419
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
420420

421-
# Don't set the retry count header if it was already set or removed by the caller. We check
421+
# Don't set these headers if they were already set or removed by the caller. We check
422422
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
423-
if "x-stainless-retry-count" not in (header.lower() for header in custom_headers):
423+
lower_custom_headers = [header.lower() for header in custom_headers]
424+
if "x-stainless-retry-count" not in lower_custom_headers:
424425
headers["x-stainless-retry-count"] = str(retries_taken)
426+
if "x-stainless-read-timeout" not in lower_custom_headers:
427+
timeout = self.timeout if isinstance(options.timeout, NotGiven) else options.timeout
428+
if isinstance(timeout, Timeout):
429+
timeout = timeout.read
430+
if timeout is not None:
431+
headers["x-stainless-read-timeout"] = str(timeout)
425432

426433
return headers
427434

src/llama_stack_client/_client.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ class LlamaStackClient(SyncAPIClient):
9898
with_streaming_response: LlamaStackClientWithStreamedResponse
9999

100100
# client options
101+
api_key: str | None
101102

102103
def __init__(
103104
self,
104105
*,
106+
api_key: str | None = None,
105107
base_url: str | httpx.URL | None = None,
106108
api_key: str | None = None,
107109
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
@@ -123,7 +125,14 @@ def __init__(
123125
_strict_response_validation: bool = False,
124126
provider_data: Mapping[str, Any] | None = None,
125127
) -> None:
126-
"""Construct a new synchronous llama-stack-client client instance."""
128+
"""Construct a new synchronous llama-stack-client client instance.
129+
130+
This automatically infers the `api_key` argument from the `LLAMA_STACK_API_KEY` environment variable if it is not provided.
131+
"""
132+
if api_key is None:
133+
api_key = os.environ.get("LLAMA_STACK_API_KEY")
134+
self.api_key = api_key
135+
127136
if base_url is None:
128137
base_url = os.environ.get("LLAMA_STACK_CLIENT_BASE_URL")
129138
if base_url is None:
@@ -182,6 +191,14 @@ def __init__(
182191
def qs(self) -> Querystring:
183192
return Querystring(array_format="comma")
184193

194+
@property
195+
@override
196+
def auth_headers(self) -> dict[str, str]:
197+
api_key = self.api_key
198+
if api_key is None:
199+
return {}
200+
return {"Authorization": f"Bearer {api_key}"}
201+
185202
@property
186203
@override
187204
def default_headers(self) -> dict[str, str | Omit]:
@@ -194,6 +211,7 @@ def default_headers(self) -> dict[str, str | Omit]:
194211
def copy(
195212
self,
196213
*,
214+
api_key: str | None = None,
197215
base_url: str | httpx.URL | None = None,
198216
api_key: str | None = None,
199217
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
@@ -228,6 +246,7 @@ def copy(
228246

229247
http_client = http_client or self._client
230248
return self.__class__(
249+
api_key=api_key or self.api_key,
231250
base_url=base_url or self.base_url,
232251
api_key=api_key or self.api_key,
233252
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
@@ -304,10 +323,12 @@ class AsyncLlamaStackClient(AsyncAPIClient):
304323
with_streaming_response: AsyncLlamaStackClientWithStreamedResponse
305324

306325
# client options
326+
api_key: str | None
307327

308328
def __init__(
309329
self,
310330
*,
331+
api_key: str | None = None,
311332
base_url: str | httpx.URL | None = None,
312333
api_key: str | None = None,
313334
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
@@ -329,7 +350,14 @@ def __init__(
329350
_strict_response_validation: bool = False,
330351
provider_data: Mapping[str, Any] | None = None,
331352
) -> None:
332-
"""Construct a new async llama-stack-client client instance."""
353+
"""Construct a new async llama-stack-client client instance.
354+
355+
This automatically infers the `api_key` argument from the `LLAMA_STACK_API_KEY` environment variable if it is not provided.
356+
"""
357+
if api_key is None:
358+
api_key = os.environ.get("LLAMA_STACK_API_KEY")
359+
self.api_key = api_key
360+
333361
if base_url is None:
334362
base_url = os.environ.get("LLAMA_STACK_CLIENT_BASE_URL")
335363
if base_url is None:
@@ -388,6 +416,14 @@ def __init__(
388416
def qs(self) -> Querystring:
389417
return Querystring(array_format="comma")
390418

419+
@property
420+
@override
421+
def auth_headers(self) -> dict[str, str]:
422+
api_key = self.api_key
423+
if api_key is None:
424+
return {}
425+
return {"Authorization": f"Bearer {api_key}"}
426+
391427
@property
392428
@override
393429
def default_headers(self) -> dict[str, str | Omit]:
@@ -400,6 +436,7 @@ def default_headers(self) -> dict[str, str | Omit]:
400436
def copy(
401437
self,
402438
*,
439+
api_key: str | None = None,
403440
base_url: str | httpx.URL | None = None,
404441
api_key: str | None = None,
405442
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
@@ -434,6 +471,7 @@ def copy(
434471

435472
http_client = http_client or self._client
436473
return self.__class__(
474+
api_key=api_key or self.api_key,
437475
base_url=base_url or self.base_url,
438476
api_key=api_key or self.api_key,
439477
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,

src/llama_stack_client/_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
77

88
# default timeout is 1 minute
9-
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
9+
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
1010
DEFAULT_MAX_RETRIES = 2
1111
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
1212

src/llama_stack_client/resources/agents/turn.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def create(
5959
messages: Iterable[turn_create_params.Message],
6060
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
6161
stream: Literal[False] | NotGiven = NOT_GIVEN,
62+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
6263
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
6364
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
6465
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -69,6 +70,8 @@ def create(
6970
) -> Turn:
7071
"""
7172
Args:
73+
tool_config: Configuration for tool use.
74+
7275
extra_headers: Send extra headers
7376
7477
extra_query: Add additional query parameters to the request
@@ -88,6 +91,7 @@ def create(
8891
messages: Iterable[turn_create_params.Message],
8992
stream: Literal[True],
9093
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
94+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
9195
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
9296
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
9397
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -98,6 +102,8 @@ def create(
98102
) -> Stream[AgentTurnResponseStreamChunk]:
99103
"""
100104
Args:
105+
tool_config: Configuration for tool use.
106+
101107
extra_headers: Send extra headers
102108
103109
extra_query: Add additional query parameters to the request
@@ -117,6 +123,7 @@ def create(
117123
messages: Iterable[turn_create_params.Message],
118124
stream: bool,
119125
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
126+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
120127
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
121128
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
122129
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -127,6 +134,8 @@ def create(
127134
) -> Turn | Stream[AgentTurnResponseStreamChunk]:
128135
"""
129136
Args:
137+
tool_config: Configuration for tool use.
138+
130139
extra_headers: Send extra headers
131140
132141
extra_query: Add additional query parameters to the request
@@ -146,6 +155,7 @@ def create(
146155
messages: Iterable[turn_create_params.Message],
147156
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
148157
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
158+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
149159
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
150160
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
151161
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -165,6 +175,7 @@ def create(
165175
"messages": messages,
166176
"documents": documents,
167177
"stream": stream,
178+
"tool_config": tool_config,
168179
"toolgroups": toolgroups,
169180
},
170181
turn_create_params.TurnCreateParams,
@@ -244,6 +255,7 @@ async def create(
244255
messages: Iterable[turn_create_params.Message],
245256
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
246257
stream: Literal[False] | NotGiven = NOT_GIVEN,
258+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
247259
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
248260
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
249261
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -254,6 +266,8 @@ async def create(
254266
) -> Turn:
255267
"""
256268
Args:
269+
tool_config: Configuration for tool use.
270+
257271
extra_headers: Send extra headers
258272
259273
extra_query: Add additional query parameters to the request
@@ -273,6 +287,7 @@ async def create(
273287
messages: Iterable[turn_create_params.Message],
274288
stream: Literal[True],
275289
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
290+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
276291
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
277292
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
278293
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -283,6 +298,8 @@ async def create(
283298
) -> AsyncStream[AgentTurnResponseStreamChunk]:
284299
"""
285300
Args:
301+
tool_config: Configuration for tool use.
302+
286303
extra_headers: Send extra headers
287304
288305
extra_query: Add additional query parameters to the request
@@ -302,6 +319,7 @@ async def create(
302319
messages: Iterable[turn_create_params.Message],
303320
stream: bool,
304321
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
322+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
305323
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
306324
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
307325
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -312,6 +330,8 @@ async def create(
312330
) -> Turn | AsyncStream[AgentTurnResponseStreamChunk]:
313331
"""
314332
Args:
333+
tool_config: Configuration for tool use.
334+
315335
extra_headers: Send extra headers
316336
317337
extra_query: Add additional query parameters to the request
@@ -331,6 +351,7 @@ async def create(
331351
messages: Iterable[turn_create_params.Message],
332352
documents: Iterable[turn_create_params.Document] | NotGiven = NOT_GIVEN,
333353
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
354+
tool_config: turn_create_params.ToolConfig | NotGiven = NOT_GIVEN,
334355
toolgroups: List[turn_create_params.Toolgroup] | NotGiven = NOT_GIVEN,
335356
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
336357
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -350,6 +371,7 @@ async def create(
350371
"messages": messages,
351372
"documents": documents,
352373
"stream": stream,
374+
"tool_config": tool_config,
353375
"toolgroups": toolgroups,
354376
},
355377
turn_create_params.TurnCreateParams,

src/llama_stack_client/resources/batch_inference.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def chat_completion(
7272
) -> BatchInferenceChatCompletionResponse:
7373
"""
7474
Args:
75+
response_format: Configuration for JSON schema-guided response generation.
76+
77+
tool_choice: Whether tool use is required or automatic. This is a hint to the model which may
78+
not be followed. It depends on the Instruction Following capabilities of the
79+
model.
80+
81+
tool_prompt_format: Prompt format for calling custom / zero shot tools.
82+
7583
extra_headers: Send extra headers
7684
7785
extra_query: Add additional query parameters to the request
@@ -118,6 +126,8 @@ def completion(
118126
) -> BatchCompletion:
119127
"""
120128
Args:
129+
response_format: Configuration for JSON schema-guided response generation.
130+
121131
extra_headers: Send extra headers
122132
123133
extra_query: Add additional query parameters to the request
@@ -185,6 +195,14 @@ async def chat_completion(
185195
) -> BatchInferenceChatCompletionResponse:
186196
"""
187197
Args:
198+
response_format: Configuration for JSON schema-guided response generation.
199+
200+
tool_choice: Whether tool use is required or automatic. This is a hint to the model which may
201+
not be followed. It depends on the Instruction Following capabilities of the
202+
model.
203+
204+
tool_prompt_format: Prompt format for calling custom / zero shot tools.
205+
188206
extra_headers: Send extra headers
189207
190208
extra_query: Add additional query parameters to the request
@@ -231,6 +249,8 @@ async def completion(
231249
) -> BatchCompletion:
232250
"""
233251
Args:
252+
response_format: Configuration for JSON schema-guided response generation.
253+
234254
extra_headers: Send extra headers
235255
236256
extra_query: Add additional query parameters to the request

0 commit comments

Comments
 (0)