parallel-web 0.1.2__py3-none-any.whl → 0.2.0__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.
Potentially problematic release.
This version of parallel-web might be problematic. Click here for more details.
- parallel/__init__.py +2 -1
- parallel/_base_client.py +34 -2
- parallel/_client.py +9 -0
- parallel/_compat.py +1 -0
- parallel/_constants.py +2 -0
- parallel/_files.py +4 -4
- parallel/_models.py +32 -8
- parallel/_types.py +35 -1
- parallel/_utils/__init__.py +1 -0
- parallel/_utils/_typing.py +5 -0
- parallel/_version.py +1 -1
- parallel/lib/_pydantic.py +1 -0
- parallel/lib/_time.py +2 -2
- parallel/resources/__init__.py +14 -0
- parallel/resources/beta/__init__.py +47 -0
- parallel/resources/beta/beta.py +301 -0
- parallel/resources/beta/task_group.py +632 -0
- parallel/resources/beta/task_run.py +499 -0
- parallel/resources/task_run.py +47 -18
- parallel/types/__init__.py +15 -0
- parallel/types/auto_schema.py +13 -0
- parallel/types/auto_schema_param.py +12 -0
- parallel/types/beta/__init__.py +30 -0
- parallel/types/beta/beta_run_input.py +63 -0
- parallel/types/beta/beta_run_input_param.py +65 -0
- parallel/types/beta/beta_search_params.py +47 -0
- parallel/types/beta/beta_task_run_result.py +74 -0
- parallel/types/beta/error_event.py +16 -0
- parallel/types/beta/mcp_server.py +25 -0
- parallel/types/beta/mcp_server_param.py +25 -0
- parallel/types/beta/mcp_tool_call.py +27 -0
- parallel/types/beta/parallel_beta_param.py +12 -0
- parallel/types/beta/search_result.py +16 -0
- parallel/types/beta/task_group.py +24 -0
- parallel/types/beta/task_group_add_runs_params.py +30 -0
- parallel/types/beta/task_group_create_params.py +13 -0
- parallel/types/beta/task_group_events_params.py +16 -0
- parallel/types/beta/task_group_events_response.py +28 -0
- parallel/types/beta/task_group_get_runs_params.py +18 -0
- parallel/types/beta/task_group_get_runs_response.py +12 -0
- parallel/types/beta/task_group_run_response.py +30 -0
- parallel/types/beta/task_group_status.py +27 -0
- parallel/types/beta/task_run_create_params.py +70 -0
- parallel/types/beta/task_run_event.py +32 -0
- parallel/types/beta/task_run_events_response.py +58 -0
- parallel/types/beta/task_run_result_params.py +18 -0
- parallel/types/beta/web_search_result.py +18 -0
- parallel/types/beta/webhook.py +16 -0
- parallel/types/beta/webhook_param.py +16 -0
- parallel/types/citation.py +21 -0
- parallel/types/field_basis.py +25 -0
- parallel/types/json_schema.py +16 -0
- parallel/types/json_schema_param.py +2 -1
- parallel/types/parsed_task_run_result.py +13 -4
- parallel/types/shared/__init__.py +6 -0
- parallel/types/shared/error_object.py +18 -0
- parallel/types/shared/error_response.py +16 -0
- parallel/types/shared/source_policy.py +21 -0
- parallel/types/shared/warning.py +22 -0
- parallel/types/shared_params/__init__.py +3 -0
- parallel/types/shared_params/source_policy.py +22 -0
- parallel/types/task_run.py +17 -18
- parallel/types/task_run_create_params.py +12 -3
- parallel/types/task_run_json_output.py +46 -0
- parallel/types/task_run_result.py +24 -94
- parallel/types/task_run_text_output.py +37 -0
- parallel/types/task_spec.py +31 -0
- parallel/types/task_spec_param.py +3 -2
- parallel/types/text_schema.py +16 -0
- {parallel_web-0.1.2.dist-info → parallel_web-0.2.0.dist-info}/METADATA +48 -136
- parallel_web-0.2.0.dist-info/RECORD +94 -0
- parallel_web-0.1.2.dist-info/RECORD +0 -47
- {parallel_web-0.1.2.dist-info → parallel_web-0.2.0.dist-info}/WHEEL +0 -0
- {parallel_web-0.1.2.dist-info → parallel_web-0.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List, Union, Iterable, Optional, cast
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
|
10
|
+
from ..._utils import is_given, maybe_transform, strip_not_given, async_maybe_transform
|
|
11
|
+
from ..._compat import cached_property
|
|
12
|
+
from ..._resource import SyncAPIResource, AsyncAPIResource
|
|
13
|
+
from ..._response import (
|
|
14
|
+
to_raw_response_wrapper,
|
|
15
|
+
to_streamed_response_wrapper,
|
|
16
|
+
async_to_raw_response_wrapper,
|
|
17
|
+
async_to_streamed_response_wrapper,
|
|
18
|
+
)
|
|
19
|
+
from ..._streaming import Stream, AsyncStream
|
|
20
|
+
from ...types.beta import task_run_create_params, task_run_result_params
|
|
21
|
+
from ..._base_client import make_request_options
|
|
22
|
+
from ...types.task_run import TaskRun
|
|
23
|
+
from ...types.task_spec_param import TaskSpecParam
|
|
24
|
+
from ...types.beta.webhook_param import WebhookParam
|
|
25
|
+
from ...types.beta.mcp_server_param import McpServerParam
|
|
26
|
+
from ...types.beta.parallel_beta_param import ParallelBetaParam
|
|
27
|
+
from ...types.beta.beta_task_run_result import BetaTaskRunResult
|
|
28
|
+
from ...types.shared_params.source_policy import SourcePolicy
|
|
29
|
+
from ...types.beta.task_run_events_response import TaskRunEventsResponse
|
|
30
|
+
|
|
31
|
+
__all__ = ["TaskRunResource", "AsyncTaskRunResource"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TaskRunResource(SyncAPIResource):
|
|
35
|
+
@cached_property
|
|
36
|
+
def with_raw_response(self) -> TaskRunResourceWithRawResponse:
|
|
37
|
+
"""
|
|
38
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
39
|
+
the raw response object instead of the parsed content.
|
|
40
|
+
|
|
41
|
+
For more information, see https://www.github.com/parallel-web/parallel-sdk-python#accessing-raw-response-data-eg-headers
|
|
42
|
+
"""
|
|
43
|
+
return TaskRunResourceWithRawResponse(self)
|
|
44
|
+
|
|
45
|
+
@cached_property
|
|
46
|
+
def with_streaming_response(self) -> TaskRunResourceWithStreamingResponse:
|
|
47
|
+
"""
|
|
48
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
49
|
+
|
|
50
|
+
For more information, see https://www.github.com/parallel-web/parallel-sdk-python#with_streaming_response
|
|
51
|
+
"""
|
|
52
|
+
return TaskRunResourceWithStreamingResponse(self)
|
|
53
|
+
|
|
54
|
+
def create(
|
|
55
|
+
self,
|
|
56
|
+
*,
|
|
57
|
+
input: Union[str, Dict[str, object]],
|
|
58
|
+
processor: str,
|
|
59
|
+
enable_events: Optional[bool] | NotGiven = NOT_GIVEN,
|
|
60
|
+
mcp_servers: Optional[Iterable[McpServerParam]] | NotGiven = NOT_GIVEN,
|
|
61
|
+
metadata: Optional[Dict[str, Union[str, float, bool]]] | NotGiven = NOT_GIVEN,
|
|
62
|
+
source_policy: Optional[SourcePolicy] | NotGiven = NOT_GIVEN,
|
|
63
|
+
task_spec: Optional[TaskSpecParam] | NotGiven = NOT_GIVEN,
|
|
64
|
+
webhook: Optional[WebhookParam] | NotGiven = NOT_GIVEN,
|
|
65
|
+
betas: List[ParallelBetaParam] | NotGiven = NOT_GIVEN,
|
|
66
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
67
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
68
|
+
extra_headers: Headers | None = None,
|
|
69
|
+
extra_query: Query | None = None,
|
|
70
|
+
extra_body: Body | None = None,
|
|
71
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
72
|
+
) -> TaskRun:
|
|
73
|
+
"""
|
|
74
|
+
Initiates a task run.
|
|
75
|
+
|
|
76
|
+
Returns immediately with a run object in status 'queued'.
|
|
77
|
+
|
|
78
|
+
Beta features can be enabled by setting the 'parallel-beta' header.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
input: Input to the task, either text or a JSON object.
|
|
82
|
+
|
|
83
|
+
processor: Processor to use for the task.
|
|
84
|
+
|
|
85
|
+
enable_events: Controls tracking of task run execution progress. When set to true, progress
|
|
86
|
+
events are recorded and can be accessed via the
|
|
87
|
+
[Task Run events](https://platform.parallel.ai/api-reference) endpoint. When
|
|
88
|
+
false, no progress events are tracked. Note that progress tracking cannot be
|
|
89
|
+
enabled after a run has been created. The flag is set to true by default for
|
|
90
|
+
premium processors (pro and above). This feature is not available via the Python
|
|
91
|
+
SDK. To enable this feature in your API requests, specify the `parallel-beta`
|
|
92
|
+
header with `events-sse-2025-07-24` value.
|
|
93
|
+
|
|
94
|
+
mcp_servers: Optional list of MCP servers to use for the run. This feature is not available
|
|
95
|
+
via the Python SDK. To enable this feature in your API requests, specify the
|
|
96
|
+
`parallel-beta` header with `mcp-server-2025-07-17` value.
|
|
97
|
+
|
|
98
|
+
metadata: User-provided metadata stored with the run. Keys and values must be strings with
|
|
99
|
+
a maximum length of 16 and 512 characters respectively.
|
|
100
|
+
|
|
101
|
+
source_policy: Source policy for web search results.
|
|
102
|
+
|
|
103
|
+
This policy governs which sources are allowed/disallowed in results.
|
|
104
|
+
|
|
105
|
+
task_spec: Specification for a task.
|
|
106
|
+
|
|
107
|
+
Auto output schemas can be specified by setting `output_schema={"type":"auto"}`.
|
|
108
|
+
Not specifying a TaskSpec is the same as setting an auto output schema.
|
|
109
|
+
|
|
110
|
+
For convenience bare strings are also accepted as input or output schemas.
|
|
111
|
+
|
|
112
|
+
webhook: Webhooks for Task Runs.
|
|
113
|
+
|
|
114
|
+
betas: Optional header to specify the beta version(s) to enable.
|
|
115
|
+
|
|
116
|
+
extra_headers: Send extra headers
|
|
117
|
+
|
|
118
|
+
extra_query: Add additional query parameters to the request
|
|
119
|
+
|
|
120
|
+
extra_body: Add additional JSON properties to the request
|
|
121
|
+
|
|
122
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
123
|
+
"""
|
|
124
|
+
extra_headers = {
|
|
125
|
+
**strip_not_given({"parallel-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
|
|
126
|
+
**(extra_headers or {}),
|
|
127
|
+
}
|
|
128
|
+
return self._post(
|
|
129
|
+
"/v1/tasks/runs?beta=true",
|
|
130
|
+
body=maybe_transform(
|
|
131
|
+
{
|
|
132
|
+
"input": input,
|
|
133
|
+
"processor": processor,
|
|
134
|
+
"enable_events": enable_events,
|
|
135
|
+
"mcp_servers": mcp_servers,
|
|
136
|
+
"metadata": metadata,
|
|
137
|
+
"source_policy": source_policy,
|
|
138
|
+
"task_spec": task_spec,
|
|
139
|
+
"webhook": webhook,
|
|
140
|
+
},
|
|
141
|
+
task_run_create_params.TaskRunCreateParams,
|
|
142
|
+
),
|
|
143
|
+
options=make_request_options(
|
|
144
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
145
|
+
),
|
|
146
|
+
cast_to=TaskRun,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def events(
|
|
150
|
+
self,
|
|
151
|
+
run_id: str,
|
|
152
|
+
*,
|
|
153
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
154
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
155
|
+
extra_headers: Headers | None = None,
|
|
156
|
+
extra_query: Query | None = None,
|
|
157
|
+
extra_body: Body | None = None,
|
|
158
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
159
|
+
) -> Stream[TaskRunEventsResponse]:
|
|
160
|
+
"""
|
|
161
|
+
Streams events for a task run.
|
|
162
|
+
|
|
163
|
+
Returns a stream of events showing progress updates and state changes for the
|
|
164
|
+
task run.
|
|
165
|
+
|
|
166
|
+
For task runs that did not have enable_events set to true during creation, the
|
|
167
|
+
frequency of events will be reduced.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
extra_headers: Send extra headers
|
|
171
|
+
|
|
172
|
+
extra_query: Add additional query parameters to the request
|
|
173
|
+
|
|
174
|
+
extra_body: Add additional JSON properties to the request
|
|
175
|
+
|
|
176
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
177
|
+
"""
|
|
178
|
+
if not run_id:
|
|
179
|
+
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
|
180
|
+
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
|
|
181
|
+
return self._get(
|
|
182
|
+
f"/v1beta/tasks/runs/{run_id}/events",
|
|
183
|
+
options=make_request_options(
|
|
184
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
185
|
+
),
|
|
186
|
+
cast_to=cast(Any, TaskRunEventsResponse), # Union types cannot be passed in as arguments in the type system
|
|
187
|
+
stream=True,
|
|
188
|
+
stream_cls=Stream[TaskRunEventsResponse],
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
def result(
|
|
192
|
+
self,
|
|
193
|
+
run_id: str,
|
|
194
|
+
*,
|
|
195
|
+
api_timeout: int | NotGiven = NOT_GIVEN,
|
|
196
|
+
betas: List[ParallelBetaParam] | NotGiven = NOT_GIVEN,
|
|
197
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
198
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
199
|
+
extra_headers: Headers | None = None,
|
|
200
|
+
extra_query: Query | None = None,
|
|
201
|
+
extra_body: Body | None = None,
|
|
202
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
203
|
+
) -> BetaTaskRunResult:
|
|
204
|
+
"""
|
|
205
|
+
Retrieves a run result by run_id, blocking until the run is completed.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
betas: Optional header to specify the beta version(s) to enable.
|
|
209
|
+
|
|
210
|
+
extra_headers: Send extra headers
|
|
211
|
+
|
|
212
|
+
extra_query: Add additional query parameters to the request
|
|
213
|
+
|
|
214
|
+
extra_body: Add additional JSON properties to the request
|
|
215
|
+
|
|
216
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
217
|
+
"""
|
|
218
|
+
if not run_id:
|
|
219
|
+
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
|
220
|
+
extra_headers = {
|
|
221
|
+
**strip_not_given({"parallel-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
|
|
222
|
+
**(extra_headers or {}),
|
|
223
|
+
}
|
|
224
|
+
return self._get(
|
|
225
|
+
f"/v1/tasks/runs/{run_id}/result?beta=true",
|
|
226
|
+
options=make_request_options(
|
|
227
|
+
extra_headers=extra_headers,
|
|
228
|
+
extra_query=extra_query,
|
|
229
|
+
extra_body=extra_body,
|
|
230
|
+
timeout=timeout,
|
|
231
|
+
query=maybe_transform({"api_timeout": api_timeout}, task_run_result_params.TaskRunResultParams),
|
|
232
|
+
),
|
|
233
|
+
cast_to=BetaTaskRunResult,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class AsyncTaskRunResource(AsyncAPIResource):
|
|
238
|
+
@cached_property
|
|
239
|
+
def with_raw_response(self) -> AsyncTaskRunResourceWithRawResponse:
|
|
240
|
+
"""
|
|
241
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
242
|
+
the raw response object instead of the parsed content.
|
|
243
|
+
|
|
244
|
+
For more information, see https://www.github.com/parallel-web/parallel-sdk-python#accessing-raw-response-data-eg-headers
|
|
245
|
+
"""
|
|
246
|
+
return AsyncTaskRunResourceWithRawResponse(self)
|
|
247
|
+
|
|
248
|
+
@cached_property
|
|
249
|
+
def with_streaming_response(self) -> AsyncTaskRunResourceWithStreamingResponse:
|
|
250
|
+
"""
|
|
251
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
252
|
+
|
|
253
|
+
For more information, see https://www.github.com/parallel-web/parallel-sdk-python#with_streaming_response
|
|
254
|
+
"""
|
|
255
|
+
return AsyncTaskRunResourceWithStreamingResponse(self)
|
|
256
|
+
|
|
257
|
+
async def create(
|
|
258
|
+
self,
|
|
259
|
+
*,
|
|
260
|
+
input: Union[str, Dict[str, object]],
|
|
261
|
+
processor: str,
|
|
262
|
+
enable_events: Optional[bool] | NotGiven = NOT_GIVEN,
|
|
263
|
+
mcp_servers: Optional[Iterable[McpServerParam]] | NotGiven = NOT_GIVEN,
|
|
264
|
+
metadata: Optional[Dict[str, Union[str, float, bool]]] | NotGiven = NOT_GIVEN,
|
|
265
|
+
source_policy: Optional[SourcePolicy] | NotGiven = NOT_GIVEN,
|
|
266
|
+
task_spec: Optional[TaskSpecParam] | NotGiven = NOT_GIVEN,
|
|
267
|
+
webhook: Optional[WebhookParam] | NotGiven = NOT_GIVEN,
|
|
268
|
+
betas: List[ParallelBetaParam] | NotGiven = NOT_GIVEN,
|
|
269
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
270
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
271
|
+
extra_headers: Headers | None = None,
|
|
272
|
+
extra_query: Query | None = None,
|
|
273
|
+
extra_body: Body | None = None,
|
|
274
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
275
|
+
) -> TaskRun:
|
|
276
|
+
"""
|
|
277
|
+
Initiates a task run.
|
|
278
|
+
|
|
279
|
+
Returns immediately with a run object in status 'queued'.
|
|
280
|
+
|
|
281
|
+
Beta features can be enabled by setting the 'parallel-beta' header.
|
|
282
|
+
|
|
283
|
+
Args:
|
|
284
|
+
input: Input to the task, either text or a JSON object.
|
|
285
|
+
|
|
286
|
+
processor: Processor to use for the task.
|
|
287
|
+
|
|
288
|
+
enable_events: Controls tracking of task run execution progress. When set to true, progress
|
|
289
|
+
events are recorded and can be accessed via the
|
|
290
|
+
[Task Run events](https://platform.parallel.ai/api-reference) endpoint. When
|
|
291
|
+
false, no progress events are tracked. Note that progress tracking cannot be
|
|
292
|
+
enabled after a run has been created. The flag is set to true by default for
|
|
293
|
+
premium processors (pro and above). This feature is not available via the Python
|
|
294
|
+
SDK. To enable this feature in your API requests, specify the `parallel-beta`
|
|
295
|
+
header with `events-sse-2025-07-24` value.
|
|
296
|
+
|
|
297
|
+
mcp_servers: Optional list of MCP servers to use for the run. This feature is not available
|
|
298
|
+
via the Python SDK. To enable this feature in your API requests, specify the
|
|
299
|
+
`parallel-beta` header with `mcp-server-2025-07-17` value.
|
|
300
|
+
|
|
301
|
+
metadata: User-provided metadata stored with the run. Keys and values must be strings with
|
|
302
|
+
a maximum length of 16 and 512 characters respectively.
|
|
303
|
+
|
|
304
|
+
source_policy: Source policy for web search results.
|
|
305
|
+
|
|
306
|
+
This policy governs which sources are allowed/disallowed in results.
|
|
307
|
+
|
|
308
|
+
task_spec: Specification for a task.
|
|
309
|
+
|
|
310
|
+
Auto output schemas can be specified by setting `output_schema={"type":"auto"}`.
|
|
311
|
+
Not specifying a TaskSpec is the same as setting an auto output schema.
|
|
312
|
+
|
|
313
|
+
For convenience bare strings are also accepted as input or output schemas.
|
|
314
|
+
|
|
315
|
+
webhook: Webhooks for Task Runs.
|
|
316
|
+
|
|
317
|
+
betas: Optional header to specify the beta version(s) to enable.
|
|
318
|
+
|
|
319
|
+
extra_headers: Send extra headers
|
|
320
|
+
|
|
321
|
+
extra_query: Add additional query parameters to the request
|
|
322
|
+
|
|
323
|
+
extra_body: Add additional JSON properties to the request
|
|
324
|
+
|
|
325
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
326
|
+
"""
|
|
327
|
+
extra_headers = {
|
|
328
|
+
**strip_not_given({"parallel-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
|
|
329
|
+
**(extra_headers or {}),
|
|
330
|
+
}
|
|
331
|
+
return await self._post(
|
|
332
|
+
"/v1/tasks/runs?beta=true",
|
|
333
|
+
body=await async_maybe_transform(
|
|
334
|
+
{
|
|
335
|
+
"input": input,
|
|
336
|
+
"processor": processor,
|
|
337
|
+
"enable_events": enable_events,
|
|
338
|
+
"mcp_servers": mcp_servers,
|
|
339
|
+
"metadata": metadata,
|
|
340
|
+
"source_policy": source_policy,
|
|
341
|
+
"task_spec": task_spec,
|
|
342
|
+
"webhook": webhook,
|
|
343
|
+
},
|
|
344
|
+
task_run_create_params.TaskRunCreateParams,
|
|
345
|
+
),
|
|
346
|
+
options=make_request_options(
|
|
347
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
348
|
+
),
|
|
349
|
+
cast_to=TaskRun,
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
async def events(
|
|
353
|
+
self,
|
|
354
|
+
run_id: str,
|
|
355
|
+
*,
|
|
356
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
357
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
358
|
+
extra_headers: Headers | None = None,
|
|
359
|
+
extra_query: Query | None = None,
|
|
360
|
+
extra_body: Body | None = None,
|
|
361
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
362
|
+
) -> AsyncStream[TaskRunEventsResponse]:
|
|
363
|
+
"""
|
|
364
|
+
Streams events for a task run.
|
|
365
|
+
|
|
366
|
+
Returns a stream of events showing progress updates and state changes for the
|
|
367
|
+
task run.
|
|
368
|
+
|
|
369
|
+
For task runs that did not have enable_events set to true during creation, the
|
|
370
|
+
frequency of events will be reduced.
|
|
371
|
+
|
|
372
|
+
Args:
|
|
373
|
+
extra_headers: Send extra headers
|
|
374
|
+
|
|
375
|
+
extra_query: Add additional query parameters to the request
|
|
376
|
+
|
|
377
|
+
extra_body: Add additional JSON properties to the request
|
|
378
|
+
|
|
379
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
380
|
+
"""
|
|
381
|
+
if not run_id:
|
|
382
|
+
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
|
383
|
+
extra_headers = {"Accept": "text/event-stream", **(extra_headers or {})}
|
|
384
|
+
return await self._get(
|
|
385
|
+
f"/v1beta/tasks/runs/{run_id}/events",
|
|
386
|
+
options=make_request_options(
|
|
387
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
388
|
+
),
|
|
389
|
+
cast_to=cast(Any, TaskRunEventsResponse), # Union types cannot be passed in as arguments in the type system
|
|
390
|
+
stream=True,
|
|
391
|
+
stream_cls=AsyncStream[TaskRunEventsResponse],
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
async def result(
|
|
395
|
+
self,
|
|
396
|
+
run_id: str,
|
|
397
|
+
*,
|
|
398
|
+
api_timeout: int | NotGiven = NOT_GIVEN,
|
|
399
|
+
betas: List[ParallelBetaParam] | NotGiven = NOT_GIVEN,
|
|
400
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
401
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
402
|
+
extra_headers: Headers | None = None,
|
|
403
|
+
extra_query: Query | None = None,
|
|
404
|
+
extra_body: Body | None = None,
|
|
405
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
406
|
+
) -> BetaTaskRunResult:
|
|
407
|
+
"""
|
|
408
|
+
Retrieves a run result by run_id, blocking until the run is completed.
|
|
409
|
+
|
|
410
|
+
Args:
|
|
411
|
+
betas: Optional header to specify the beta version(s) to enable.
|
|
412
|
+
|
|
413
|
+
extra_headers: Send extra headers
|
|
414
|
+
|
|
415
|
+
extra_query: Add additional query parameters to the request
|
|
416
|
+
|
|
417
|
+
extra_body: Add additional JSON properties to the request
|
|
418
|
+
|
|
419
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
420
|
+
"""
|
|
421
|
+
if not run_id:
|
|
422
|
+
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
|
423
|
+
extra_headers = {
|
|
424
|
+
**strip_not_given({"parallel-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
|
|
425
|
+
**(extra_headers or {}),
|
|
426
|
+
}
|
|
427
|
+
return await self._get(
|
|
428
|
+
f"/v1/tasks/runs/{run_id}/result?beta=true",
|
|
429
|
+
options=make_request_options(
|
|
430
|
+
extra_headers=extra_headers,
|
|
431
|
+
extra_query=extra_query,
|
|
432
|
+
extra_body=extra_body,
|
|
433
|
+
timeout=timeout,
|
|
434
|
+
query=await async_maybe_transform(
|
|
435
|
+
{"api_timeout": api_timeout}, task_run_result_params.TaskRunResultParams
|
|
436
|
+
),
|
|
437
|
+
),
|
|
438
|
+
cast_to=BetaTaskRunResult,
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
class TaskRunResourceWithRawResponse:
|
|
443
|
+
def __init__(self, task_run: TaskRunResource) -> None:
|
|
444
|
+
self._task_run = task_run
|
|
445
|
+
|
|
446
|
+
self.create = to_raw_response_wrapper(
|
|
447
|
+
task_run.create,
|
|
448
|
+
)
|
|
449
|
+
self.events = to_raw_response_wrapper(
|
|
450
|
+
task_run.events,
|
|
451
|
+
)
|
|
452
|
+
self.result = to_raw_response_wrapper(
|
|
453
|
+
task_run.result,
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
class AsyncTaskRunResourceWithRawResponse:
|
|
458
|
+
def __init__(self, task_run: AsyncTaskRunResource) -> None:
|
|
459
|
+
self._task_run = task_run
|
|
460
|
+
|
|
461
|
+
self.create = async_to_raw_response_wrapper(
|
|
462
|
+
task_run.create,
|
|
463
|
+
)
|
|
464
|
+
self.events = async_to_raw_response_wrapper(
|
|
465
|
+
task_run.events,
|
|
466
|
+
)
|
|
467
|
+
self.result = async_to_raw_response_wrapper(
|
|
468
|
+
task_run.result,
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
class TaskRunResourceWithStreamingResponse:
|
|
473
|
+
def __init__(self, task_run: TaskRunResource) -> None:
|
|
474
|
+
self._task_run = task_run
|
|
475
|
+
|
|
476
|
+
self.create = to_streamed_response_wrapper(
|
|
477
|
+
task_run.create,
|
|
478
|
+
)
|
|
479
|
+
self.events = to_streamed_response_wrapper(
|
|
480
|
+
task_run.events,
|
|
481
|
+
)
|
|
482
|
+
self.result = to_streamed_response_wrapper(
|
|
483
|
+
task_run.result,
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
class AsyncTaskRunResourceWithStreamingResponse:
|
|
488
|
+
def __init__(self, task_run: AsyncTaskRunResource) -> None:
|
|
489
|
+
self._task_run = task_run
|
|
490
|
+
|
|
491
|
+
self.create = async_to_streamed_response_wrapper(
|
|
492
|
+
task_run.create,
|
|
493
|
+
)
|
|
494
|
+
self.events = async_to_streamed_response_wrapper(
|
|
495
|
+
task_run.events,
|
|
496
|
+
)
|
|
497
|
+
self.result = async_to_streamed_response_wrapper(
|
|
498
|
+
task_run.result,
|
|
499
|
+
)
|