llama-stack-client 0.0.1a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. llama_stack/__init__.py +95 -0
  2. llama_stack/_base_client.py +2019 -0
  3. llama_stack/_client.py +518 -0
  4. llama_stack/_compat.py +217 -0
  5. llama_stack/_constants.py +14 -0
  6. llama_stack/_exceptions.py +108 -0
  7. llama_stack/_files.py +123 -0
  8. llama_stack/_models.py +785 -0
  9. llama_stack/_qs.py +150 -0
  10. llama_stack/_resource.py +43 -0
  11. llama_stack/_response.py +823 -0
  12. llama_stack/_streaming.py +333 -0
  13. llama_stack/_types.py +217 -0
  14. llama_stack/_utils/__init__.py +55 -0
  15. llama_stack/_utils/_logs.py +25 -0
  16. llama_stack/_utils/_proxy.py +62 -0
  17. llama_stack/_utils/_reflection.py +42 -0
  18. llama_stack/_utils/_streams.py +12 -0
  19. llama_stack/_utils/_sync.py +81 -0
  20. llama_stack/_utils/_transform.py +382 -0
  21. llama_stack/_utils/_typing.py +120 -0
  22. llama_stack/_utils/_utils.py +397 -0
  23. llama_stack/_version.py +4 -0
  24. llama_stack/lib/.keep +4 -0
  25. llama_stack/py.typed +0 -0
  26. llama_stack/resources/__init__.py +173 -0
  27. llama_stack/resources/agentic_system/__init__.py +61 -0
  28. llama_stack/resources/agentic_system/agentic_system.py +338 -0
  29. llama_stack/resources/agentic_system/sessions.py +363 -0
  30. llama_stack/resources/agentic_system/steps.py +186 -0
  31. llama_stack/resources/agentic_system/turns.py +443 -0
  32. llama_stack/resources/batch_inference.py +315 -0
  33. llama_stack/resources/datasets.py +331 -0
  34. llama_stack/resources/evaluate/__init__.py +47 -0
  35. llama_stack/resources/evaluate/evaluate.py +135 -0
  36. llama_stack/resources/evaluate/jobs/__init__.py +61 -0
  37. llama_stack/resources/evaluate/jobs/artifacts.py +168 -0
  38. llama_stack/resources/evaluate/jobs/jobs.py +310 -0
  39. llama_stack/resources/evaluate/jobs/logs.py +168 -0
  40. llama_stack/resources/evaluate/jobs/status.py +168 -0
  41. llama_stack/resources/evaluate/question_answering.py +167 -0
  42. llama_stack/resources/evaluations.py +243 -0
  43. llama_stack/resources/inference/__init__.py +33 -0
  44. llama_stack/resources/inference/embeddings.py +178 -0
  45. llama_stack/resources/inference/inference.py +591 -0
  46. llama_stack/resources/memory_banks/__init__.py +33 -0
  47. llama_stack/resources/memory_banks/documents.py +268 -0
  48. llama_stack/resources/memory_banks/memory_banks.py +675 -0
  49. llama_stack/resources/post_training/__init__.py +33 -0
  50. llama_stack/resources/post_training/jobs.py +451 -0
  51. llama_stack/resources/post_training/post_training.py +365 -0
  52. llama_stack/resources/reward_scoring.py +178 -0
  53. llama_stack/resources/safety.py +179 -0
  54. llama_stack/resources/synthetic_data_generation.py +183 -0
  55. llama_stack/resources/telemetry.py +244 -0
  56. llama_stack/types/__init__.py +75 -0
  57. llama_stack/types/agentic_system/__init__.py +16 -0
  58. llama_stack/types/agentic_system/agentic_system_step.py +18 -0
  59. llama_stack/types/agentic_system/agentic_system_turn_stream_chunk.py +12 -0
  60. llama_stack/types/agentic_system/session.py +21 -0
  61. llama_stack/types/agentic_system/session_create_params.py +13 -0
  62. llama_stack/types/agentic_system/session_create_response.py +11 -0
  63. llama_stack/types/agentic_system/session_delete_params.py +13 -0
  64. llama_stack/types/agentic_system/session_retrieve_params.py +16 -0
  65. llama_stack/types/agentic_system/step_retrieve_params.py +15 -0
  66. llama_stack/types/agentic_system/turn.py +39 -0
  67. llama_stack/types/agentic_system/turn_create_params.py +36 -0
  68. llama_stack/types/agentic_system/turn_retrieve_params.py +13 -0
  69. llama_stack/types/agentic_system/turn_stream_event.py +98 -0
  70. llama_stack/types/agentic_system_create_params.py +191 -0
  71. llama_stack/types/agentic_system_create_response.py +11 -0
  72. llama_stack/types/agentic_system_delete_params.py +11 -0
  73. llama_stack/types/batch_chat_completion.py +12 -0
  74. llama_stack/types/batch_inference_chat_completion_params.py +57 -0
  75. llama_stack/types/batch_inference_completion_params.py +24 -0
  76. llama_stack/types/chat_completion_stream_chunk.py +41 -0
  77. llama_stack/types/completion_stream_chunk.py +17 -0
  78. llama_stack/types/custom_query_generator_config_param.py +11 -0
  79. llama_stack/types/dataset_create_params.py +15 -0
  80. llama_stack/types/dataset_delete_params.py +11 -0
  81. llama_stack/types/dataset_get_params.py +11 -0
  82. llama_stack/types/default_query_generator_config_param.py +13 -0
  83. llama_stack/types/evaluate/__init__.py +9 -0
  84. llama_stack/types/evaluate/evaluation_job_artifacts.py +11 -0
  85. llama_stack/types/evaluate/evaluation_job_log_stream.py +11 -0
  86. llama_stack/types/evaluate/evaluation_job_status.py +11 -0
  87. llama_stack/types/evaluate/job_cancel_params.py +11 -0
  88. llama_stack/types/evaluate/jobs/__init__.py +7 -0
  89. llama_stack/types/evaluate/jobs/artifact_list_params.py +11 -0
  90. llama_stack/types/evaluate/jobs/log_list_params.py +11 -0
  91. llama_stack/types/evaluate/jobs/status_list_params.py +11 -0
  92. llama_stack/types/evaluate/question_answering_create_params.py +12 -0
  93. llama_stack/types/evaluation_job.py +11 -0
  94. llama_stack/types/evaluation_summarization_params.py +12 -0
  95. llama_stack/types/evaluation_text_generation_params.py +12 -0
  96. llama_stack/types/inference/__init__.py +6 -0
  97. llama_stack/types/inference/embedding_create_params.py +14 -0
  98. llama_stack/types/inference/embeddings.py +11 -0
  99. llama_stack/types/inference_chat_completion_params.py +75 -0
  100. llama_stack/types/inference_chat_completion_response.py +20 -0
  101. llama_stack/types/inference_completion_params.py +26 -0
  102. llama_stack/types/inference_completion_response.py +20 -0
  103. llama_stack/types/inference_step.py +26 -0
  104. llama_stack/types/llm_query_generator_config_param.py +15 -0
  105. llama_stack/types/memory_bank_create_params.py +11 -0
  106. llama_stack/types/memory_bank_drop_params.py +11 -0
  107. llama_stack/types/memory_bank_drop_response.py +7 -0
  108. llama_stack/types/memory_bank_insert_params.py +26 -0
  109. llama_stack/types/memory_bank_query_params.py +16 -0
  110. llama_stack/types/memory_bank_retrieve_params.py +11 -0
  111. llama_stack/types/memory_bank_update_params.py +24 -0
  112. llama_stack/types/memory_banks/__init__.py +7 -0
  113. llama_stack/types/memory_banks/document_delete_params.py +14 -0
  114. llama_stack/types/memory_banks/document_retrieve_params.py +14 -0
  115. llama_stack/types/memory_banks/document_retrieve_response.py +17 -0
  116. llama_stack/types/memory_retrieval_step.py +25 -0
  117. llama_stack/types/post_training/__init__.py +11 -0
  118. llama_stack/types/post_training/job_artifacts_params.py +11 -0
  119. llama_stack/types/post_training/job_cancel_params.py +11 -0
  120. llama_stack/types/post_training/job_logs_params.py +11 -0
  121. llama_stack/types/post_training/job_status_params.py +11 -0
  122. llama_stack/types/post_training/post_training_job_artifacts.py +13 -0
  123. llama_stack/types/post_training/post_training_job_log_stream.py +13 -0
  124. llama_stack/types/post_training/post_training_job_status.py +25 -0
  125. llama_stack/types/post_training_job.py +11 -0
  126. llama_stack/types/post_training_preference_optimize_params.py +68 -0
  127. llama_stack/types/post_training_supervised_fine_tune_params.py +107 -0
  128. llama_stack/types/query_documents.py +21 -0
  129. llama_stack/types/rest_api_execution_config_param.py +20 -0
  130. llama_stack/types/reward_scoring.py +12 -0
  131. llama_stack/types/reward_scoring_score_params.py +35 -0
  132. llama_stack/types/safety_run_shields_params.py +23 -0
  133. llama_stack/types/safety_run_shields_response.py +12 -0
  134. llama_stack/types/scored_dialog_generations.py +28 -0
  135. llama_stack/types/shared/__init__.py +10 -0
  136. llama_stack/types/shared/attachment.py +13 -0
  137. llama_stack/types/shared/batch_completion.py +12 -0
  138. llama_stack/types/shared/completion_message.py +19 -0
  139. llama_stack/types/shared/sampling_params.py +22 -0
  140. llama_stack/types/shared/system_message.py +14 -0
  141. llama_stack/types/shared/tool_call.py +19 -0
  142. llama_stack/types/shared/tool_response_message.py +18 -0
  143. llama_stack/types/shared/user_message.py +16 -0
  144. llama_stack/types/shared_params/__init__.py +9 -0
  145. llama_stack/types/shared_params/attachment.py +14 -0
  146. llama_stack/types/shared_params/completion_message.py +20 -0
  147. llama_stack/types/shared_params/sampling_params.py +21 -0
  148. llama_stack/types/shared_params/system_message.py +14 -0
  149. llama_stack/types/shared_params/tool_call.py +23 -0
  150. llama_stack/types/shared_params/tool_response_message.py +18 -0
  151. llama_stack/types/shared_params/user_message.py +16 -0
  152. llama_stack/types/sheid_response.py +20 -0
  153. llama_stack/types/shield_call_step.py +24 -0
  154. llama_stack/types/shield_definition_param.py +28 -0
  155. llama_stack/types/synthetic_data_generation.py +14 -0
  156. llama_stack/types/synthetic_data_generation_generate_params.py +24 -0
  157. llama_stack/types/telemetry_get_trace_params.py +11 -0
  158. llama_stack/types/telemetry_get_trace_response.py +18 -0
  159. llama_stack/types/telemetry_log_params.py +94 -0
  160. llama_stack/types/token_log_probs.py +11 -0
  161. llama_stack/types/tool_execution_step.py +34 -0
  162. llama_stack/types/tool_param_definition_param.py +15 -0
  163. llama_stack/types/train_eval_dataset.py +16 -0
  164. llama_stack/types/train_eval_dataset_param.py +16 -0
  165. llama_stack_client-0.0.1a0.dist-info/METADATA +365 -0
  166. llama_stack_client-0.0.1a0.dist-info/RECORD +168 -0
  167. llama_stack_client-0.0.1a0.dist-info/WHEEL +4 -0
  168. llama_stack_client-0.0.1a0.dist-info/licenses/LICENSE +201 -0
llama_stack/_client.py ADDED
@@ -0,0 +1,518 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from typing import Any, Dict, Union, Mapping, cast
7
+ from typing_extensions import Self, Literal, override
8
+
9
+ import httpx
10
+
11
+ from . import resources, _exceptions
12
+ from ._qs import Querystring
13
+ from ._types import (
14
+ NOT_GIVEN,
15
+ Omit,
16
+ Timeout,
17
+ NotGiven,
18
+ Transport,
19
+ ProxiesTypes,
20
+ RequestOptions,
21
+ )
22
+ from ._utils import (
23
+ is_given,
24
+ get_async_library,
25
+ )
26
+ from ._version import __version__
27
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
28
+ from ._exceptions import APIStatusError
29
+ from ._base_client import (
30
+ DEFAULT_MAX_RETRIES,
31
+ SyncAPIClient,
32
+ AsyncAPIClient,
33
+ )
34
+
35
+ __all__ = [
36
+ "ENVIRONMENTS",
37
+ "Timeout",
38
+ "Transport",
39
+ "ProxiesTypes",
40
+ "RequestOptions",
41
+ "resources",
42
+ "LlamaStack",
43
+ "AsyncLlamaStack",
44
+ "Client",
45
+ "AsyncClient",
46
+ ]
47
+
48
+ ENVIRONMENTS: Dict[str, str] = {
49
+ "production": "http://any-hosted-llama-stack.com",
50
+ "sandbox": "https://example.com",
51
+ }
52
+
53
+
54
+ class LlamaStack(SyncAPIClient):
55
+ telemetry: resources.TelemetryResource
56
+ agentic_system: resources.AgenticSystemResource
57
+ datasets: resources.DatasetsResource
58
+ evaluate: resources.EvaluateResource
59
+ evaluations: resources.EvaluationsResource
60
+ inference: resources.InferenceResource
61
+ safety: resources.SafetyResource
62
+ memory_banks: resources.MemoryBanksResource
63
+ post_training: resources.PostTrainingResource
64
+ reward_scoring: resources.RewardScoringResource
65
+ synthetic_data_generation: resources.SyntheticDataGenerationResource
66
+ batch_inference: resources.BatchInferenceResource
67
+ with_raw_response: LlamaStackWithRawResponse
68
+ with_streaming_response: LlamaStackWithStreamedResponse
69
+
70
+ # client options
71
+
72
+ _environment: Literal["production", "sandbox"] | NotGiven
73
+
74
+ def __init__(
75
+ self,
76
+ *,
77
+ environment: Literal["production", "sandbox"] | NotGiven = NOT_GIVEN,
78
+ base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
79
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
80
+ max_retries: int = DEFAULT_MAX_RETRIES,
81
+ default_headers: Mapping[str, str] | None = None,
82
+ default_query: Mapping[str, object] | None = None,
83
+ # Configure a custom httpx client.
84
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
85
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
86
+ http_client: httpx.Client | None = None,
87
+ # Enable or disable schema validation for data returned by the API.
88
+ # When enabled an error APIResponseValidationError is raised
89
+ # if the API responds with invalid data for the expected schema.
90
+ #
91
+ # This parameter may be removed or changed in the future.
92
+ # If you rely on this feature, please open a GitHub issue
93
+ # outlining your use-case to help us decide if it should be
94
+ # part of our public interface in the future.
95
+ _strict_response_validation: bool = False,
96
+ ) -> None:
97
+ """Construct a new synchronous llama-stack client instance."""
98
+ self._environment = environment
99
+
100
+ base_url_env = os.environ.get("LLAMA_STACK_BASE_URL")
101
+ if is_given(base_url) and base_url is not None:
102
+ # cast required because mypy doesn't understand the type narrowing
103
+ base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
104
+ elif is_given(environment):
105
+ if base_url_env and base_url is not None:
106
+ raise ValueError(
107
+ "Ambiguous URL; The `LLAMA_STACK_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
108
+ )
109
+
110
+ try:
111
+ base_url = ENVIRONMENTS[environment]
112
+ except KeyError as exc:
113
+ raise ValueError(f"Unknown environment: {environment}") from exc
114
+ elif base_url_env is not None:
115
+ base_url = base_url_env
116
+ else:
117
+ self._environment = environment = "production"
118
+
119
+ try:
120
+ base_url = ENVIRONMENTS[environment]
121
+ except KeyError as exc:
122
+ raise ValueError(f"Unknown environment: {environment}") from exc
123
+
124
+ super().__init__(
125
+ version=__version__,
126
+ base_url=base_url,
127
+ max_retries=max_retries,
128
+ timeout=timeout,
129
+ http_client=http_client,
130
+ custom_headers=default_headers,
131
+ custom_query=default_query,
132
+ _strict_response_validation=_strict_response_validation,
133
+ )
134
+
135
+ self.telemetry = resources.TelemetryResource(self)
136
+ self.agentic_system = resources.AgenticSystemResource(self)
137
+ self.datasets = resources.DatasetsResource(self)
138
+ self.evaluate = resources.EvaluateResource(self)
139
+ self.evaluations = resources.EvaluationsResource(self)
140
+ self.inference = resources.InferenceResource(self)
141
+ self.safety = resources.SafetyResource(self)
142
+ self.memory_banks = resources.MemoryBanksResource(self)
143
+ self.post_training = resources.PostTrainingResource(self)
144
+ self.reward_scoring = resources.RewardScoringResource(self)
145
+ self.synthetic_data_generation = resources.SyntheticDataGenerationResource(self)
146
+ self.batch_inference = resources.BatchInferenceResource(self)
147
+ self.with_raw_response = LlamaStackWithRawResponse(self)
148
+ self.with_streaming_response = LlamaStackWithStreamedResponse(self)
149
+
150
+ @property
151
+ @override
152
+ def qs(self) -> Querystring:
153
+ return Querystring(array_format="comma")
154
+
155
+ @property
156
+ @override
157
+ def default_headers(self) -> dict[str, str | Omit]:
158
+ return {
159
+ **super().default_headers,
160
+ "X-Stainless-Async": "false",
161
+ **self._custom_headers,
162
+ }
163
+
164
+ def copy(
165
+ self,
166
+ *,
167
+ environment: Literal["production", "sandbox"] | None = None,
168
+ base_url: str | httpx.URL | None = None,
169
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
170
+ http_client: httpx.Client | None = None,
171
+ max_retries: int | NotGiven = NOT_GIVEN,
172
+ default_headers: Mapping[str, str] | None = None,
173
+ set_default_headers: Mapping[str, str] | None = None,
174
+ default_query: Mapping[str, object] | None = None,
175
+ set_default_query: Mapping[str, object] | None = None,
176
+ _extra_kwargs: Mapping[str, Any] = {},
177
+ ) -> Self:
178
+ """
179
+ Create a new client instance re-using the same options given to the current client with optional overriding.
180
+ """
181
+ if default_headers is not None and set_default_headers is not None:
182
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
183
+
184
+ if default_query is not None and set_default_query is not None:
185
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
186
+
187
+ headers = self._custom_headers
188
+ if default_headers is not None:
189
+ headers = {**headers, **default_headers}
190
+ elif set_default_headers is not None:
191
+ headers = set_default_headers
192
+
193
+ params = self._custom_query
194
+ if default_query is not None:
195
+ params = {**params, **default_query}
196
+ elif set_default_query is not None:
197
+ params = set_default_query
198
+
199
+ http_client = http_client or self._client
200
+ return self.__class__(
201
+ base_url=base_url or self.base_url,
202
+ environment=environment or self._environment,
203
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
204
+ http_client=http_client,
205
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
206
+ default_headers=headers,
207
+ default_query=params,
208
+ **_extra_kwargs,
209
+ )
210
+
211
+ # Alias for `copy` for nicer inline usage, e.g.
212
+ # client.with_options(timeout=10).foo.create(...)
213
+ with_options = copy
214
+
215
+ @override
216
+ def _make_status_error(
217
+ self,
218
+ err_msg: str,
219
+ *,
220
+ body: object,
221
+ response: httpx.Response,
222
+ ) -> APIStatusError:
223
+ if response.status_code == 400:
224
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
225
+
226
+ if response.status_code == 401:
227
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
228
+
229
+ if response.status_code == 403:
230
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
231
+
232
+ if response.status_code == 404:
233
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
234
+
235
+ if response.status_code == 409:
236
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
237
+
238
+ if response.status_code == 422:
239
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
240
+
241
+ if response.status_code == 429:
242
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
243
+
244
+ if response.status_code >= 500:
245
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
246
+ return APIStatusError(err_msg, response=response, body=body)
247
+
248
+
249
+ class AsyncLlamaStack(AsyncAPIClient):
250
+ telemetry: resources.AsyncTelemetryResource
251
+ agentic_system: resources.AsyncAgenticSystemResource
252
+ datasets: resources.AsyncDatasetsResource
253
+ evaluate: resources.AsyncEvaluateResource
254
+ evaluations: resources.AsyncEvaluationsResource
255
+ inference: resources.AsyncInferenceResource
256
+ safety: resources.AsyncSafetyResource
257
+ memory_banks: resources.AsyncMemoryBanksResource
258
+ post_training: resources.AsyncPostTrainingResource
259
+ reward_scoring: resources.AsyncRewardScoringResource
260
+ synthetic_data_generation: resources.AsyncSyntheticDataGenerationResource
261
+ batch_inference: resources.AsyncBatchInferenceResource
262
+ with_raw_response: AsyncLlamaStackWithRawResponse
263
+ with_streaming_response: AsyncLlamaStackWithStreamedResponse
264
+
265
+ # client options
266
+
267
+ _environment: Literal["production", "sandbox"] | NotGiven
268
+
269
+ def __init__(
270
+ self,
271
+ *,
272
+ environment: Literal["production", "sandbox"] | NotGiven = NOT_GIVEN,
273
+ base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
274
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
275
+ max_retries: int = DEFAULT_MAX_RETRIES,
276
+ default_headers: Mapping[str, str] | None = None,
277
+ default_query: Mapping[str, object] | None = None,
278
+ # Configure a custom httpx client.
279
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
280
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
281
+ http_client: httpx.AsyncClient | None = None,
282
+ # Enable or disable schema validation for data returned by the API.
283
+ # When enabled an error APIResponseValidationError is raised
284
+ # if the API responds with invalid data for the expected schema.
285
+ #
286
+ # This parameter may be removed or changed in the future.
287
+ # If you rely on this feature, please open a GitHub issue
288
+ # outlining your use-case to help us decide if it should be
289
+ # part of our public interface in the future.
290
+ _strict_response_validation: bool = False,
291
+ ) -> None:
292
+ """Construct a new async llama-stack client instance."""
293
+ self._environment = environment
294
+
295
+ base_url_env = os.environ.get("LLAMA_STACK_BASE_URL")
296
+ if is_given(base_url) and base_url is not None:
297
+ # cast required because mypy doesn't understand the type narrowing
298
+ base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
299
+ elif is_given(environment):
300
+ if base_url_env and base_url is not None:
301
+ raise ValueError(
302
+ "Ambiguous URL; The `LLAMA_STACK_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
303
+ )
304
+
305
+ try:
306
+ base_url = ENVIRONMENTS[environment]
307
+ except KeyError as exc:
308
+ raise ValueError(f"Unknown environment: {environment}") from exc
309
+ elif base_url_env is not None:
310
+ base_url = base_url_env
311
+ else:
312
+ self._environment = environment = "production"
313
+
314
+ try:
315
+ base_url = ENVIRONMENTS[environment]
316
+ except KeyError as exc:
317
+ raise ValueError(f"Unknown environment: {environment}") from exc
318
+
319
+ super().__init__(
320
+ version=__version__,
321
+ base_url=base_url,
322
+ max_retries=max_retries,
323
+ timeout=timeout,
324
+ http_client=http_client,
325
+ custom_headers=default_headers,
326
+ custom_query=default_query,
327
+ _strict_response_validation=_strict_response_validation,
328
+ )
329
+
330
+ self.telemetry = resources.AsyncTelemetryResource(self)
331
+ self.agentic_system = resources.AsyncAgenticSystemResource(self)
332
+ self.datasets = resources.AsyncDatasetsResource(self)
333
+ self.evaluate = resources.AsyncEvaluateResource(self)
334
+ self.evaluations = resources.AsyncEvaluationsResource(self)
335
+ self.inference = resources.AsyncInferenceResource(self)
336
+ self.safety = resources.AsyncSafetyResource(self)
337
+ self.memory_banks = resources.AsyncMemoryBanksResource(self)
338
+ self.post_training = resources.AsyncPostTrainingResource(self)
339
+ self.reward_scoring = resources.AsyncRewardScoringResource(self)
340
+ self.synthetic_data_generation = resources.AsyncSyntheticDataGenerationResource(self)
341
+ self.batch_inference = resources.AsyncBatchInferenceResource(self)
342
+ self.with_raw_response = AsyncLlamaStackWithRawResponse(self)
343
+ self.with_streaming_response = AsyncLlamaStackWithStreamedResponse(self)
344
+
345
+ @property
346
+ @override
347
+ def qs(self) -> Querystring:
348
+ return Querystring(array_format="comma")
349
+
350
+ @property
351
+ @override
352
+ def default_headers(self) -> dict[str, str | Omit]:
353
+ return {
354
+ **super().default_headers,
355
+ "X-Stainless-Async": f"async:{get_async_library()}",
356
+ **self._custom_headers,
357
+ }
358
+
359
+ def copy(
360
+ self,
361
+ *,
362
+ environment: Literal["production", "sandbox"] | None = None,
363
+ base_url: str | httpx.URL | None = None,
364
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
365
+ http_client: httpx.AsyncClient | None = None,
366
+ max_retries: int | NotGiven = NOT_GIVEN,
367
+ default_headers: Mapping[str, str] | None = None,
368
+ set_default_headers: Mapping[str, str] | None = None,
369
+ default_query: Mapping[str, object] | None = None,
370
+ set_default_query: Mapping[str, object] | None = None,
371
+ _extra_kwargs: Mapping[str, Any] = {},
372
+ ) -> Self:
373
+ """
374
+ Create a new client instance re-using the same options given to the current client with optional overriding.
375
+ """
376
+ if default_headers is not None and set_default_headers is not None:
377
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
378
+
379
+ if default_query is not None and set_default_query is not None:
380
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
381
+
382
+ headers = self._custom_headers
383
+ if default_headers is not None:
384
+ headers = {**headers, **default_headers}
385
+ elif set_default_headers is not None:
386
+ headers = set_default_headers
387
+
388
+ params = self._custom_query
389
+ if default_query is not None:
390
+ params = {**params, **default_query}
391
+ elif set_default_query is not None:
392
+ params = set_default_query
393
+
394
+ http_client = http_client or self._client
395
+ return self.__class__(
396
+ base_url=base_url or self.base_url,
397
+ environment=environment or self._environment,
398
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
399
+ http_client=http_client,
400
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
401
+ default_headers=headers,
402
+ default_query=params,
403
+ **_extra_kwargs,
404
+ )
405
+
406
+ # Alias for `copy` for nicer inline usage, e.g.
407
+ # client.with_options(timeout=10).foo.create(...)
408
+ with_options = copy
409
+
410
+ @override
411
+ def _make_status_error(
412
+ self,
413
+ err_msg: str,
414
+ *,
415
+ body: object,
416
+ response: httpx.Response,
417
+ ) -> APIStatusError:
418
+ if response.status_code == 400:
419
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
420
+
421
+ if response.status_code == 401:
422
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
423
+
424
+ if response.status_code == 403:
425
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
426
+
427
+ if response.status_code == 404:
428
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
429
+
430
+ if response.status_code == 409:
431
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
432
+
433
+ if response.status_code == 422:
434
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
435
+
436
+ if response.status_code == 429:
437
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
438
+
439
+ if response.status_code >= 500:
440
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
441
+ return APIStatusError(err_msg, response=response, body=body)
442
+
443
+
444
+ class LlamaStackWithRawResponse:
445
+ def __init__(self, client: LlamaStack) -> None:
446
+ self.telemetry = resources.TelemetryResourceWithRawResponse(client.telemetry)
447
+ self.agentic_system = resources.AgenticSystemResourceWithRawResponse(client.agentic_system)
448
+ self.datasets = resources.DatasetsResourceWithRawResponse(client.datasets)
449
+ self.evaluate = resources.EvaluateResourceWithRawResponse(client.evaluate)
450
+ self.evaluations = resources.EvaluationsResourceWithRawResponse(client.evaluations)
451
+ self.inference = resources.InferenceResourceWithRawResponse(client.inference)
452
+ self.safety = resources.SafetyResourceWithRawResponse(client.safety)
453
+ self.memory_banks = resources.MemoryBanksResourceWithRawResponse(client.memory_banks)
454
+ self.post_training = resources.PostTrainingResourceWithRawResponse(client.post_training)
455
+ self.reward_scoring = resources.RewardScoringResourceWithRawResponse(client.reward_scoring)
456
+ self.synthetic_data_generation = resources.SyntheticDataGenerationResourceWithRawResponse(
457
+ client.synthetic_data_generation
458
+ )
459
+ self.batch_inference = resources.BatchInferenceResourceWithRawResponse(client.batch_inference)
460
+
461
+
462
+ class AsyncLlamaStackWithRawResponse:
463
+ def __init__(self, client: AsyncLlamaStack) -> None:
464
+ self.telemetry = resources.AsyncTelemetryResourceWithRawResponse(client.telemetry)
465
+ self.agentic_system = resources.AsyncAgenticSystemResourceWithRawResponse(client.agentic_system)
466
+ self.datasets = resources.AsyncDatasetsResourceWithRawResponse(client.datasets)
467
+ self.evaluate = resources.AsyncEvaluateResourceWithRawResponse(client.evaluate)
468
+ self.evaluations = resources.AsyncEvaluationsResourceWithRawResponse(client.evaluations)
469
+ self.inference = resources.AsyncInferenceResourceWithRawResponse(client.inference)
470
+ self.safety = resources.AsyncSafetyResourceWithRawResponse(client.safety)
471
+ self.memory_banks = resources.AsyncMemoryBanksResourceWithRawResponse(client.memory_banks)
472
+ self.post_training = resources.AsyncPostTrainingResourceWithRawResponse(client.post_training)
473
+ self.reward_scoring = resources.AsyncRewardScoringResourceWithRawResponse(client.reward_scoring)
474
+ self.synthetic_data_generation = resources.AsyncSyntheticDataGenerationResourceWithRawResponse(
475
+ client.synthetic_data_generation
476
+ )
477
+ self.batch_inference = resources.AsyncBatchInferenceResourceWithRawResponse(client.batch_inference)
478
+
479
+
480
+ class LlamaStackWithStreamedResponse:
481
+ def __init__(self, client: LlamaStack) -> None:
482
+ self.telemetry = resources.TelemetryResourceWithStreamingResponse(client.telemetry)
483
+ self.agentic_system = resources.AgenticSystemResourceWithStreamingResponse(client.agentic_system)
484
+ self.datasets = resources.DatasetsResourceWithStreamingResponse(client.datasets)
485
+ self.evaluate = resources.EvaluateResourceWithStreamingResponse(client.evaluate)
486
+ self.evaluations = resources.EvaluationsResourceWithStreamingResponse(client.evaluations)
487
+ self.inference = resources.InferenceResourceWithStreamingResponse(client.inference)
488
+ self.safety = resources.SafetyResourceWithStreamingResponse(client.safety)
489
+ self.memory_banks = resources.MemoryBanksResourceWithStreamingResponse(client.memory_banks)
490
+ self.post_training = resources.PostTrainingResourceWithStreamingResponse(client.post_training)
491
+ self.reward_scoring = resources.RewardScoringResourceWithStreamingResponse(client.reward_scoring)
492
+ self.synthetic_data_generation = resources.SyntheticDataGenerationResourceWithStreamingResponse(
493
+ client.synthetic_data_generation
494
+ )
495
+ self.batch_inference = resources.BatchInferenceResourceWithStreamingResponse(client.batch_inference)
496
+
497
+
498
+ class AsyncLlamaStackWithStreamedResponse:
499
+ def __init__(self, client: AsyncLlamaStack) -> None:
500
+ self.telemetry = resources.AsyncTelemetryResourceWithStreamingResponse(client.telemetry)
501
+ self.agentic_system = resources.AsyncAgenticSystemResourceWithStreamingResponse(client.agentic_system)
502
+ self.datasets = resources.AsyncDatasetsResourceWithStreamingResponse(client.datasets)
503
+ self.evaluate = resources.AsyncEvaluateResourceWithStreamingResponse(client.evaluate)
504
+ self.evaluations = resources.AsyncEvaluationsResourceWithStreamingResponse(client.evaluations)
505
+ self.inference = resources.AsyncInferenceResourceWithStreamingResponse(client.inference)
506
+ self.safety = resources.AsyncSafetyResourceWithStreamingResponse(client.safety)
507
+ self.memory_banks = resources.AsyncMemoryBanksResourceWithStreamingResponse(client.memory_banks)
508
+ self.post_training = resources.AsyncPostTrainingResourceWithStreamingResponse(client.post_training)
509
+ self.reward_scoring = resources.AsyncRewardScoringResourceWithStreamingResponse(client.reward_scoring)
510
+ self.synthetic_data_generation = resources.AsyncSyntheticDataGenerationResourceWithStreamingResponse(
511
+ client.synthetic_data_generation
512
+ )
513
+ self.batch_inference = resources.AsyncBatchInferenceResourceWithStreamingResponse(client.batch_inference)
514
+
515
+
516
+ Client = LlamaStack
517
+
518
+ AsyncClient = AsyncLlamaStack