chunkr-ai 0.1.0a3__py3-none-any.whl → 0.1.0a4__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 -0
- chunkr_ai/_version.py +1 -1
- chunkr_ai/lib/tasks_poll.py +122 -0
- chunkr_ai/types/__init__.py +1 -1
- chunkr_ai/types/{files_page_response.py → files_list_response.py} +2 -2
- {chunkr_ai-0.1.0a3.dist-info → chunkr_ai-0.1.0a4.dist-info}/METADATA +1 -1
- {chunkr_ai-0.1.0a3.dist-info → chunkr_ai-0.1.0a4.dist-info}/RECORD +9 -8
- {chunkr_ai-0.1.0a3.dist-info → chunkr_ai-0.1.0a4.dist-info}/WHEEL +0 -0
- {chunkr_ai-0.1.0a3.dist-info → chunkr_ai-0.1.0a4.dist-info}/licenses/LICENSE +0 -0
chunkr_ai/__init__.py
CHANGED
@@ -72,6 +72,9 @@ __all__ = [
|
|
72
72
|
]
|
73
73
|
|
74
74
|
if not _t.TYPE_CHECKING:
|
75
|
+
# Load custom helpers that monkey-patch generated types.
|
76
|
+
# This keeps custom code separate from generated files, per Stainless guidance.
|
77
|
+
from .lib import tasks_poll as _tasks_poll # noqa: F401
|
75
78
|
from ._utils._resources_proxy import resources as resources
|
76
79
|
|
77
80
|
_setup_logging()
|
chunkr_ai/_version.py
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
"""
|
4
|
+
Custom helpers for task polling.
|
5
|
+
|
6
|
+
This module adds `Task.poll()` and `Task.apoll()` methods at runtime to the
|
7
|
+
generated `Task` model, without modifying generated code directly.
|
8
|
+
|
9
|
+
Usage:
|
10
|
+
task = client.tasks.get(task_id)
|
11
|
+
task = task.poll(client) # blocks until terminal state
|
12
|
+
|
13
|
+
# async
|
14
|
+
task = await async_client.tasks.get(task_id)
|
15
|
+
task = await task.apoll(async_client)
|
16
|
+
"""
|
17
|
+
|
18
|
+
import time
|
19
|
+
import asyncio
|
20
|
+
from typing import Protocol, cast
|
21
|
+
|
22
|
+
from .._types import NOT_GIVEN, NotGiven
|
23
|
+
from .._client import Chunkr, AsyncChunkr
|
24
|
+
from ..types.task import Task as _Task
|
25
|
+
from .._exceptions import ChunkrError
|
26
|
+
|
27
|
+
TERMINAL_STATUSES = {"Succeeded", "Failed", "Cancelled"}
|
28
|
+
|
29
|
+
|
30
|
+
def _task_poll(
|
31
|
+
self: _Task,
|
32
|
+
client: Chunkr,
|
33
|
+
*,
|
34
|
+
interval: float = 0.5,
|
35
|
+
timeout: float = 600.0,
|
36
|
+
include_chunks: bool | NotGiven = NOT_GIVEN,
|
37
|
+
base64_urls: bool | NotGiven = NOT_GIVEN,
|
38
|
+
) -> _Task:
|
39
|
+
"""Poll the task until it reaches a terminal status.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
client: Synchronous Chunkr client instance.
|
43
|
+
interval: Seconds to sleep between polls.
|
44
|
+
timeout: Maximum total seconds to wait before raising an error.
|
45
|
+
include_chunks: Whether to include chunks in the output response for each poll.
|
46
|
+
base64_urls: Whether to return base64 encoded URLs.
|
47
|
+
"""
|
48
|
+
start_time = time.monotonic()
|
49
|
+
current: _Task = self
|
50
|
+
|
51
|
+
class _TasksGetProtocol(Protocol):
|
52
|
+
def get(
|
53
|
+
self,
|
54
|
+
task_id: str,
|
55
|
+
*,
|
56
|
+
base64_urls: bool | NotGiven = NOT_GIVEN,
|
57
|
+
include_chunks: bool | NotGiven = NOT_GIVEN,
|
58
|
+
) -> _Task: ...
|
59
|
+
|
60
|
+
resource = cast(_TasksGetProtocol, client.tasks)
|
61
|
+
|
62
|
+
while current.status not in TERMINAL_STATUSES:
|
63
|
+
if time.monotonic() - start_time > timeout:
|
64
|
+
raise ChunkrError("Task polling timed out.")
|
65
|
+
|
66
|
+
if interval > 0:
|
67
|
+
time.sleep(interval)
|
68
|
+
|
69
|
+
current = resource.get(
|
70
|
+
current.task_id,
|
71
|
+
include_chunks=include_chunks,
|
72
|
+
base64_urls=base64_urls,
|
73
|
+
)
|
74
|
+
|
75
|
+
return current
|
76
|
+
|
77
|
+
|
78
|
+
async def _task_apoll(
|
79
|
+
self: _Task,
|
80
|
+
client: AsyncChunkr,
|
81
|
+
*,
|
82
|
+
interval: float = 0.5,
|
83
|
+
timeout: float = 600.0,
|
84
|
+
include_chunks: bool | NotGiven = NOT_GIVEN,
|
85
|
+
base64_urls: bool | NotGiven = NOT_GIVEN,
|
86
|
+
) -> _Task:
|
87
|
+
"""Async poll the task until it reaches a terminal status."""
|
88
|
+
start_time = time.monotonic()
|
89
|
+
current: _Task = self
|
90
|
+
|
91
|
+
class _AsyncTasksGetProtocol(Protocol):
|
92
|
+
async def get(
|
93
|
+
self,
|
94
|
+
task_id: str,
|
95
|
+
*,
|
96
|
+
base64_urls: bool | NotGiven = NOT_GIVEN,
|
97
|
+
include_chunks: bool | NotGiven = NOT_GIVEN,
|
98
|
+
) -> _Task: ...
|
99
|
+
|
100
|
+
aresource = cast(_AsyncTasksGetProtocol, client.tasks)
|
101
|
+
|
102
|
+
while current.status not in TERMINAL_STATUSES:
|
103
|
+
if time.monotonic() - start_time > timeout:
|
104
|
+
raise ChunkrError("Task polling timed out.")
|
105
|
+
|
106
|
+
if interval > 0:
|
107
|
+
await asyncio.sleep(interval)
|
108
|
+
|
109
|
+
current = await aresource.get(
|
110
|
+
current.task_id,
|
111
|
+
include_chunks=include_chunks,
|
112
|
+
base64_urls=base64_urls,
|
113
|
+
)
|
114
|
+
|
115
|
+
return current
|
116
|
+
|
117
|
+
|
118
|
+
# Attach methods to the generated Task model
|
119
|
+
_Task.poll = _task_poll # type: ignore[attr-defined]
|
120
|
+
_Task.apoll = _task_apoll # type: ignore[attr-defined]
|
121
|
+
|
122
|
+
|
chunkr_ai/types/__init__.py
CHANGED
@@ -11,5 +11,5 @@ from .task_get_params import TaskGetParams as TaskGetParams
|
|
11
11
|
from .file_list_params import FileListParams as FileListParams
|
12
12
|
from .task_list_params import TaskListParams as TaskListParams
|
13
13
|
from .file_create_params import FileCreateParams as FileCreateParams
|
14
|
-
from .
|
14
|
+
from .files_list_response import FilesListResponse as FilesListResponse
|
15
15
|
from .health_check_response import HealthCheckResponse as HealthCheckResponse
|
@@ -6,10 +6,10 @@ from datetime import datetime
|
|
6
6
|
from .file import File
|
7
7
|
from .._models import BaseModel
|
8
8
|
|
9
|
-
__all__ = ["
|
9
|
+
__all__ = ["FilesListResponse"]
|
10
10
|
|
11
11
|
|
12
|
-
class
|
12
|
+
class FilesListResponse(BaseModel):
|
13
13
|
files: List[File]
|
14
14
|
"""List of files"""
|
15
15
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: chunkr-ai
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.0a4
|
4
4
|
Summary: The official Python library for the chunkr API
|
5
5
|
Project-URL: Homepage, https://github.com/lumina-ai-inc/chunkr-python
|
6
6
|
Project-URL: Repository, https://github.com/lumina-ai-inc/chunkr-python
|
@@ -1,4 +1,4 @@
|
|
1
|
-
chunkr_ai/__init__.py,sha256=
|
1
|
+
chunkr_ai/__init__.py,sha256=RqteAJ-1Ma7DnoNz_AJJIjmynGeoGJ3F4ZKrSnjp9zs,2793
|
2
2
|
chunkr_ai/_base_client.py,sha256=Nv5b_rmVdmmPbF42mlOfymbSC6lxcYsrsvBhKSBDXWQ,67038
|
3
3
|
chunkr_ai/_client.py,sha256=fseZHGtnXGw3uSa1Le8SxH2oSBeHczn6mOsLeLGj4rY,15867
|
4
4
|
chunkr_ai/_compat.py,sha256=VWemUKbj6DDkQ-O4baSpHVLJafotzeXmCQGJugfVTIw,6580
|
@@ -11,7 +11,7 @@ chunkr_ai/_resource.py,sha256=f5tiwjxcKdbeMor8idoHtMFTUhqD9yc2xXtq5rqeLLk,1100
|
|
11
11
|
chunkr_ai/_response.py,sha256=xXNpF53hiYARmAW7npKuxQ5UHAEjgAzm7ME_L3eIstY,28800
|
12
12
|
chunkr_ai/_streaming.py,sha256=ZmyrVWk7-AWkLAATR55WgNxnyFzYmaqJt2LthA_PTqQ,10100
|
13
13
|
chunkr_ai/_types.py,sha256=dnzU2Q2tLcuk29QFEcnPC1wp0-4XB4Cpef_3AnRhV5Y,6200
|
14
|
-
chunkr_ai/_version.py,sha256=
|
14
|
+
chunkr_ai/_version.py,sha256=hJYiv4ePWLGN-Ur1VkK5zJERczdAZjPDNh7APrmHgBE,169
|
15
15
|
chunkr_ai/pagination.py,sha256=bT-ErcJ80YlKBV6tWq2s9uqg-wv7o66SKe_AgUAGrKc,3533
|
16
16
|
chunkr_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
17
|
chunkr_ai/_utils/__init__.py,sha256=PNZ_QJuzZEgyYXqkO1HVhGkj5IU9bglVUcw7H-Knjzw,2062
|
@@ -25,20 +25,21 @@ chunkr_ai/_utils/_transform.py,sha256=n7kskEWz6o__aoNvhFoGVyDoalNe6mJwp-g7BWkdj8
|
|
25
25
|
chunkr_ai/_utils/_typing.py,sha256=D0DbbNu8GnYQTSICnTSHDGsYXj8TcAKyhejb0XcnjtY,4602
|
26
26
|
chunkr_ai/_utils/_utils.py,sha256=ts4CiiuNpFiGB6YMdkQRh2SZvYvsl7mAF-JWHCcLDf4,12312
|
27
27
|
chunkr_ai/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
28
|
+
chunkr_ai/lib/tasks_poll.py,sha256=3yosl_hH5j6NVNH9mANqneAW0FJSbIV9dMoTcF-OdJU,3341
|
28
29
|
chunkr_ai/resources/__init__.py,sha256=K-axuAEg2pJQl45N5ao1tm8AnRwpQVVNp_b6qSMgB6A,1426
|
29
30
|
chunkr_ai/resources/files.py,sha256=Dez080pD_xUr1jOW3y6QSg92sSSZhEYObPze2RWktoY,26304
|
30
31
|
chunkr_ai/resources/health.py,sha256=XTvUtRs5hEK-uccb_40mcIex85eEUo1a171nQUjpSOs,4965
|
31
32
|
chunkr_ai/resources/tasks/__init__.py,sha256=W-sclAx_Kfm7OBGlSs694QzNCMkewtz9LU9KRcb8Ud0,976
|
32
33
|
chunkr_ai/resources/tasks/parse.py,sha256=um0sw2ZU7bY6AK7LKAS0GxAHUyuSzav_NlhxXPjNjxY,28491
|
33
34
|
chunkr_ai/resources/tasks/tasks.py,sha256=UC15zZNpY7u85X_JJudDuNrnpaeULiISaBde4BRHGSw,21653
|
34
|
-
chunkr_ai/types/__init__.py,sha256=
|
35
|
+
chunkr_ai/types/__init__.py,sha256=DSRAMgXVRTZM2t8s2yrFU-FHt3FTs_wpZfVILH1zjJ0,728
|
35
36
|
chunkr_ai/types/delete.py,sha256=EU78fjXpc8-fqvgcFTuJ0ejs5u_UjbhOz5frkeUHvxY,225
|
36
37
|
chunkr_ai/types/file.py,sha256=kOxR0g-3A-qOxz2cjuTcq0wFMqPoph9uQuLYQ56zb-c,718
|
37
38
|
chunkr_ai/types/file_create_params.py,sha256=eR5tUPv1ZxGk94y6Ps5PDF5AoHsTfPRM9jNxnrEEnCQ,440
|
38
39
|
chunkr_ai/types/file_list_params.py,sha256=oJGTf88aAxBhNfmQDbxGT63b95HdSbMXUubKjXM22_U,822
|
39
40
|
chunkr_ai/types/file_url.py,sha256=L434WnOXkNmt59dJiaAgT1_3pN3BIsxm2q14zHQK6xY,365
|
40
41
|
chunkr_ai/types/file_url_params.py,sha256=ZHfKiy_6B25StdDemulavGcsPggNNMKLWf6KN7xfPTY,413
|
41
|
-
chunkr_ai/types/
|
42
|
+
chunkr_ai/types/files_list_response.py,sha256=ggSRWhTzZWjcDXxStyCzrYICXXB5TqnL2j-SN9mHH_g,506
|
42
43
|
chunkr_ai/types/health_check_response.py,sha256=6Zn5YYHCQf2RgMjDlf39mtiTPqfaBfC9Vv599U_rKCI,200
|
43
44
|
chunkr_ai/types/task.py,sha256=aew6aT0ngKtwgfUCSCvMTJOBQL1Xp0F0otB_wxumIGQ,46703
|
44
45
|
chunkr_ai/types/task_get_params.py,sha256=Nx2luhebcoaiuRln4KP4FarWvBPd1OYi__efi56zHPM,460
|
@@ -46,7 +47,7 @@ chunkr_ai/types/task_list_params.py,sha256=fCku42QW6QUsLmZgKJBaxisGvUcmcQ5fa6LgH
|
|
46
47
|
chunkr_ai/types/tasks/__init__.py,sha256=VdLEmQvgPoiykSEYaRhkMYVaIueGDkR4P_MjCq9SbQY,267
|
47
48
|
chunkr_ai/types/tasks/parse_create_params.py,sha256=PBg2VR_OnBdB8K4NihuefGJXgUXBn7v5317LZG7PDks,34340
|
48
49
|
chunkr_ai/types/tasks/parse_update_params.py,sha256=B1cKfdX_cNDh0m2zDoH0FiZP_Qc-a5GFy-5iXHDHuy8,34113
|
49
|
-
chunkr_ai-0.1.
|
50
|
-
chunkr_ai-0.1.
|
51
|
-
chunkr_ai-0.1.
|
52
|
-
chunkr_ai-0.1.
|
50
|
+
chunkr_ai-0.1.0a4.dist-info/METADATA,sha256=241RRJb1pTZBg9IG3oGx3_WASrJDN8a2myyJhQ9TUNE,16441
|
51
|
+
chunkr_ai-0.1.0a4.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
52
|
+
chunkr_ai-0.1.0a4.dist-info/licenses/LICENSE,sha256=3FDRL-L-DFkrFy8yJpb1Nxhuztm0PB2kawcCgK5utFg,11336
|
53
|
+
chunkr_ai-0.1.0a4.dist-info/RECORD,,
|
File without changes
|
File without changes
|