chunkr-ai 0.1.0a7__py3-none-any.whl → 0.1.0a9__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.
- chunkr_ai/__init__.py +3 -1
- chunkr_ai/_base_client.py +12 -12
- chunkr_ai/_client.py +8 -8
- chunkr_ai/_compat.py +48 -48
- chunkr_ai/_models.py +50 -44
- chunkr_ai/_qs.py +7 -7
- chunkr_ai/_types.py +18 -11
- chunkr_ai/_utils/__init__.py +8 -2
- chunkr_ai/_utils/_compat.py +45 -0
- chunkr_ai/_utils/_datetime_parse.py +136 -0
- chunkr_ai/_utils/_transform.py +13 -3
- chunkr_ai/_utils/_typing.py +1 -1
- chunkr_ai/_utils/_utils.py +4 -5
- chunkr_ai/_version.py +1 -1
- chunkr_ai/resources/files.py +29 -29
- chunkr_ai/resources/health.py +3 -3
- chunkr_ai/resources/tasks/extract.py +21 -37
- chunkr_ai/resources/tasks/parse.py +29 -54
- chunkr_ai/resources/tasks/tasks.py +35 -51
- chunkr_ai/resources/webhooks.py +3 -3
- chunkr_ai/types/__init__.py +0 -2
- chunkr_ai/types/extract_output_response.py +45 -2
- chunkr_ai/types/file_info.py +3 -0
- chunkr_ai/types/ocr_result.py +6 -6
- chunkr_ai/types/parse_configuration.py +0 -4
- chunkr_ai/types/parse_configuration_param.py +0 -4
- chunkr_ai/types/segment.py +8 -5
- chunkr_ai/types/segment_processing.py +92 -2
- chunkr_ai/types/segment_processing_param.py +92 -2
- chunkr_ai/types/task_get_params.py +0 -3
- chunkr_ai/types/tasks/extract_create_response.py +0 -147
- chunkr_ai/types/tasks/extract_get_params.py +0 -3
- chunkr_ai/types/tasks/extract_get_response.py +0 -147
- chunkr_ai/types/tasks/parse_create_params.py +0 -4
- chunkr_ai/types/tasks/parse_get_params.py +0 -3
- chunkr_ai/types/version_info.py +1 -1
- {chunkr_ai-0.1.0a7.dist-info → chunkr_ai-0.1.0a9.dist-info}/METADATA +1 -1
- {chunkr_ai-0.1.0a7.dist-info → chunkr_ai-0.1.0a9.dist-info}/RECORD +40 -40
- chunkr_ai/types/llm_processing.py +0 -36
- chunkr_ai/types/llm_processing_param.py +0 -36
- {chunkr_ai-0.1.0a7.dist-info → chunkr_ai-0.1.0a9.dist-info}/WHEEL +0 -0
- {chunkr_ai-0.1.0a7.dist-info → chunkr_ai-0.1.0a9.dist-info}/licenses/LICENSE +0 -0
chunkr_ai/__init__.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import typing as _t
|
4
4
|
|
5
5
|
from . import types
|
6
|
-
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
|
6
|
+
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given
|
7
7
|
from ._utils import file_from_path
|
8
8
|
from ._client import Chunkr, Client, Stream, Timeout, Transport, AsyncChunkr, AsyncClient, AsyncStream, RequestOptions
|
9
9
|
from ._models import BaseModel
|
@@ -39,7 +39,9 @@ __all__ = [
|
|
39
39
|
"ProxiesTypes",
|
40
40
|
"NotGiven",
|
41
41
|
"NOT_GIVEN",
|
42
|
+
"not_given",
|
42
43
|
"Omit",
|
44
|
+
"omit",
|
43
45
|
"ChunkrError",
|
44
46
|
"APIError",
|
45
47
|
"APIStatusError",
|
chunkr_ai/_base_client.py
CHANGED
@@ -42,7 +42,6 @@ from . import _exceptions
|
|
42
42
|
from ._qs import Querystring
|
43
43
|
from ._files import to_httpx_files, async_to_httpx_files
|
44
44
|
from ._types import (
|
45
|
-
NOT_GIVEN,
|
46
45
|
Body,
|
47
46
|
Omit,
|
48
47
|
Query,
|
@@ -57,9 +56,10 @@ from ._types import (
|
|
57
56
|
RequestOptions,
|
58
57
|
HttpxRequestFiles,
|
59
58
|
ModelBuilderProtocol,
|
59
|
+
not_given,
|
60
60
|
)
|
61
61
|
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
|
62
|
-
from ._compat import
|
62
|
+
from ._compat import PYDANTIC_V1, model_copy, model_dump
|
63
63
|
from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
|
64
64
|
from ._response import (
|
65
65
|
APIResponse,
|
@@ -145,9 +145,9 @@ class PageInfo:
|
|
145
145
|
def __init__(
|
146
146
|
self,
|
147
147
|
*,
|
148
|
-
url: URL | NotGiven =
|
149
|
-
json: Body | NotGiven =
|
150
|
-
params: Query | NotGiven =
|
148
|
+
url: URL | NotGiven = not_given,
|
149
|
+
json: Body | NotGiven = not_given,
|
150
|
+
params: Query | NotGiven = not_given,
|
151
151
|
) -> None:
|
152
152
|
self.url = url
|
153
153
|
self.json = json
|
@@ -232,7 +232,7 @@ class BaseSyncPage(BasePage[_T], Generic[_T]):
|
|
232
232
|
model: Type[_T],
|
233
233
|
options: FinalRequestOptions,
|
234
234
|
) -> None:
|
235
|
-
if
|
235
|
+
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
|
236
236
|
self.__pydantic_private__ = {}
|
237
237
|
|
238
238
|
self._model = model
|
@@ -320,7 +320,7 @@ class BaseAsyncPage(BasePage[_T], Generic[_T]):
|
|
320
320
|
client: AsyncAPIClient,
|
321
321
|
options: FinalRequestOptions,
|
322
322
|
) -> None:
|
323
|
-
if
|
323
|
+
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
|
324
324
|
self.__pydantic_private__ = {}
|
325
325
|
|
326
326
|
self._model = model
|
@@ -595,7 +595,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|
595
595
|
# we internally support defining a temporary header to override the
|
596
596
|
# default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
|
597
597
|
# see _response.py for implementation details
|
598
|
-
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER,
|
598
|
+
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
|
599
599
|
if is_given(override_cast_to):
|
600
600
|
options.headers = headers
|
601
601
|
return cast(Type[ResponseT], override_cast_to)
|
@@ -825,7 +825,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|
825
825
|
version: str,
|
826
826
|
base_url: str | URL,
|
827
827
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
828
|
-
timeout: float | Timeout | None | NotGiven =
|
828
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
829
829
|
http_client: httpx.Client | None = None,
|
830
830
|
custom_headers: Mapping[str, str] | None = None,
|
831
831
|
custom_query: Mapping[str, object] | None = None,
|
@@ -1356,7 +1356,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|
1356
1356
|
base_url: str | URL,
|
1357
1357
|
_strict_response_validation: bool,
|
1358
1358
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
1359
|
-
timeout: float | Timeout | None | NotGiven =
|
1359
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
1360
1360
|
http_client: httpx.AsyncClient | None = None,
|
1361
1361
|
custom_headers: Mapping[str, str] | None = None,
|
1362
1362
|
custom_query: Mapping[str, object] | None = None,
|
@@ -1818,8 +1818,8 @@ def make_request_options(
|
|
1818
1818
|
extra_query: Query | None = None,
|
1819
1819
|
extra_body: Body | None = None,
|
1820
1820
|
idempotency_key: str | None = None,
|
1821
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
1822
|
-
post_parser: PostParser | NotGiven =
|
1821
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
1822
|
+
post_parser: PostParser | NotGiven = not_given,
|
1823
1823
|
) -> RequestOptions:
|
1824
1824
|
"""Create a dict of type RequestOptions without keys of NotGiven values."""
|
1825
1825
|
options: RequestOptions = {}
|
chunkr_ai/_client.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
5
|
import os
|
6
|
-
from typing import Any,
|
6
|
+
from typing import Any, Mapping
|
7
7
|
from typing_extensions import Self, override
|
8
8
|
|
9
9
|
import httpx
|
@@ -11,13 +11,13 @@ import httpx
|
|
11
11
|
from . import _exceptions
|
12
12
|
from ._qs import Querystring
|
13
13
|
from ._types import (
|
14
|
-
NOT_GIVEN,
|
15
14
|
Omit,
|
16
15
|
Timeout,
|
17
16
|
NotGiven,
|
18
17
|
Transport,
|
19
18
|
ProxiesTypes,
|
20
19
|
RequestOptions,
|
20
|
+
not_given,
|
21
21
|
)
|
22
22
|
from ._utils import is_given, get_async_library
|
23
23
|
from ._version import __version__
|
@@ -52,7 +52,7 @@ class Chunkr(SyncAPIClient):
|
|
52
52
|
api_key: str | None = None,
|
53
53
|
webhook_key: str | None = None,
|
54
54
|
base_url: str | httpx.URL | None = None,
|
55
|
-
timeout:
|
55
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
56
56
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
57
57
|
default_headers: Mapping[str, str] | None = None,
|
58
58
|
default_query: Mapping[str, object] | None = None,
|
@@ -139,9 +139,9 @@ class Chunkr(SyncAPIClient):
|
|
139
139
|
api_key: str | None = None,
|
140
140
|
webhook_key: str | None = None,
|
141
141
|
base_url: str | httpx.URL | None = None,
|
142
|
-
timeout: float | Timeout | None | NotGiven =
|
142
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
143
143
|
http_client: httpx.Client | None = None,
|
144
|
-
max_retries: int | NotGiven =
|
144
|
+
max_retries: int | NotGiven = not_given,
|
145
145
|
default_headers: Mapping[str, str] | None = None,
|
146
146
|
set_default_headers: Mapping[str, str] | None = None,
|
147
147
|
default_query: Mapping[str, object] | None = None,
|
@@ -238,7 +238,7 @@ class AsyncChunkr(AsyncAPIClient):
|
|
238
238
|
api_key: str | None = None,
|
239
239
|
webhook_key: str | None = None,
|
240
240
|
base_url: str | httpx.URL | None = None,
|
241
|
-
timeout:
|
241
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
242
242
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
243
243
|
default_headers: Mapping[str, str] | None = None,
|
244
244
|
default_query: Mapping[str, object] | None = None,
|
@@ -325,9 +325,9 @@ class AsyncChunkr(AsyncAPIClient):
|
|
325
325
|
api_key: str | None = None,
|
326
326
|
webhook_key: str | None = None,
|
327
327
|
base_url: str | httpx.URL | None = None,
|
328
|
-
timeout: float | Timeout | None | NotGiven =
|
328
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
329
329
|
http_client: httpx.AsyncClient | None = None,
|
330
|
-
max_retries: int | NotGiven =
|
330
|
+
max_retries: int | NotGiven = not_given,
|
331
331
|
default_headers: Mapping[str, str] | None = None,
|
332
332
|
set_default_headers: Mapping[str, str] | None = None,
|
333
333
|
default_query: Mapping[str, object] | None = None,
|
chunkr_ai/_compat.py
CHANGED
@@ -12,14 +12,13 @@ from ._types import IncEx, StrBytesIntFloat
|
|
12
12
|
_T = TypeVar("_T")
|
13
13
|
_ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
|
14
14
|
|
15
|
-
# --------------- Pydantic v2 compatibility ---------------
|
15
|
+
# --------------- Pydantic v2, v3 compatibility ---------------
|
16
16
|
|
17
17
|
# Pyright incorrectly reports some of our functions as overriding a method when they don't
|
18
18
|
# pyright: reportIncompatibleMethodOverride=false
|
19
19
|
|
20
|
-
|
20
|
+
PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
|
21
21
|
|
22
|
-
# v1 re-exports
|
23
22
|
if TYPE_CHECKING:
|
24
23
|
|
25
24
|
def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
|
@@ -44,90 +43,92 @@ if TYPE_CHECKING:
|
|
44
43
|
...
|
45
44
|
|
46
45
|
else:
|
47
|
-
|
48
|
-
|
46
|
+
# v1 re-exports
|
47
|
+
if PYDANTIC_V1:
|
48
|
+
from pydantic.typing import (
|
49
49
|
get_args as get_args,
|
50
50
|
is_union as is_union,
|
51
51
|
get_origin as get_origin,
|
52
52
|
is_typeddict as is_typeddict,
|
53
53
|
is_literal_type as is_literal_type,
|
54
54
|
)
|
55
|
-
from pydantic.
|
55
|
+
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
|
56
56
|
else:
|
57
|
-
from
|
57
|
+
from ._utils import (
|
58
58
|
get_args as get_args,
|
59
59
|
is_union as is_union,
|
60
60
|
get_origin as get_origin,
|
61
|
+
parse_date as parse_date,
|
61
62
|
is_typeddict as is_typeddict,
|
63
|
+
parse_datetime as parse_datetime,
|
62
64
|
is_literal_type as is_literal_type,
|
63
65
|
)
|
64
|
-
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
|
65
66
|
|
66
67
|
|
67
68
|
# refactored config
|
68
69
|
if TYPE_CHECKING:
|
69
70
|
from pydantic import ConfigDict as ConfigDict
|
70
71
|
else:
|
71
|
-
if
|
72
|
-
from pydantic import ConfigDict
|
73
|
-
else:
|
72
|
+
if PYDANTIC_V1:
|
74
73
|
# TODO: provide an error message here?
|
75
74
|
ConfigDict = None
|
75
|
+
else:
|
76
|
+
from pydantic import ConfigDict as ConfigDict
|
76
77
|
|
77
78
|
|
78
79
|
# renamed methods / properties
|
79
80
|
def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
|
80
|
-
if
|
81
|
-
return model.model_validate(value)
|
82
|
-
else:
|
81
|
+
if PYDANTIC_V1:
|
83
82
|
return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
|
83
|
+
else:
|
84
|
+
return model.model_validate(value)
|
84
85
|
|
85
86
|
|
86
87
|
def field_is_required(field: FieldInfo) -> bool:
|
87
|
-
if
|
88
|
-
return field.
|
89
|
-
return field.
|
88
|
+
if PYDANTIC_V1:
|
89
|
+
return field.required # type: ignore
|
90
|
+
return field.is_required()
|
90
91
|
|
91
92
|
|
92
93
|
def field_get_default(field: FieldInfo) -> Any:
|
93
94
|
value = field.get_default()
|
94
|
-
if
|
95
|
-
from pydantic_core import PydanticUndefined
|
96
|
-
|
97
|
-
if value == PydanticUndefined:
|
98
|
-
return None
|
95
|
+
if PYDANTIC_V1:
|
99
96
|
return value
|
97
|
+
from pydantic_core import PydanticUndefined
|
98
|
+
|
99
|
+
if value == PydanticUndefined:
|
100
|
+
return None
|
100
101
|
return value
|
101
102
|
|
102
103
|
|
103
104
|
def field_outer_type(field: FieldInfo) -> Any:
|
104
|
-
if
|
105
|
-
return field.
|
106
|
-
return field.
|
105
|
+
if PYDANTIC_V1:
|
106
|
+
return field.outer_type_ # type: ignore
|
107
|
+
return field.annotation
|
107
108
|
|
108
109
|
|
109
110
|
def get_model_config(model: type[pydantic.BaseModel]) -> Any:
|
110
|
-
if
|
111
|
-
return model.
|
112
|
-
return model.
|
111
|
+
if PYDANTIC_V1:
|
112
|
+
return model.__config__ # type: ignore
|
113
|
+
return model.model_config
|
113
114
|
|
114
115
|
|
115
116
|
def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
|
116
|
-
if
|
117
|
-
return model.
|
118
|
-
return model.
|
117
|
+
if PYDANTIC_V1:
|
118
|
+
return model.__fields__ # type: ignore
|
119
|
+
return model.model_fields
|
119
120
|
|
120
121
|
|
121
122
|
def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
|
122
|
-
if
|
123
|
-
return model.
|
124
|
-
return model.
|
123
|
+
if PYDANTIC_V1:
|
124
|
+
return model.copy(deep=deep) # type: ignore
|
125
|
+
return model.model_copy(deep=deep)
|
125
126
|
|
126
127
|
|
127
128
|
def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
|
128
|
-
if
|
129
|
-
return model.
|
130
|
-
return model.
|
129
|
+
if PYDANTIC_V1:
|
130
|
+
return model.json(indent=indent) # type: ignore
|
131
|
+
return model.model_dump_json(indent=indent)
|
131
132
|
|
132
133
|
|
133
134
|
def model_dump(
|
@@ -139,14 +140,14 @@ def model_dump(
|
|
139
140
|
warnings: bool = True,
|
140
141
|
mode: Literal["json", "python"] = "python",
|
141
142
|
) -> dict[str, Any]:
|
142
|
-
if
|
143
|
+
if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
|
143
144
|
return model.model_dump(
|
144
145
|
mode=mode,
|
145
146
|
exclude=exclude,
|
146
147
|
exclude_unset=exclude_unset,
|
147
148
|
exclude_defaults=exclude_defaults,
|
148
149
|
# warnings are not supported in Pydantic v1
|
149
|
-
warnings=
|
150
|
+
warnings=True if PYDANTIC_V1 else warnings,
|
150
151
|
)
|
151
152
|
return cast(
|
152
153
|
"dict[str, Any]",
|
@@ -159,9 +160,9 @@ def model_dump(
|
|
159
160
|
|
160
161
|
|
161
162
|
def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
|
162
|
-
if
|
163
|
-
return model.
|
164
|
-
return model.
|
163
|
+
if PYDANTIC_V1:
|
164
|
+
return model.parse_obj(data) # pyright: ignore[reportDeprecated]
|
165
|
+
return model.model_validate(data)
|
165
166
|
|
166
167
|
|
167
168
|
# generic models
|
@@ -170,17 +171,16 @@ if TYPE_CHECKING:
|
|
170
171
|
class GenericModel(pydantic.BaseModel): ...
|
171
172
|
|
172
173
|
else:
|
173
|
-
if
|
174
|
+
if PYDANTIC_V1:
|
175
|
+
import pydantic.generics
|
176
|
+
|
177
|
+
class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
|
178
|
+
else:
|
174
179
|
# there no longer needs to be a distinction in v2 but
|
175
180
|
# we still have to create our own subclass to avoid
|
176
181
|
# inconsistent MRO ordering errors
|
177
182
|
class GenericModel(pydantic.BaseModel): ...
|
178
183
|
|
179
|
-
else:
|
180
|
-
import pydantic.generics
|
181
|
-
|
182
|
-
class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
|
183
|
-
|
184
184
|
|
185
185
|
# cached properties
|
186
186
|
if TYPE_CHECKING:
|
chunkr_ai/_models.py
CHANGED
@@ -50,7 +50,7 @@ from ._utils import (
|
|
50
50
|
strip_annotated_type,
|
51
51
|
)
|
52
52
|
from ._compat import (
|
53
|
-
|
53
|
+
PYDANTIC_V1,
|
54
54
|
ConfigDict,
|
55
55
|
GenericModel as BaseGenericModel,
|
56
56
|
get_args,
|
@@ -81,11 +81,7 @@ class _ConfigProtocol(Protocol):
|
|
81
81
|
|
82
82
|
|
83
83
|
class BaseModel(pydantic.BaseModel):
|
84
|
-
if
|
85
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(
|
86
|
-
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
|
87
|
-
)
|
88
|
-
else:
|
84
|
+
if PYDANTIC_V1:
|
89
85
|
|
90
86
|
@property
|
91
87
|
@override
|
@@ -95,6 +91,10 @@ class BaseModel(pydantic.BaseModel):
|
|
95
91
|
|
96
92
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
97
93
|
extra: Any = pydantic.Extra.allow # type: ignore
|
94
|
+
else:
|
95
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(
|
96
|
+
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
|
97
|
+
)
|
98
98
|
|
99
99
|
def to_dict(
|
100
100
|
self,
|
@@ -215,25 +215,25 @@ class BaseModel(pydantic.BaseModel):
|
|
215
215
|
if key not in model_fields:
|
216
216
|
parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
|
217
217
|
|
218
|
-
if
|
219
|
-
_extra[key] = parsed
|
220
|
-
else:
|
218
|
+
if PYDANTIC_V1:
|
221
219
|
_fields_set.add(key)
|
222
220
|
fields_values[key] = parsed
|
221
|
+
else:
|
222
|
+
_extra[key] = parsed
|
223
223
|
|
224
224
|
object.__setattr__(m, "__dict__", fields_values)
|
225
225
|
|
226
|
-
if
|
227
|
-
# these properties are copied from Pydantic's `model_construct()` method
|
228
|
-
object.__setattr__(m, "__pydantic_private__", None)
|
229
|
-
object.__setattr__(m, "__pydantic_extra__", _extra)
|
230
|
-
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
231
|
-
else:
|
226
|
+
if PYDANTIC_V1:
|
232
227
|
# init_private_attributes() does not exist in v2
|
233
228
|
m._init_private_attributes() # type: ignore
|
234
229
|
|
235
230
|
# copied from Pydantic v1's `construct()` method
|
236
231
|
object.__setattr__(m, "__fields_set__", _fields_set)
|
232
|
+
else:
|
233
|
+
# these properties are copied from Pydantic's `model_construct()` method
|
234
|
+
object.__setattr__(m, "__pydantic_private__", None)
|
235
|
+
object.__setattr__(m, "__pydantic_extra__", _extra)
|
236
|
+
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
237
237
|
|
238
238
|
return m
|
239
239
|
|
@@ -243,7 +243,7 @@ class BaseModel(pydantic.BaseModel):
|
|
243
243
|
# although not in practice
|
244
244
|
model_construct = construct
|
245
245
|
|
246
|
-
if
|
246
|
+
if PYDANTIC_V1:
|
247
247
|
# we define aliases for some of the new pydantic v2 methods so
|
248
248
|
# that we can just document these methods without having to specify
|
249
249
|
# a specific pydantic version as some users may not know which
|
@@ -256,7 +256,7 @@ class BaseModel(pydantic.BaseModel):
|
|
256
256
|
mode: Literal["json", "python"] | str = "python",
|
257
257
|
include: IncEx | None = None,
|
258
258
|
exclude: IncEx | None = None,
|
259
|
-
by_alias: bool =
|
259
|
+
by_alias: bool | None = None,
|
260
260
|
exclude_unset: bool = False,
|
261
261
|
exclude_defaults: bool = False,
|
262
262
|
exclude_none: bool = False,
|
@@ -264,6 +264,7 @@ class BaseModel(pydantic.BaseModel):
|
|
264
264
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
265
265
|
context: dict[str, Any] | None = None,
|
266
266
|
serialize_as_any: bool = False,
|
267
|
+
fallback: Callable[[Any], Any] | None = None,
|
267
268
|
) -> dict[str, Any]:
|
268
269
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
|
269
270
|
|
@@ -295,10 +296,12 @@ class BaseModel(pydantic.BaseModel):
|
|
295
296
|
raise ValueError("context is only supported in Pydantic v2")
|
296
297
|
if serialize_as_any != False:
|
297
298
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
299
|
+
if fallback is not None:
|
300
|
+
raise ValueError("fallback is only supported in Pydantic v2")
|
298
301
|
dumped = super().dict( # pyright: ignore[reportDeprecated]
|
299
302
|
include=include,
|
300
303
|
exclude=exclude,
|
301
|
-
by_alias=by_alias,
|
304
|
+
by_alias=by_alias if by_alias is not None else False,
|
302
305
|
exclude_unset=exclude_unset,
|
303
306
|
exclude_defaults=exclude_defaults,
|
304
307
|
exclude_none=exclude_none,
|
@@ -313,13 +316,14 @@ class BaseModel(pydantic.BaseModel):
|
|
313
316
|
indent: int | None = None,
|
314
317
|
include: IncEx | None = None,
|
315
318
|
exclude: IncEx | None = None,
|
316
|
-
by_alias: bool =
|
319
|
+
by_alias: bool | None = None,
|
317
320
|
exclude_unset: bool = False,
|
318
321
|
exclude_defaults: bool = False,
|
319
322
|
exclude_none: bool = False,
|
320
323
|
round_trip: bool = False,
|
321
324
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
322
325
|
context: dict[str, Any] | None = None,
|
326
|
+
fallback: Callable[[Any], Any] | None = None,
|
323
327
|
serialize_as_any: bool = False,
|
324
328
|
) -> str:
|
325
329
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
|
@@ -348,11 +352,13 @@ class BaseModel(pydantic.BaseModel):
|
|
348
352
|
raise ValueError("context is only supported in Pydantic v2")
|
349
353
|
if serialize_as_any != False:
|
350
354
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
355
|
+
if fallback is not None:
|
356
|
+
raise ValueError("fallback is only supported in Pydantic v2")
|
351
357
|
return super().json( # type: ignore[reportDeprecated]
|
352
358
|
indent=indent,
|
353
359
|
include=include,
|
354
360
|
exclude=exclude,
|
355
|
-
by_alias=by_alias,
|
361
|
+
by_alias=by_alias if by_alias is not None else False,
|
356
362
|
exclude_unset=exclude_unset,
|
357
363
|
exclude_defaults=exclude_defaults,
|
358
364
|
exclude_none=exclude_none,
|
@@ -363,10 +369,10 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
363
369
|
if value is None:
|
364
370
|
return field_get_default(field)
|
365
371
|
|
366
|
-
if
|
367
|
-
type_ = field.annotation
|
368
|
-
else:
|
372
|
+
if PYDANTIC_V1:
|
369
373
|
type_ = cast(type, field.outer_type_) # type: ignore
|
374
|
+
else:
|
375
|
+
type_ = field.annotation # type: ignore
|
370
376
|
|
371
377
|
if type_ is None:
|
372
378
|
raise RuntimeError(f"Unexpected field type is None for {key}")
|
@@ -375,7 +381,7 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
375
381
|
|
376
382
|
|
377
383
|
def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
|
378
|
-
if
|
384
|
+
if PYDANTIC_V1:
|
379
385
|
# TODO
|
380
386
|
return None
|
381
387
|
|
@@ -628,30 +634,30 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
|
|
628
634
|
for variant in get_args(union):
|
629
635
|
variant = strip_annotated_type(variant)
|
630
636
|
if is_basemodel_type(variant):
|
631
|
-
if
|
632
|
-
|
633
|
-
if not
|
637
|
+
if PYDANTIC_V1:
|
638
|
+
field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
|
639
|
+
if not field_info:
|
634
640
|
continue
|
635
641
|
|
636
642
|
# Note: if one variant defines an alias then they all should
|
637
|
-
discriminator_alias =
|
638
|
-
|
639
|
-
field_schema = field["schema"]
|
643
|
+
discriminator_alias = field_info.alias
|
640
644
|
|
641
|
-
if
|
642
|
-
for entry in
|
645
|
+
if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
|
646
|
+
for entry in get_args(annotation):
|
643
647
|
if isinstance(entry, str):
|
644
648
|
mapping[entry] = variant
|
645
649
|
else:
|
646
|
-
|
647
|
-
if not
|
650
|
+
field = _extract_field_schema_pv2(variant, discriminator_field_name)
|
651
|
+
if not field:
|
648
652
|
continue
|
649
653
|
|
650
654
|
# Note: if one variant defines an alias then they all should
|
651
|
-
discriminator_alias =
|
655
|
+
discriminator_alias = field.get("serialization_alias")
|
652
656
|
|
653
|
-
|
654
|
-
|
657
|
+
field_schema = field["schema"]
|
658
|
+
|
659
|
+
if field_schema["type"] == "literal":
|
660
|
+
for entry in cast("LiteralSchema", field_schema)["expected"]:
|
655
661
|
if isinstance(entry, str):
|
656
662
|
mapping[entry] = variant
|
657
663
|
|
@@ -714,7 +720,7 @@ else:
|
|
714
720
|
pass
|
715
721
|
|
716
722
|
|
717
|
-
if
|
723
|
+
if not PYDANTIC_V1:
|
718
724
|
from pydantic import TypeAdapter as _TypeAdapter
|
719
725
|
|
720
726
|
_CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))
|
@@ -782,12 +788,12 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
782
788
|
json_data: Union[Body, None] = None
|
783
789
|
extra_json: Union[AnyMapping, None] = None
|
784
790
|
|
785
|
-
if
|
786
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
787
|
-
else:
|
791
|
+
if PYDANTIC_V1:
|
788
792
|
|
789
793
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
790
794
|
arbitrary_types_allowed: bool = True
|
795
|
+
else:
|
796
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
791
797
|
|
792
798
|
def get_max_retries(self, max_retries: int) -> int:
|
793
799
|
if isinstance(self.max_retries, NotGiven):
|
@@ -820,9 +826,9 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
820
826
|
key: strip_not_given(value)
|
821
827
|
for key, value in values.items()
|
822
828
|
}
|
823
|
-
if
|
824
|
-
return super().
|
825
|
-
return
|
829
|
+
if PYDANTIC_V1:
|
830
|
+
return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
|
831
|
+
return super().model_construct(_fields_set, **kwargs)
|
826
832
|
|
827
833
|
if not TYPE_CHECKING:
|
828
834
|
# type checkers incorrectly complain about this assignment
|
chunkr_ai/_qs.py
CHANGED
@@ -4,7 +4,7 @@ from typing import Any, List, Tuple, Union, Mapping, TypeVar
|
|
4
4
|
from urllib.parse import parse_qs, urlencode
|
5
5
|
from typing_extensions import Literal, get_args
|
6
6
|
|
7
|
-
from ._types import
|
7
|
+
from ._types import NotGiven, not_given
|
8
8
|
from ._utils import flatten
|
9
9
|
|
10
10
|
_T = TypeVar("_T")
|
@@ -41,8 +41,8 @@ class Querystring:
|
|
41
41
|
self,
|
42
42
|
params: Params,
|
43
43
|
*,
|
44
|
-
array_format:
|
45
|
-
nested_format:
|
44
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
45
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
46
46
|
) -> str:
|
47
47
|
return urlencode(
|
48
48
|
self.stringify_items(
|
@@ -56,8 +56,8 @@ class Querystring:
|
|
56
56
|
self,
|
57
57
|
params: Params,
|
58
58
|
*,
|
59
|
-
array_format:
|
60
|
-
nested_format:
|
59
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
60
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
61
61
|
) -> list[tuple[str, str]]:
|
62
62
|
opts = Options(
|
63
63
|
qs=self,
|
@@ -143,8 +143,8 @@ class Options:
|
|
143
143
|
self,
|
144
144
|
qs: Querystring = _qs,
|
145
145
|
*,
|
146
|
-
array_format:
|
147
|
-
nested_format:
|
146
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
147
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
148
148
|
) -> None:
|
149
149
|
self.array_format = qs.array_format if isinstance(array_format, NotGiven) else array_format
|
150
150
|
self.nested_format = qs.nested_format if isinstance(nested_format, NotGiven) else nested_format
|