parallel-web 0.2.0__py3-none-any.whl → 0.2.2__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 +3 -1
- parallel/_base_client.py +12 -12
- parallel/_client.py +8 -8
- parallel/_compat.py +54 -54
- parallel/_models.py +50 -44
- parallel/_qs.py +7 -7
- parallel/_types.py +18 -11
- parallel/_utils/__init__.py +8 -2
- parallel/_utils/_compat.py +45 -0
- parallel/_utils/_datetime_parse.py +136 -0
- parallel/_utils/_transform.py +13 -3
- parallel/_utils/_typing.py +1 -1
- parallel/_utils/_utils.py +4 -5
- parallel/_version.py +1 -1
- parallel/lib/_parsing/_task_run_result.py +2 -3
- parallel/lib/_parsing/_task_spec.py +4 -4
- parallel/lib/_pydantic.py +3 -3
- parallel/resources/beta/beta.py +16 -16
- parallel/resources/beta/task_group.py +53 -35
- parallel/resources/beta/task_run.py +41 -41
- parallel/resources/task_run.py +33 -33
- parallel/types/beta/beta_run_input.py +6 -6
- parallel/types/beta/beta_run_input_param.py +6 -6
- parallel/types/beta/beta_search_params.py +3 -2
- parallel/types/beta/mcp_server_param.py +4 -2
- parallel/types/beta/search_result.py +1 -1
- parallel/types/beta/task_run_create_params.py +6 -6
- parallel/types/beta/task_run_events_response.py +6 -0
- parallel/types/shared_params/source_policy.py +4 -3
- parallel/types/text_schema.py +1 -1
- parallel/types/text_schema_param.py +3 -2
- {parallel_web-0.2.0.dist-info → parallel_web-0.2.2.dist-info}/METADATA +1 -1
- {parallel_web-0.2.0.dist-info → parallel_web-0.2.2.dist-info}/RECORD +35 -33
- {parallel_web-0.2.0.dist-info → parallel_web-0.2.2.dist-info}/WHEEL +0 -0
- {parallel_web-0.2.0.dist-info → parallel_web-0.2.2.dist-info}/licenses/LICENSE +0 -0
parallel/_types.py
CHANGED
|
@@ -117,18 +117,21 @@ class RequestOptions(TypedDict, total=False):
|
|
|
117
117
|
# Sentinel class used until PEP 0661 is accepted
|
|
118
118
|
class NotGiven:
|
|
119
119
|
"""
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
For parameters with a meaningful None value, we need to distinguish between
|
|
121
|
+
the user explicitly passing None, and the user not passing the parameter at
|
|
122
|
+
all.
|
|
123
|
+
|
|
124
|
+
User code shouldn't need to use not_given directly.
|
|
122
125
|
|
|
123
126
|
For example:
|
|
124
127
|
|
|
125
128
|
```py
|
|
126
|
-
def
|
|
129
|
+
def create(timeout: Timeout | None | NotGiven = not_given): ...
|
|
127
130
|
|
|
128
131
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
create(timeout=1) # 1s timeout
|
|
133
|
+
create(timeout=None) # No timeout
|
|
134
|
+
create() # Default timeout behavior
|
|
132
135
|
```
|
|
133
136
|
"""
|
|
134
137
|
|
|
@@ -140,13 +143,14 @@ class NotGiven:
|
|
|
140
143
|
return "NOT_GIVEN"
|
|
141
144
|
|
|
142
145
|
|
|
143
|
-
|
|
146
|
+
not_given = NotGiven()
|
|
147
|
+
# for backwards compatibility:
|
|
144
148
|
NOT_GIVEN = NotGiven()
|
|
145
149
|
|
|
146
150
|
|
|
147
151
|
class Omit:
|
|
148
|
-
"""
|
|
149
|
-
|
|
152
|
+
"""
|
|
153
|
+
To explicitly omit something from being sent in a request, use `omit`.
|
|
150
154
|
|
|
151
155
|
```py
|
|
152
156
|
# as the default `Content-Type` header is `application/json` that will be sent
|
|
@@ -156,8 +160,8 @@ class Omit:
|
|
|
156
160
|
# to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
|
|
157
161
|
client.post(..., headers={"Content-Type": "multipart/form-data"})
|
|
158
162
|
|
|
159
|
-
# instead you can remove the default `application/json` header by passing
|
|
160
|
-
client.post(..., headers={"Content-Type":
|
|
163
|
+
# instead you can remove the default `application/json` header by passing omit
|
|
164
|
+
client.post(..., headers={"Content-Type": omit})
|
|
161
165
|
```
|
|
162
166
|
"""
|
|
163
167
|
|
|
@@ -165,6 +169,9 @@ class Omit:
|
|
|
165
169
|
return False
|
|
166
170
|
|
|
167
171
|
|
|
172
|
+
omit = Omit()
|
|
173
|
+
|
|
174
|
+
|
|
168
175
|
@runtime_checkable
|
|
169
176
|
class ModelBuilderProtocol(Protocol):
|
|
170
177
|
@classmethod
|
parallel/_utils/__init__.py
CHANGED
|
@@ -11,7 +11,6 @@ from ._utils import (
|
|
|
11
11
|
lru_cache as lru_cache,
|
|
12
12
|
is_mapping as is_mapping,
|
|
13
13
|
is_tuple_t as is_tuple_t,
|
|
14
|
-
parse_date as parse_date,
|
|
15
14
|
is_iterable as is_iterable,
|
|
16
15
|
is_sequence as is_sequence,
|
|
17
16
|
coerce_float as coerce_float,
|
|
@@ -24,7 +23,6 @@ from ._utils import (
|
|
|
24
23
|
coerce_boolean as coerce_boolean,
|
|
25
24
|
coerce_integer as coerce_integer,
|
|
26
25
|
file_from_path as file_from_path,
|
|
27
|
-
parse_datetime as parse_datetime,
|
|
28
26
|
strip_not_given as strip_not_given,
|
|
29
27
|
deepcopy_minimal as deepcopy_minimal,
|
|
30
28
|
get_async_library as get_async_library,
|
|
@@ -33,6 +31,13 @@ from ._utils import (
|
|
|
33
31
|
maybe_coerce_boolean as maybe_coerce_boolean,
|
|
34
32
|
maybe_coerce_integer as maybe_coerce_integer,
|
|
35
33
|
)
|
|
34
|
+
from ._compat import (
|
|
35
|
+
get_args as get_args,
|
|
36
|
+
is_union as is_union,
|
|
37
|
+
get_origin as get_origin,
|
|
38
|
+
is_typeddict as is_typeddict,
|
|
39
|
+
is_literal_type as is_literal_type,
|
|
40
|
+
)
|
|
36
41
|
from ._typing import (
|
|
37
42
|
is_list_type as is_list_type,
|
|
38
43
|
is_union_type as is_union_type,
|
|
@@ -57,3 +62,4 @@ from ._reflection import (
|
|
|
57
62
|
function_has_argument as function_has_argument,
|
|
58
63
|
assert_signatures_in_sync as assert_signatures_in_sync,
|
|
59
64
|
)
|
|
65
|
+
from ._datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import typing_extensions
|
|
5
|
+
from typing import Any, Type, Union, Literal, Optional
|
|
6
|
+
from datetime import date, datetime
|
|
7
|
+
from typing_extensions import get_args as _get_args, get_origin as _get_origin
|
|
8
|
+
|
|
9
|
+
from .._types import StrBytesIntFloat
|
|
10
|
+
from ._datetime_parse import parse_date as _parse_date, parse_datetime as _parse_datetime
|
|
11
|
+
|
|
12
|
+
_LITERAL_TYPES = {Literal, typing_extensions.Literal}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_args(tp: type[Any]) -> tuple[Any, ...]:
|
|
16
|
+
return _get_args(tp)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_origin(tp: type[Any]) -> type[Any] | None:
|
|
20
|
+
return _get_origin(tp)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_union(tp: Optional[Type[Any]]) -> bool:
|
|
24
|
+
if sys.version_info < (3, 10):
|
|
25
|
+
return tp is Union # type: ignore[comparison-overlap]
|
|
26
|
+
else:
|
|
27
|
+
import types
|
|
28
|
+
|
|
29
|
+
return tp is Union or tp is types.UnionType
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def is_typeddict(tp: Type[Any]) -> bool:
|
|
33
|
+
return typing_extensions.is_typeddict(tp)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def is_literal_type(tp: Type[Any]) -> bool:
|
|
37
|
+
return get_origin(tp) in _LITERAL_TYPES
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
|
|
41
|
+
return _parse_date(value)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
|
|
45
|
+
return _parse_datetime(value)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file contains code from https://github.com/pydantic/pydantic/blob/main/pydantic/v1/datetime_parse.py
|
|
3
|
+
without the Pydantic v1 specific errors.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import re
|
|
9
|
+
from typing import Dict, Union, Optional
|
|
10
|
+
from datetime import date, datetime, timezone, timedelta
|
|
11
|
+
|
|
12
|
+
from .._types import StrBytesIntFloat
|
|
13
|
+
|
|
14
|
+
date_expr = r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
|
|
15
|
+
time_expr = (
|
|
16
|
+
r"(?P<hour>\d{1,2}):(?P<minute>\d{1,2})"
|
|
17
|
+
r"(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?"
|
|
18
|
+
r"(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
date_re = re.compile(f"{date_expr}$")
|
|
22
|
+
datetime_re = re.compile(f"{date_expr}[T ]{time_expr}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
EPOCH = datetime(1970, 1, 1)
|
|
26
|
+
# if greater than this, the number is in ms, if less than or equal it's in seconds
|
|
27
|
+
# (in seconds this is 11th October 2603, in ms it's 20th August 1970)
|
|
28
|
+
MS_WATERSHED = int(2e10)
|
|
29
|
+
# slightly more than datetime.max in ns - (datetime.max - EPOCH).total_seconds() * 1e9
|
|
30
|
+
MAX_NUMBER = int(3e20)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_numeric(value: StrBytesIntFloat, native_expected_type: str) -> Union[None, int, float]:
|
|
34
|
+
if isinstance(value, (int, float)):
|
|
35
|
+
return value
|
|
36
|
+
try:
|
|
37
|
+
return float(value)
|
|
38
|
+
except ValueError:
|
|
39
|
+
return None
|
|
40
|
+
except TypeError:
|
|
41
|
+
raise TypeError(f"invalid type; expected {native_expected_type}, string, bytes, int or float") from None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _from_unix_seconds(seconds: Union[int, float]) -> datetime:
|
|
45
|
+
if seconds > MAX_NUMBER:
|
|
46
|
+
return datetime.max
|
|
47
|
+
elif seconds < -MAX_NUMBER:
|
|
48
|
+
return datetime.min
|
|
49
|
+
|
|
50
|
+
while abs(seconds) > MS_WATERSHED:
|
|
51
|
+
seconds /= 1000
|
|
52
|
+
dt = EPOCH + timedelta(seconds=seconds)
|
|
53
|
+
return dt.replace(tzinfo=timezone.utc)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _parse_timezone(value: Optional[str]) -> Union[None, int, timezone]:
|
|
57
|
+
if value == "Z":
|
|
58
|
+
return timezone.utc
|
|
59
|
+
elif value is not None:
|
|
60
|
+
offset_mins = int(value[-2:]) if len(value) > 3 else 0
|
|
61
|
+
offset = 60 * int(value[1:3]) + offset_mins
|
|
62
|
+
if value[0] == "-":
|
|
63
|
+
offset = -offset
|
|
64
|
+
return timezone(timedelta(minutes=offset))
|
|
65
|
+
else:
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
|
|
70
|
+
"""
|
|
71
|
+
Parse a datetime/int/float/string and return a datetime.datetime.
|
|
72
|
+
|
|
73
|
+
This function supports time zone offsets. When the input contains one,
|
|
74
|
+
the output uses a timezone with a fixed offset from UTC.
|
|
75
|
+
|
|
76
|
+
Raise ValueError if the input is well formatted but not a valid datetime.
|
|
77
|
+
Raise ValueError if the input isn't well formatted.
|
|
78
|
+
"""
|
|
79
|
+
if isinstance(value, datetime):
|
|
80
|
+
return value
|
|
81
|
+
|
|
82
|
+
number = _get_numeric(value, "datetime")
|
|
83
|
+
if number is not None:
|
|
84
|
+
return _from_unix_seconds(number)
|
|
85
|
+
|
|
86
|
+
if isinstance(value, bytes):
|
|
87
|
+
value = value.decode()
|
|
88
|
+
|
|
89
|
+
assert not isinstance(value, (float, int))
|
|
90
|
+
|
|
91
|
+
match = datetime_re.match(value)
|
|
92
|
+
if match is None:
|
|
93
|
+
raise ValueError("invalid datetime format")
|
|
94
|
+
|
|
95
|
+
kw = match.groupdict()
|
|
96
|
+
if kw["microsecond"]:
|
|
97
|
+
kw["microsecond"] = kw["microsecond"].ljust(6, "0")
|
|
98
|
+
|
|
99
|
+
tzinfo = _parse_timezone(kw.pop("tzinfo"))
|
|
100
|
+
kw_: Dict[str, Union[None, int, timezone]] = {k: int(v) for k, v in kw.items() if v is not None}
|
|
101
|
+
kw_["tzinfo"] = tzinfo
|
|
102
|
+
|
|
103
|
+
return datetime(**kw_) # type: ignore
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
|
|
107
|
+
"""
|
|
108
|
+
Parse a date/int/float/string and return a datetime.date.
|
|
109
|
+
|
|
110
|
+
Raise ValueError if the input is well formatted but not a valid date.
|
|
111
|
+
Raise ValueError if the input isn't well formatted.
|
|
112
|
+
"""
|
|
113
|
+
if isinstance(value, date):
|
|
114
|
+
if isinstance(value, datetime):
|
|
115
|
+
return value.date()
|
|
116
|
+
else:
|
|
117
|
+
return value
|
|
118
|
+
|
|
119
|
+
number = _get_numeric(value, "date")
|
|
120
|
+
if number is not None:
|
|
121
|
+
return _from_unix_seconds(number).date()
|
|
122
|
+
|
|
123
|
+
if isinstance(value, bytes):
|
|
124
|
+
value = value.decode()
|
|
125
|
+
|
|
126
|
+
assert not isinstance(value, (float, int))
|
|
127
|
+
match = date_re.match(value)
|
|
128
|
+
if match is None:
|
|
129
|
+
raise ValueError("invalid date format")
|
|
130
|
+
|
|
131
|
+
kw = {k: int(v) for k, v in match.groupdict().items()}
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
return date(**kw)
|
|
135
|
+
except ValueError:
|
|
136
|
+
raise ValueError("invalid date format") from None
|
parallel/_utils/_transform.py
CHANGED
|
@@ -16,18 +16,20 @@ from ._utils import (
|
|
|
16
16
|
lru_cache,
|
|
17
17
|
is_mapping,
|
|
18
18
|
is_iterable,
|
|
19
|
+
is_sequence,
|
|
19
20
|
)
|
|
20
21
|
from .._files import is_base64_file_input
|
|
22
|
+
from ._compat import get_origin, is_typeddict
|
|
21
23
|
from ._typing import (
|
|
22
24
|
is_list_type,
|
|
23
25
|
is_union_type,
|
|
24
26
|
extract_type_arg,
|
|
25
27
|
is_iterable_type,
|
|
26
28
|
is_required_type,
|
|
29
|
+
is_sequence_type,
|
|
27
30
|
is_annotated_type,
|
|
28
31
|
strip_annotated_type,
|
|
29
32
|
)
|
|
30
|
-
from .._compat import get_origin, model_dump, is_typeddict
|
|
31
33
|
|
|
32
34
|
_T = TypeVar("_T")
|
|
33
35
|
|
|
@@ -167,6 +169,8 @@ def _transform_recursive(
|
|
|
167
169
|
|
|
168
170
|
Defaults to the same value as the `annotation` argument.
|
|
169
171
|
"""
|
|
172
|
+
from .._compat import model_dump
|
|
173
|
+
|
|
170
174
|
if inner_type is None:
|
|
171
175
|
inner_type = annotation
|
|
172
176
|
|
|
@@ -184,6 +188,8 @@ def _transform_recursive(
|
|
|
184
188
|
(is_list_type(stripped_type) and is_list(data))
|
|
185
189
|
# Iterable[T]
|
|
186
190
|
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
|
|
191
|
+
# Sequence[T]
|
|
192
|
+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
|
|
187
193
|
):
|
|
188
194
|
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
|
|
189
195
|
# intended as an iterable, so we don't transform it.
|
|
@@ -262,7 +268,7 @@ def _transform_typeddict(
|
|
|
262
268
|
annotations = get_type_hints(expected_type, include_extras=True)
|
|
263
269
|
for key, value in data.items():
|
|
264
270
|
if not is_given(value):
|
|
265
|
-
# we don't need to include
|
|
271
|
+
# we don't need to include omitted values here as they'll
|
|
266
272
|
# be stripped out before the request is sent anyway
|
|
267
273
|
continue
|
|
268
274
|
|
|
@@ -329,6 +335,8 @@ async def _async_transform_recursive(
|
|
|
329
335
|
|
|
330
336
|
Defaults to the same value as the `annotation` argument.
|
|
331
337
|
"""
|
|
338
|
+
from .._compat import model_dump
|
|
339
|
+
|
|
332
340
|
if inner_type is None:
|
|
333
341
|
inner_type = annotation
|
|
334
342
|
|
|
@@ -346,6 +354,8 @@ async def _async_transform_recursive(
|
|
|
346
354
|
(is_list_type(stripped_type) and is_list(data))
|
|
347
355
|
# Iterable[T]
|
|
348
356
|
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
|
|
357
|
+
# Sequence[T]
|
|
358
|
+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
|
|
349
359
|
):
|
|
350
360
|
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
|
|
351
361
|
# intended as an iterable, so we don't transform it.
|
|
@@ -424,7 +434,7 @@ async def _async_transform_typeddict(
|
|
|
424
434
|
annotations = get_type_hints(expected_type, include_extras=True)
|
|
425
435
|
for key, value in data.items():
|
|
426
436
|
if not is_given(value):
|
|
427
|
-
# we don't need to include
|
|
437
|
+
# we don't need to include omitted values here as they'll
|
|
428
438
|
# be stripped out before the request is sent anyway
|
|
429
439
|
continue
|
|
430
440
|
|
parallel/_utils/_typing.py
CHANGED
parallel/_utils/_utils.py
CHANGED
|
@@ -21,8 +21,7 @@ from typing_extensions import TypeGuard
|
|
|
21
21
|
|
|
22
22
|
import sniffio
|
|
23
23
|
|
|
24
|
-
from .._types import NotGiven, FileTypes,
|
|
25
|
-
from .._compat import parse_date as parse_date, parse_datetime as parse_datetime
|
|
24
|
+
from .._types import Omit, NotGiven, FileTypes, HeadersLike
|
|
26
25
|
|
|
27
26
|
_T = TypeVar("_T")
|
|
28
27
|
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
|
|
@@ -64,7 +63,7 @@ def _extract_items(
|
|
|
64
63
|
try:
|
|
65
64
|
key = path[index]
|
|
66
65
|
except IndexError:
|
|
67
|
-
if
|
|
66
|
+
if not is_given(obj):
|
|
68
67
|
# no value was provided - we can safely ignore
|
|
69
68
|
return []
|
|
70
69
|
|
|
@@ -127,8 +126,8 @@ def _extract_items(
|
|
|
127
126
|
return []
|
|
128
127
|
|
|
129
128
|
|
|
130
|
-
def is_given(obj:
|
|
131
|
-
return not isinstance(obj, NotGiven)
|
|
129
|
+
def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
|
|
130
|
+
return not isinstance(obj, NotGiven) and not isinstance(obj, Omit)
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
# Type safe methods for narrowing types with TypeVars.
|
parallel/_version.py
CHANGED
|
@@ -4,14 +4,13 @@ from typing import Any, Type, Union, Callable, Coroutine, cast
|
|
|
4
4
|
|
|
5
5
|
from .._time import timeout_retry_context
|
|
6
6
|
from ...types import TaskRunResult, ParsedTaskRunResult
|
|
7
|
-
from ..._types import
|
|
7
|
+
from ..._types import Omit
|
|
8
8
|
from ..._utils import is_str, is_given
|
|
9
9
|
from ..._compat import model_parse, model_parse_json
|
|
10
10
|
from ..._models import construct_type_unchecked
|
|
11
11
|
from .._pydantic import is_basemodel_type
|
|
12
12
|
from ._task_spec import is_output_schema_param
|
|
13
13
|
from ...types.task_spec_param import OutputT, OutputSchema
|
|
14
|
-
from ...types.parsed_task_run_result import ParsedTaskRunResult
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
def wait_for_result(
|
|
@@ -37,7 +36,7 @@ async def wait_for_result_async(
|
|
|
37
36
|
|
|
38
37
|
|
|
39
38
|
def task_run_result_parser(
|
|
40
|
-
run_result: TaskRunResult, output_format: Union[OutputSchema, Type[OutputT]] |
|
|
39
|
+
run_result: TaskRunResult, output_format: Union[OutputSchema, Type[OutputT]] | Omit | None
|
|
41
40
|
) -> TaskRunResult | ParsedTaskRunResult[OutputT]:
|
|
42
41
|
"""Parse a TaskRunResult object into a ParsedTaskRunResult based on output_format."""
|
|
43
42
|
if not is_given(output_format) or output_format is None or is_output_schema_param(output_format):
|
|
@@ -5,7 +5,7 @@ from typing_extensions import TypeGuard
|
|
|
5
5
|
|
|
6
6
|
import pydantic
|
|
7
7
|
|
|
8
|
-
from ..._types import
|
|
8
|
+
from ..._types import Omit
|
|
9
9
|
from ..._utils import is_str, is_dict, is_given
|
|
10
10
|
from .._pydantic import to_json_schema, is_basemodel_type
|
|
11
11
|
from ...types.task_spec_param import (
|
|
@@ -81,12 +81,12 @@ def _generate_output_schema(output_format: OutputSchema | Type[OutputT]) -> Outp
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
def build_task_spec_param(
|
|
84
|
-
output_format: OutputSchema | Type[OutputT] |
|
|
84
|
+
output_format: OutputSchema | Type[OutputT] | Omit | None,
|
|
85
85
|
_: Union[str, object], # placeholder for input
|
|
86
|
-
) -> TaskSpecParam |
|
|
86
|
+
) -> TaskSpecParam | Omit:
|
|
87
87
|
"""Build a TaskSpecParam from an OutputSchema or Type[OutputT] if provided."""
|
|
88
88
|
if not is_given(output_format) or output_format is None:
|
|
89
|
-
return
|
|
89
|
+
return Omit()
|
|
90
90
|
|
|
91
91
|
# output format has type OutputSchema | Type[OutputT] here
|
|
92
92
|
output_schema = _generate_output_schema(output_format) # type: ignore[arg-type]
|
parallel/lib/_pydantic.py
CHANGED
|
@@ -6,7 +6,7 @@ from typing_extensions import TypeGuard
|
|
|
6
6
|
|
|
7
7
|
import pydantic
|
|
8
8
|
|
|
9
|
-
from .._compat import
|
|
9
|
+
from .._compat import PYDANTIC_V1, model_json_schema
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def to_json_schema(
|
|
@@ -16,8 +16,8 @@ def to_json_schema(
|
|
|
16
16
|
if is_basemodel_type(model_type):
|
|
17
17
|
schema = model_json_schema(model_type)
|
|
18
18
|
elif isinstance(model_type, pydantic.TypeAdapter):
|
|
19
|
-
if
|
|
20
|
-
raise TypeError(f"TypeAdapters are
|
|
19
|
+
if PYDANTIC_V1:
|
|
20
|
+
raise TypeError(f"TypeAdapters are not supported with Pydantic v1 - {model_type}")
|
|
21
21
|
schema = model_type.json_schema()
|
|
22
22
|
else:
|
|
23
23
|
raise TypeError(f"Unsupported type: {model_type}")
|
parallel/resources/beta/beta.py
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Optional
|
|
6
6
|
from typing_extensions import Literal
|
|
7
7
|
|
|
8
8
|
import httpx
|
|
9
9
|
|
|
10
|
-
from ..._types import
|
|
10
|
+
from ..._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
|
|
11
11
|
from ..._utils import maybe_transform, async_maybe_transform
|
|
12
12
|
from .task_run import (
|
|
13
13
|
TaskRunResource,
|
|
@@ -72,18 +72,18 @@ class BetaResource(SyncAPIResource):
|
|
|
72
72
|
def search(
|
|
73
73
|
self,
|
|
74
74
|
*,
|
|
75
|
-
max_chars_per_result: Optional[int] |
|
|
76
|
-
max_results: Optional[int] |
|
|
77
|
-
objective: Optional[str] |
|
|
78
|
-
processor: Literal["base", "pro"] |
|
|
79
|
-
search_queries: Optional[
|
|
80
|
-
source_policy: Optional[SourcePolicy] |
|
|
75
|
+
max_chars_per_result: Optional[int] | Omit = omit,
|
|
76
|
+
max_results: Optional[int] | Omit = omit,
|
|
77
|
+
objective: Optional[str] | Omit = omit,
|
|
78
|
+
processor: Literal["base", "pro"] | Omit = omit,
|
|
79
|
+
search_queries: Optional[SequenceNotStr[str]] | Omit = omit,
|
|
80
|
+
source_policy: Optional[SourcePolicy] | Omit = omit,
|
|
81
81
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
82
82
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
83
83
|
extra_headers: Headers | None = None,
|
|
84
84
|
extra_query: Query | None = None,
|
|
85
85
|
extra_body: Body | None = None,
|
|
86
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
|
86
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
87
87
|
) -> SearchResult:
|
|
88
88
|
"""
|
|
89
89
|
Searches the web.
|
|
@@ -168,18 +168,18 @@ class AsyncBetaResource(AsyncAPIResource):
|
|
|
168
168
|
async def search(
|
|
169
169
|
self,
|
|
170
170
|
*,
|
|
171
|
-
max_chars_per_result: Optional[int] |
|
|
172
|
-
max_results: Optional[int] |
|
|
173
|
-
objective: Optional[str] |
|
|
174
|
-
processor: Literal["base", "pro"] |
|
|
175
|
-
search_queries: Optional[
|
|
176
|
-
source_policy: Optional[SourcePolicy] |
|
|
171
|
+
max_chars_per_result: Optional[int] | Omit = omit,
|
|
172
|
+
max_results: Optional[int] | Omit = omit,
|
|
173
|
+
objective: Optional[str] | Omit = omit,
|
|
174
|
+
processor: Literal["base", "pro"] | Omit = omit,
|
|
175
|
+
search_queries: Optional[SequenceNotStr[str]] | Omit = omit,
|
|
176
|
+
source_policy: Optional[SourcePolicy] | Omit = omit,
|
|
177
177
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
178
178
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
179
179
|
extra_headers: Headers | None = None,
|
|
180
180
|
extra_query: Query | None = None,
|
|
181
181
|
extra_body: Body | None = None,
|
|
182
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
|
182
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
183
183
|
) -> SearchResult:
|
|
184
184
|
"""
|
|
185
185
|
Searches the web.
|