chunkr-ai 0.1.0a6__py3-none-any.whl → 0.1.0a8__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 +2 -0
- chunkr_ai/_base_client.py +3 -3
- chunkr_ai/_client.py +31 -3
- chunkr_ai/_compat.py +48 -48
- chunkr_ai/_constants.py +5 -5
- chunkr_ai/_exceptions.py +4 -0
- chunkr_ai/_models.py +41 -41
- chunkr_ai/_types.py +35 -1
- chunkr_ai/_utils/__init__.py +9 -2
- chunkr_ai/_utils/_compat.py +45 -0
- chunkr_ai/_utils/_datetime_parse.py +136 -0
- chunkr_ai/_utils/_transform.py +11 -1
- chunkr_ai/_utils/_typing.py +6 -1
- chunkr_ai/_utils/_utils.py +0 -1
- chunkr_ai/_version.py +1 -1
- chunkr_ai/resources/__init__.py +14 -0
- chunkr_ai/resources/files.py +3 -3
- chunkr_ai/resources/tasks/__init__.py +14 -0
- chunkr_ai/resources/tasks/extract.py +393 -0
- chunkr_ai/resources/tasks/parse.py +110 -286
- chunkr_ai/resources/tasks/tasks.py +64 -32
- chunkr_ai/resources/webhooks.py +193 -0
- chunkr_ai/types/__init__.py +27 -1
- chunkr_ai/types/bounding_box.py +19 -0
- chunkr_ai/types/cell.py +39 -0
- chunkr_ai/types/cell_style.py +28 -0
- chunkr_ai/types/chunk.py +40 -0
- chunkr_ai/types/chunk_processing.py +40 -0
- chunkr_ai/types/chunk_processing_param.py +42 -0
- chunkr_ai/types/extract_configuration.py +24 -0
- chunkr_ai/types/extract_output_response.py +62 -0
- chunkr_ai/types/file_create_params.py +2 -1
- chunkr_ai/types/file_info.py +21 -0
- chunkr_ai/types/generation_config.py +29 -0
- chunkr_ai/types/generation_config_param.py +29 -0
- chunkr_ai/types/llm_processing.py +36 -0
- chunkr_ai/types/llm_processing_param.py +36 -0
- chunkr_ai/types/ocr_result.py +28 -0
- chunkr_ai/types/page.py +27 -0
- chunkr_ai/types/parse_configuration.py +64 -0
- chunkr_ai/types/parse_configuration_param.py +65 -0
- chunkr_ai/types/parse_output_response.py +29 -0
- chunkr_ai/types/segment.py +109 -0
- chunkr_ai/types/segment_processing.py +228 -0
- chunkr_ai/types/segment_processing_param.py +229 -0
- chunkr_ai/types/task_extract_updated_webhook_event.py +22 -0
- chunkr_ai/types/task_get_params.py +0 -3
- chunkr_ai/types/task_list_params.py +7 -1
- chunkr_ai/types/task_parse_updated_webhook_event.py +22 -0
- chunkr_ai/types/task_response.py +68 -0
- chunkr_ai/types/tasks/__init__.py +7 -1
- chunkr_ai/types/tasks/extract_create_params.py +47 -0
- chunkr_ai/types/tasks/extract_create_response.py +67 -0
- chunkr_ai/types/tasks/extract_get_params.py +18 -0
- chunkr_ai/types/tasks/extract_get_response.py +67 -0
- chunkr_ai/types/tasks/parse_create_params.py +25 -793
- chunkr_ai/types/tasks/parse_create_response.py +55 -0
- chunkr_ai/types/tasks/parse_get_params.py +18 -0
- chunkr_ai/types/tasks/parse_get_response.py +55 -0
- chunkr_ai/types/unwrap_webhook_event.py +11 -0
- chunkr_ai/types/version_info.py +31 -0
- chunkr_ai/types/webhook_url_response.py +9 -0
- {chunkr_ai-0.1.0a6.dist-info → chunkr_ai-0.1.0a8.dist-info}/METADATA +14 -13
- chunkr_ai-0.1.0a8.dist-info/RECORD +88 -0
- chunkr_ai/types/task.py +0 -1225
- chunkr_ai/types/tasks/parse_update_params.py +0 -845
- chunkr_ai-0.1.0a6.dist-info/RECORD +0 -52
- {chunkr_ai-0.1.0a6.dist-info → chunkr_ai-0.1.0a8.dist-info}/WHEEL +0 -0
- {chunkr_ai-0.1.0a6.dist-info → chunkr_ai-0.1.0a8.dist-info}/licenses/LICENSE +0 -0
chunkr_ai/__init__.py
CHANGED
@@ -24,6 +24,7 @@ from ._exceptions import (
|
|
24
24
|
InternalServerError,
|
25
25
|
PermissionDeniedError,
|
26
26
|
UnprocessableEntityError,
|
27
|
+
APIWebhookValidationError,
|
27
28
|
APIResponseValidationError,
|
28
29
|
)
|
29
30
|
from ._base_client import DefaultHttpxClient, DefaultAioHttpClient, DefaultAsyncHttpxClient
|
@@ -45,6 +46,7 @@ __all__ = [
|
|
45
46
|
"APITimeoutError",
|
46
47
|
"APIConnectionError",
|
47
48
|
"APIResponseValidationError",
|
49
|
+
"APIWebhookValidationError",
|
48
50
|
"BadRequestError",
|
49
51
|
"AuthenticationError",
|
50
52
|
"PermissionDeniedError",
|
chunkr_ai/_base_client.py
CHANGED
@@ -59,7 +59,7 @@ from ._types import (
|
|
59
59
|
ModelBuilderProtocol,
|
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,
|
@@ -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
|
chunkr_ai/_client.py
CHANGED
@@ -21,7 +21,7 @@ from ._types import (
|
|
21
21
|
)
|
22
22
|
from ._utils import is_given, get_async_library
|
23
23
|
from ._version import __version__
|
24
|
-
from .resources import files, health
|
24
|
+
from .resources import files, health, webhooks
|
25
25
|
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
|
26
26
|
from ._exceptions import ChunkrError, APIStatusError
|
27
27
|
from ._base_client import (
|
@@ -38,16 +38,19 @@ class Chunkr(SyncAPIClient):
|
|
38
38
|
tasks: tasks.TasksResource
|
39
39
|
files: files.FilesResource
|
40
40
|
health: health.HealthResource
|
41
|
+
webhooks: webhooks.WebhooksResource
|
41
42
|
with_raw_response: ChunkrWithRawResponse
|
42
43
|
with_streaming_response: ChunkrWithStreamedResponse
|
43
44
|
|
44
45
|
# client options
|
45
46
|
api_key: str
|
47
|
+
webhook_key: str | None
|
46
48
|
|
47
49
|
def __init__(
|
48
50
|
self,
|
49
51
|
*,
|
50
52
|
api_key: str | None = None,
|
53
|
+
webhook_key: str | None = None,
|
51
54
|
base_url: str | httpx.URL | None = None,
|
52
55
|
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
53
56
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
@@ -69,7 +72,9 @@ class Chunkr(SyncAPIClient):
|
|
69
72
|
) -> None:
|
70
73
|
"""Construct a new synchronous Chunkr client instance.
|
71
74
|
|
72
|
-
This automatically infers the
|
75
|
+
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
|
76
|
+
- `api_key` from `CHUNKR_API_KEY`
|
77
|
+
- `webhook_key` from `CHUNKR_WEBHOOK_KEY`
|
73
78
|
"""
|
74
79
|
if api_key is None:
|
75
80
|
api_key = os.environ.get("CHUNKR_API_KEY")
|
@@ -79,6 +84,10 @@ class Chunkr(SyncAPIClient):
|
|
79
84
|
)
|
80
85
|
self.api_key = api_key
|
81
86
|
|
87
|
+
if webhook_key is None:
|
88
|
+
webhook_key = os.environ.get("CHUNKR_WEBHOOK_KEY")
|
89
|
+
self.webhook_key = webhook_key
|
90
|
+
|
82
91
|
if base_url is None:
|
83
92
|
base_url = os.environ.get("CHUNKR_BASE_URL")
|
84
93
|
if base_url is None:
|
@@ -100,6 +109,7 @@ class Chunkr(SyncAPIClient):
|
|
100
109
|
self.tasks = tasks.TasksResource(self)
|
101
110
|
self.files = files.FilesResource(self)
|
102
111
|
self.health = health.HealthResource(self)
|
112
|
+
self.webhooks = webhooks.WebhooksResource(self)
|
103
113
|
self.with_raw_response = ChunkrWithRawResponse(self)
|
104
114
|
self.with_streaming_response = ChunkrWithStreamedResponse(self)
|
105
115
|
|
@@ -127,6 +137,7 @@ class Chunkr(SyncAPIClient):
|
|
127
137
|
self,
|
128
138
|
*,
|
129
139
|
api_key: str | None = None,
|
140
|
+
webhook_key: str | None = None,
|
130
141
|
base_url: str | httpx.URL | None = None,
|
131
142
|
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
132
143
|
http_client: httpx.Client | None = None,
|
@@ -161,6 +172,7 @@ class Chunkr(SyncAPIClient):
|
|
161
172
|
http_client = http_client or self._client
|
162
173
|
return self.__class__(
|
163
174
|
api_key=api_key or self.api_key,
|
175
|
+
webhook_key=webhook_key or self.webhook_key,
|
164
176
|
base_url=base_url or self.base_url,
|
165
177
|
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
166
178
|
http_client=http_client,
|
@@ -212,16 +224,19 @@ class AsyncChunkr(AsyncAPIClient):
|
|
212
224
|
tasks: tasks.AsyncTasksResource
|
213
225
|
files: files.AsyncFilesResource
|
214
226
|
health: health.AsyncHealthResource
|
227
|
+
webhooks: webhooks.AsyncWebhooksResource
|
215
228
|
with_raw_response: AsyncChunkrWithRawResponse
|
216
229
|
with_streaming_response: AsyncChunkrWithStreamedResponse
|
217
230
|
|
218
231
|
# client options
|
219
232
|
api_key: str
|
233
|
+
webhook_key: str | None
|
220
234
|
|
221
235
|
def __init__(
|
222
236
|
self,
|
223
237
|
*,
|
224
238
|
api_key: str | None = None,
|
239
|
+
webhook_key: str | None = None,
|
225
240
|
base_url: str | httpx.URL | None = None,
|
226
241
|
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
227
242
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
@@ -243,7 +258,9 @@ class AsyncChunkr(AsyncAPIClient):
|
|
243
258
|
) -> None:
|
244
259
|
"""Construct a new async AsyncChunkr client instance.
|
245
260
|
|
246
|
-
This automatically infers the
|
261
|
+
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
|
262
|
+
- `api_key` from `CHUNKR_API_KEY`
|
263
|
+
- `webhook_key` from `CHUNKR_WEBHOOK_KEY`
|
247
264
|
"""
|
248
265
|
if api_key is None:
|
249
266
|
api_key = os.environ.get("CHUNKR_API_KEY")
|
@@ -253,6 +270,10 @@ class AsyncChunkr(AsyncAPIClient):
|
|
253
270
|
)
|
254
271
|
self.api_key = api_key
|
255
272
|
|
273
|
+
if webhook_key is None:
|
274
|
+
webhook_key = os.environ.get("CHUNKR_WEBHOOK_KEY")
|
275
|
+
self.webhook_key = webhook_key
|
276
|
+
|
256
277
|
if base_url is None:
|
257
278
|
base_url = os.environ.get("CHUNKR_BASE_URL")
|
258
279
|
if base_url is None:
|
@@ -274,6 +295,7 @@ class AsyncChunkr(AsyncAPIClient):
|
|
274
295
|
self.tasks = tasks.AsyncTasksResource(self)
|
275
296
|
self.files = files.AsyncFilesResource(self)
|
276
297
|
self.health = health.AsyncHealthResource(self)
|
298
|
+
self.webhooks = webhooks.AsyncWebhooksResource(self)
|
277
299
|
self.with_raw_response = AsyncChunkrWithRawResponse(self)
|
278
300
|
self.with_streaming_response = AsyncChunkrWithStreamedResponse(self)
|
279
301
|
|
@@ -301,6 +323,7 @@ class AsyncChunkr(AsyncAPIClient):
|
|
301
323
|
self,
|
302
324
|
*,
|
303
325
|
api_key: str | None = None,
|
326
|
+
webhook_key: str | None = None,
|
304
327
|
base_url: str | httpx.URL | None = None,
|
305
328
|
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
306
329
|
http_client: httpx.AsyncClient | None = None,
|
@@ -335,6 +358,7 @@ class AsyncChunkr(AsyncAPIClient):
|
|
335
358
|
http_client = http_client or self._client
|
336
359
|
return self.__class__(
|
337
360
|
api_key=api_key or self.api_key,
|
361
|
+
webhook_key=webhook_key or self.webhook_key,
|
338
362
|
base_url=base_url or self.base_url,
|
339
363
|
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
340
364
|
http_client=http_client,
|
@@ -387,6 +411,7 @@ class ChunkrWithRawResponse:
|
|
387
411
|
self.tasks = tasks.TasksResourceWithRawResponse(client.tasks)
|
388
412
|
self.files = files.FilesResourceWithRawResponse(client.files)
|
389
413
|
self.health = health.HealthResourceWithRawResponse(client.health)
|
414
|
+
self.webhooks = webhooks.WebhooksResourceWithRawResponse(client.webhooks)
|
390
415
|
|
391
416
|
|
392
417
|
class AsyncChunkrWithRawResponse:
|
@@ -394,6 +419,7 @@ class AsyncChunkrWithRawResponse:
|
|
394
419
|
self.tasks = tasks.AsyncTasksResourceWithRawResponse(client.tasks)
|
395
420
|
self.files = files.AsyncFilesResourceWithRawResponse(client.files)
|
396
421
|
self.health = health.AsyncHealthResourceWithRawResponse(client.health)
|
422
|
+
self.webhooks = webhooks.AsyncWebhooksResourceWithRawResponse(client.webhooks)
|
397
423
|
|
398
424
|
|
399
425
|
class ChunkrWithStreamedResponse:
|
@@ -401,6 +427,7 @@ class ChunkrWithStreamedResponse:
|
|
401
427
|
self.tasks = tasks.TasksResourceWithStreamingResponse(client.tasks)
|
402
428
|
self.files = files.FilesResourceWithStreamingResponse(client.files)
|
403
429
|
self.health = health.HealthResourceWithStreamingResponse(client.health)
|
430
|
+
self.webhooks = webhooks.WebhooksResourceWithStreamingResponse(client.webhooks)
|
404
431
|
|
405
432
|
|
406
433
|
class AsyncChunkrWithStreamedResponse:
|
@@ -408,6 +435,7 @@ class AsyncChunkrWithStreamedResponse:
|
|
408
435
|
self.tasks = tasks.AsyncTasksResourceWithStreamingResponse(client.tasks)
|
409
436
|
self.files = files.AsyncFilesResourceWithStreamingResponse(client.files)
|
410
437
|
self.health = health.AsyncHealthResourceWithStreamingResponse(client.health)
|
438
|
+
self.webhooks = webhooks.AsyncWebhooksResourceWithStreamingResponse(client.webhooks)
|
411
439
|
|
412
440
|
|
413
441
|
Client = Chunkr
|
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/_constants.py
CHANGED
@@ -5,10 +5,10 @@ import httpx
|
|
5
5
|
RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
|
6
6
|
OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
|
7
7
|
|
8
|
-
# default timeout is
|
9
|
-
DEFAULT_TIMEOUT = httpx.Timeout(timeout=
|
10
|
-
DEFAULT_MAX_RETRIES =
|
8
|
+
# default timeout is 1 minute
|
9
|
+
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
|
10
|
+
DEFAULT_MAX_RETRIES = 2
|
11
11
|
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
|
12
12
|
|
13
|
-
INITIAL_RETRY_DELAY =
|
14
|
-
MAX_RETRY_DELAY =
|
13
|
+
INITIAL_RETRY_DELAY = 0.5
|
14
|
+
MAX_RETRY_DELAY = 8.0
|
chunkr_ai/_exceptions.py
CHANGED
@@ -54,6 +54,10 @@ class APIResponseValidationError(APIError):
|
|
54
54
|
self.status_code = response.status_code
|
55
55
|
|
56
56
|
|
57
|
+
class APIWebhookValidationError(APIError):
|
58
|
+
pass
|
59
|
+
|
60
|
+
|
57
61
|
class APIStatusError(APIError):
|
58
62
|
"""Raised when an API response has a status code of 4xx or 5xx."""
|
59
63
|
|
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
|
@@ -304,7 +304,7 @@ class BaseModel(pydantic.BaseModel):
|
|
304
304
|
exclude_none=exclude_none,
|
305
305
|
)
|
306
306
|
|
307
|
-
return cast(dict[str, Any], json_safe(dumped)) if mode == "json" else dumped
|
307
|
+
return cast("dict[str, Any]", json_safe(dumped)) if mode == "json" else dumped
|
308
308
|
|
309
309
|
@override
|
310
310
|
def model_dump_json(
|
@@ -363,10 +363,10 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
363
363
|
if value is None:
|
364
364
|
return field_get_default(field)
|
365
365
|
|
366
|
-
if
|
367
|
-
type_ = field.annotation
|
368
|
-
else:
|
366
|
+
if PYDANTIC_V1:
|
369
367
|
type_ = cast(type, field.outer_type_) # type: ignore
|
368
|
+
else:
|
369
|
+
type_ = field.annotation # type: ignore
|
370
370
|
|
371
371
|
if type_ is None:
|
372
372
|
raise RuntimeError(f"Unexpected field type is None for {key}")
|
@@ -375,7 +375,7 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
375
375
|
|
376
376
|
|
377
377
|
def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
|
378
|
-
if
|
378
|
+
if PYDANTIC_V1:
|
379
379
|
# TODO
|
380
380
|
return None
|
381
381
|
|
@@ -628,30 +628,30 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
|
|
628
628
|
for variant in get_args(union):
|
629
629
|
variant = strip_annotated_type(variant)
|
630
630
|
if is_basemodel_type(variant):
|
631
|
-
if
|
632
|
-
|
633
|
-
if not
|
631
|
+
if PYDANTIC_V1:
|
632
|
+
field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
|
633
|
+
if not field_info:
|
634
634
|
continue
|
635
635
|
|
636
636
|
# Note: if one variant defines an alias then they all should
|
637
|
-
discriminator_alias =
|
638
|
-
|
639
|
-
field_schema = field["schema"]
|
637
|
+
discriminator_alias = field_info.alias
|
640
638
|
|
641
|
-
if
|
642
|
-
for entry in
|
639
|
+
if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
|
640
|
+
for entry in get_args(annotation):
|
643
641
|
if isinstance(entry, str):
|
644
642
|
mapping[entry] = variant
|
645
643
|
else:
|
646
|
-
|
647
|
-
if not
|
644
|
+
field = _extract_field_schema_pv2(variant, discriminator_field_name)
|
645
|
+
if not field:
|
648
646
|
continue
|
649
647
|
|
650
648
|
# Note: if one variant defines an alias then they all should
|
651
|
-
discriminator_alias =
|
649
|
+
discriminator_alias = field.get("serialization_alias")
|
652
650
|
|
653
|
-
|
654
|
-
|
651
|
+
field_schema = field["schema"]
|
652
|
+
|
653
|
+
if field_schema["type"] == "literal":
|
654
|
+
for entry in cast("LiteralSchema", field_schema)["expected"]:
|
655
655
|
if isinstance(entry, str):
|
656
656
|
mapping[entry] = variant
|
657
657
|
|
@@ -714,7 +714,7 @@ else:
|
|
714
714
|
pass
|
715
715
|
|
716
716
|
|
717
|
-
if
|
717
|
+
if not PYDANTIC_V1:
|
718
718
|
from pydantic import TypeAdapter as _TypeAdapter
|
719
719
|
|
720
720
|
_CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))
|
@@ -782,12 +782,12 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
782
782
|
json_data: Union[Body, None] = None
|
783
783
|
extra_json: Union[AnyMapping, None] = None
|
784
784
|
|
785
|
-
if
|
786
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
787
|
-
else:
|
785
|
+
if PYDANTIC_V1:
|
788
786
|
|
789
787
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
790
788
|
arbitrary_types_allowed: bool = True
|
789
|
+
else:
|
790
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
791
791
|
|
792
792
|
def get_max_retries(self, max_retries: int) -> int:
|
793
793
|
if isinstance(self.max_retries, NotGiven):
|
@@ -820,9 +820,9 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
820
820
|
key: strip_not_given(value)
|
821
821
|
for key, value in values.items()
|
822
822
|
}
|
823
|
-
if
|
824
|
-
return super().
|
825
|
-
return
|
823
|
+
if PYDANTIC_V1:
|
824
|
+
return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
|
825
|
+
return super().model_construct(_fields_set, **kwargs)
|
826
826
|
|
827
827
|
if not TYPE_CHECKING:
|
828
828
|
# type checkers incorrectly complain about this assignment
|
chunkr_ai/_types.py
CHANGED
@@ -13,10 +13,21 @@ from typing import (
|
|
13
13
|
Mapping,
|
14
14
|
TypeVar,
|
15
15
|
Callable,
|
16
|
+
Iterator,
|
16
17
|
Optional,
|
17
18
|
Sequence,
|
18
19
|
)
|
19
|
-
from typing_extensions import
|
20
|
+
from typing_extensions import (
|
21
|
+
Set,
|
22
|
+
Literal,
|
23
|
+
Protocol,
|
24
|
+
TypeAlias,
|
25
|
+
TypedDict,
|
26
|
+
SupportsIndex,
|
27
|
+
overload,
|
28
|
+
override,
|
29
|
+
runtime_checkable,
|
30
|
+
)
|
20
31
|
|
21
32
|
import httpx
|
22
33
|
import pydantic
|
@@ -217,3 +228,26 @@ class _GenericAlias(Protocol):
|
|
217
228
|
class HttpxSendArgs(TypedDict, total=False):
|
218
229
|
auth: httpx.Auth
|
219
230
|
follow_redirects: bool
|
231
|
+
|
232
|
+
|
233
|
+
_T_co = TypeVar("_T_co", covariant=True)
|
234
|
+
|
235
|
+
|
236
|
+
if TYPE_CHECKING:
|
237
|
+
# This works because str.__contains__ does not accept object (either in typeshed or at runtime)
|
238
|
+
# https://github.com/hauntsaninja/useful_types/blob/5e9710f3875107d068e7679fd7fec9cfab0eff3b/useful_types/__init__.py#L285
|
239
|
+
class SequenceNotStr(Protocol[_T_co]):
|
240
|
+
@overload
|
241
|
+
def __getitem__(self, index: SupportsIndex, /) -> _T_co: ...
|
242
|
+
@overload
|
243
|
+
def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ...
|
244
|
+
def __contains__(self, value: object, /) -> bool: ...
|
245
|
+
def __len__(self) -> int: ...
|
246
|
+
def __iter__(self) -> Iterator[_T_co]: ...
|
247
|
+
def index(self, value: Any, start: int = 0, stop: int = ..., /) -> int: ...
|
248
|
+
def count(self, value: Any, /) -> int: ...
|
249
|
+
def __reversed__(self) -> Iterator[_T_co]: ...
|
250
|
+
else:
|
251
|
+
# just point this to a normal `Sequence` at runtime to avoid having to special case
|
252
|
+
# deserializing our custom sequence type
|
253
|
+
SequenceNotStr = Sequence
|