chunkr-ai 0.1.0__py3-none-any.whl → 0.1.0a1__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 +89 -2
- chunkr_ai/_base_client.py +1995 -0
- chunkr_ai/_client.py +402 -0
- chunkr_ai/_compat.py +219 -0
- chunkr_ai/_constants.py +14 -0
- chunkr_ai/_exceptions.py +108 -0
- chunkr_ai/_files.py +123 -0
- chunkr_ai/_models.py +829 -0
- chunkr_ai/_qs.py +150 -0
- chunkr_ai/_resource.py +43 -0
- chunkr_ai/_response.py +830 -0
- chunkr_ai/_streaming.py +333 -0
- chunkr_ai/_types.py +219 -0
- chunkr_ai/_utils/__init__.py +57 -0
- chunkr_ai/_utils/_logs.py +25 -0
- chunkr_ai/_utils/_proxy.py +65 -0
- chunkr_ai/_utils/_reflection.py +42 -0
- chunkr_ai/_utils/_resources_proxy.py +24 -0
- chunkr_ai/_utils/_streams.py +12 -0
- chunkr_ai/_utils/_sync.py +86 -0
- chunkr_ai/_utils/_transform.py +447 -0
- chunkr_ai/_utils/_typing.py +151 -0
- chunkr_ai/_utils/_utils.py +422 -0
- chunkr_ai/_version.py +4 -0
- chunkr_ai/lib/.keep +4 -0
- chunkr_ai/pagination.py +71 -0
- chunkr_ai/resources/__init__.py +33 -0
- chunkr_ai/resources/health.py +136 -0
- chunkr_ai/resources/task.py +1166 -0
- chunkr_ai/types/__init__.py +27 -0
- chunkr_ai/types/auto_generation_config.py +39 -0
- chunkr_ai/types/auto_generation_config_param.py +39 -0
- chunkr_ai/types/bounding_box.py +19 -0
- chunkr_ai/types/chunk_processing.py +40 -0
- chunkr_ai/types/chunk_processing_param.py +42 -0
- chunkr_ai/types/health_check_response.py +7 -0
- chunkr_ai/types/ignore_generation_config.py +39 -0
- chunkr_ai/types/ignore_generation_config_param.py +39 -0
- chunkr_ai/types/llm_generation_config.py +39 -0
- chunkr_ai/types/llm_generation_config_param.py +39 -0
- chunkr_ai/types/llm_processing.py +36 -0
- chunkr_ai/types/llm_processing_param.py +36 -0
- chunkr_ai/types/picture_generation_config.py +39 -0
- chunkr_ai/types/picture_generation_config_param.py +39 -0
- chunkr_ai/types/segment_processing.py +280 -0
- chunkr_ai/types/segment_processing_param.py +281 -0
- chunkr_ai/types/table_generation_config.py +39 -0
- chunkr_ai/types/table_generation_config_param.py +39 -0
- chunkr_ai/types/task.py +379 -0
- chunkr_ai/types/task_get_params.py +18 -0
- chunkr_ai/types/task_list_params.py +37 -0
- chunkr_ai/types/task_parse_params.py +90 -0
- chunkr_ai/types/task_update_params.py +90 -0
- chunkr_ai-0.1.0a1.dist-info/METADATA +504 -0
- chunkr_ai-0.1.0a1.dist-info/RECORD +58 -0
- {chunkr_ai-0.1.0.dist-info → chunkr_ai-0.1.0a1.dist-info}/WHEEL +1 -2
- chunkr_ai-0.1.0a1.dist-info/licenses/LICENSE +201 -0
- chunkr_ai/api/auth.py +0 -13
- chunkr_ai/api/chunkr.py +0 -103
- chunkr_ai/api/chunkr_base.py +0 -185
- chunkr_ai/api/configuration.py +0 -313
- chunkr_ai/api/decorators.py +0 -101
- chunkr_ai/api/misc.py +0 -139
- chunkr_ai/api/protocol.py +0 -14
- chunkr_ai/api/task_response.py +0 -208
- chunkr_ai/models.py +0 -55
- chunkr_ai-0.1.0.dist-info/METADATA +0 -268
- chunkr_ai-0.1.0.dist-info/RECORD +0 -16
- chunkr_ai-0.1.0.dist-info/licenses/LICENSE +0 -21
- chunkr_ai-0.1.0.dist-info/top_level.txt +0 -1
- /chunkr_ai/{api/__init__.py → py.typed} +0 -0
chunkr_ai/api/task_response.py
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
from datetime import datetime
|
2
|
-
from typing import Optional, cast, Awaitable, Union
|
3
|
-
from pydantic import BaseModel, PrivateAttr
|
4
|
-
import asyncio
|
5
|
-
import json
|
6
|
-
import os
|
7
|
-
import httpx
|
8
|
-
|
9
|
-
from .configuration import Configuration, OutputConfiguration, OutputResponse, Status
|
10
|
-
from .protocol import ChunkrClientProtocol
|
11
|
-
from .misc import prepare_upload_data
|
12
|
-
from .decorators import anywhere, require_task, retry_on_429
|
13
|
-
|
14
|
-
class TaskResponse(BaseModel):
|
15
|
-
configuration: OutputConfiguration
|
16
|
-
created_at: datetime
|
17
|
-
expires_at: Optional[datetime] = None
|
18
|
-
finished_at: Optional[datetime] = None
|
19
|
-
message: Optional[str] = None
|
20
|
-
output: Optional[OutputResponse] = None
|
21
|
-
started_at: Optional[datetime] = None
|
22
|
-
status: Status
|
23
|
-
task_id: str
|
24
|
-
task_url: Optional[str] = None
|
25
|
-
include_chunks: bool = False
|
26
|
-
_base64_urls: bool = False
|
27
|
-
_client: Optional[ChunkrClientProtocol] = PrivateAttr(default=None)
|
28
|
-
|
29
|
-
def with_client(self, client: ChunkrClientProtocol, include_chunks: bool = False, base64_urls: bool = False) -> "TaskResponse":
|
30
|
-
self._client = client
|
31
|
-
self.include_chunks = include_chunks
|
32
|
-
self._base64_urls = base64_urls
|
33
|
-
return self
|
34
|
-
|
35
|
-
def _check_status(self) -> Optional["TaskResponse"]:
|
36
|
-
"""Helper method to check task status and handle completion/failure"""
|
37
|
-
if self.status == "Failed":
|
38
|
-
if getattr(self._client, 'raise_on_failure', True):
|
39
|
-
raise ValueError(self.message)
|
40
|
-
return self
|
41
|
-
if self.status not in ("Starting", "Processing"):
|
42
|
-
return self
|
43
|
-
return None
|
44
|
-
|
45
|
-
@require_task()
|
46
|
-
async def _poll_request(self) -> dict:
|
47
|
-
try:
|
48
|
-
if not self._client:
|
49
|
-
raise ValueError("Chunkr client protocol is not initialized")
|
50
|
-
if not self._client._client or self._client._client.is_closed:
|
51
|
-
raise ValueError("httpx client is not open")
|
52
|
-
assert self.task_url is not None
|
53
|
-
r = await self._client._client.get(
|
54
|
-
self.task_url, headers=self._client._headers()
|
55
|
-
)
|
56
|
-
r.raise_for_status()
|
57
|
-
return r.json()
|
58
|
-
except (ConnectionError, TimeoutError, OSError,
|
59
|
-
httpx.ReadTimeout, httpx.ConnectTimeout,
|
60
|
-
httpx.WriteTimeout, httpx.PoolTimeout,
|
61
|
-
httpx.ConnectError, httpx.ReadError,
|
62
|
-
httpx.NetworkError) as e:
|
63
|
-
print(f"Connection error while polling the task: {str(e)}\nretrying...")
|
64
|
-
await asyncio.sleep(0.5)
|
65
|
-
return await self._poll_request()
|
66
|
-
except Exception as e:
|
67
|
-
raise e
|
68
|
-
|
69
|
-
@anywhere()
|
70
|
-
async def poll(self) -> "TaskResponse":
|
71
|
-
"""Poll the task for completion."""
|
72
|
-
while True:
|
73
|
-
j = await self._poll_request()
|
74
|
-
if not self._client:
|
75
|
-
raise ValueError("Chunkr client protocol is not initialized")
|
76
|
-
updated = TaskResponse(**j).with_client(self._client)
|
77
|
-
self.__dict__.update(updated.__dict__)
|
78
|
-
if res := self._check_status():
|
79
|
-
return res
|
80
|
-
await asyncio.sleep(0.5)
|
81
|
-
|
82
|
-
@anywhere()
|
83
|
-
@require_task()
|
84
|
-
@retry_on_429()
|
85
|
-
async def update(self, config: Configuration) -> "TaskResponse":
|
86
|
-
"""Update the task configuration."""
|
87
|
-
data = await prepare_upload_data(None, None, config)
|
88
|
-
if not self._client:
|
89
|
-
raise ValueError("Chunkr client protocol is not initialized")
|
90
|
-
if not self._client._client or self._client._client.is_closed:
|
91
|
-
raise ValueError("httpx client is not open")
|
92
|
-
assert self.task_url is not None
|
93
|
-
r = await self._client._client.patch(
|
94
|
-
f"{self.task_url}/parse",
|
95
|
-
json=data,
|
96
|
-
headers=self._client._headers()
|
97
|
-
)
|
98
|
-
r.raise_for_status()
|
99
|
-
updated = TaskResponse(**r.json()).with_client(self._client)
|
100
|
-
self.__dict__.update(updated.__dict__)
|
101
|
-
return cast(TaskResponse, self.poll())
|
102
|
-
|
103
|
-
@anywhere()
|
104
|
-
@require_task()
|
105
|
-
async def delete(self) -> "TaskResponse":
|
106
|
-
"""Delete the task."""
|
107
|
-
if not self._client:
|
108
|
-
raise ValueError("Chunkr client protocol is not initialized")
|
109
|
-
if not self._client._client or self._client._client.is_closed:
|
110
|
-
raise ValueError("httpx client is not open")
|
111
|
-
assert self.task_url is not None
|
112
|
-
r = await self._client._client.delete(
|
113
|
-
self.task_url, headers=self._client._headers()
|
114
|
-
)
|
115
|
-
r.raise_for_status()
|
116
|
-
return self
|
117
|
-
|
118
|
-
@anywhere()
|
119
|
-
@require_task()
|
120
|
-
async def cancel(self) -> "TaskResponse":
|
121
|
-
"""Cancel the task."""
|
122
|
-
if not self._client:
|
123
|
-
raise ValueError("Chunkr client protocol is not initialized")
|
124
|
-
if not self._client._client or self._client._client.is_closed:
|
125
|
-
raise ValueError("httpx client is not open")
|
126
|
-
assert self.task_url is not None
|
127
|
-
r = await self._client._client.get(
|
128
|
-
f"{self.task_url}/cancel", headers=self._client._headers()
|
129
|
-
)
|
130
|
-
r.raise_for_status()
|
131
|
-
return cast(TaskResponse, self.poll())
|
132
|
-
|
133
|
-
def _write_to_file(self, content: Union[str, dict], output_file: Optional[str], is_json: bool = False) -> None:
|
134
|
-
"""Helper method to write content to a file
|
135
|
-
|
136
|
-
Args:
|
137
|
-
content: Content to write (string or dict for JSON)
|
138
|
-
output_file: Path to save the content
|
139
|
-
is_json: Whether the content should be written as JSON
|
140
|
-
"""
|
141
|
-
class DateTimeEncoder(json.JSONEncoder):
|
142
|
-
def default(self, obj):
|
143
|
-
if isinstance(obj, datetime):
|
144
|
-
return obj.isoformat()
|
145
|
-
return super().default(obj)
|
146
|
-
if output_file:
|
147
|
-
directory = os.path.dirname(output_file)
|
148
|
-
if directory:
|
149
|
-
os.makedirs(directory, exist_ok=True)
|
150
|
-
with open(output_file, "w", encoding="utf-8") as f:
|
151
|
-
if is_json:
|
152
|
-
json.dump(content, f, cls=DateTimeEncoder, indent=2)
|
153
|
-
else:
|
154
|
-
if isinstance(content, str):
|
155
|
-
f.write(content)
|
156
|
-
else:
|
157
|
-
raise ValueError("Content is not a string")
|
158
|
-
|
159
|
-
def html(self, output_file: Optional[str] = None) -> str:
|
160
|
-
"""Get the full HTML of the task
|
161
|
-
|
162
|
-
Args:
|
163
|
-
output_file (str, optional): Path to save the HTML content. Defaults to None.
|
164
|
-
"""
|
165
|
-
content = self._get_content("html")
|
166
|
-
self._write_to_file(content, output_file)
|
167
|
-
return content
|
168
|
-
|
169
|
-
def markdown(self, output_file: Optional[str] = None) -> str:
|
170
|
-
"""Get the full markdown of the task
|
171
|
-
|
172
|
-
Args:
|
173
|
-
output_file (str, optional): Path to save the markdown content. Defaults to None.
|
174
|
-
"""
|
175
|
-
content = self._get_content("markdown", separator="\n\n")
|
176
|
-
self._write_to_file(content, output_file)
|
177
|
-
return content
|
178
|
-
|
179
|
-
def content(self, output_file: Optional[str] = None) -> str:
|
180
|
-
"""Get the full content of the task
|
181
|
-
|
182
|
-
Args:
|
183
|
-
output_file (str, optional): Path to save the content. Defaults to None.
|
184
|
-
"""
|
185
|
-
content = self._get_content("content")
|
186
|
-
self._write_to_file(content, output_file)
|
187
|
-
return content
|
188
|
-
|
189
|
-
def json(self, output_file: Optional[str] = None) -> dict:
|
190
|
-
"""Get the full task data as JSON
|
191
|
-
|
192
|
-
Args:
|
193
|
-
output_file (str, optional): Path to save the task data as JSON. Defaults to None.
|
194
|
-
"""
|
195
|
-
data = self.model_dump()
|
196
|
-
self._write_to_file(data, output_file, is_json=True)
|
197
|
-
return data
|
198
|
-
|
199
|
-
def _get_content(self, t: str, separator: str = "\n") -> str:
|
200
|
-
if not self.output:
|
201
|
-
return ""
|
202
|
-
parts = []
|
203
|
-
for c in self.output.chunks:
|
204
|
-
for s in c.segments:
|
205
|
-
v = getattr(s, t)
|
206
|
-
if v:
|
207
|
-
parts.append(v)
|
208
|
-
return separator.join(parts)
|
chunkr_ai/models.py
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
from .api.configuration import (
|
2
|
-
BoundingBox,
|
3
|
-
Chunk,
|
4
|
-
ChunkProcessing,
|
5
|
-
Configuration,
|
6
|
-
CroppingStrategy,
|
7
|
-
EmbedSource,
|
8
|
-
ErrorHandlingStrategy,
|
9
|
-
FallbackStrategy,
|
10
|
-
GenerationStrategy,
|
11
|
-
GenerationConfig,
|
12
|
-
LlmProcessing,
|
13
|
-
Model,
|
14
|
-
OCRResult,
|
15
|
-
OcrStrategy,
|
16
|
-
OutputResponse,
|
17
|
-
Segment,
|
18
|
-
SegmentFormat,
|
19
|
-
SegmentProcessing,
|
20
|
-
SegmentType,
|
21
|
-
SegmentationStrategy,
|
22
|
-
Status,
|
23
|
-
Pipeline,
|
24
|
-
Tokenizer,
|
25
|
-
TokenizerType,
|
26
|
-
)
|
27
|
-
from .api.task_response import TaskResponse
|
28
|
-
|
29
|
-
__all__ = [
|
30
|
-
"BoundingBox",
|
31
|
-
"Chunk",
|
32
|
-
"ChunkProcessing",
|
33
|
-
"Configuration",
|
34
|
-
"CroppingStrategy",
|
35
|
-
"EmbedSource",
|
36
|
-
"ErrorHandlingStrategy",
|
37
|
-
"FallbackStrategy",
|
38
|
-
"GenerationConfig",
|
39
|
-
"GenerationStrategy",
|
40
|
-
"LlmProcessing",
|
41
|
-
"Model",
|
42
|
-
"OCRResult",
|
43
|
-
"OcrStrategy",
|
44
|
-
"OutputResponse",
|
45
|
-
"Segment",
|
46
|
-
"SegmentFormat",
|
47
|
-
"SegmentProcessing",
|
48
|
-
"SegmentType",
|
49
|
-
"SegmentationStrategy",
|
50
|
-
"Status",
|
51
|
-
"TaskResponse",
|
52
|
-
"Pipeline",
|
53
|
-
"Tokenizer",
|
54
|
-
"TokenizerType",
|
55
|
-
]
|
@@ -1,268 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: chunkr-ai
|
3
|
-
Version: 0.1.0
|
4
|
-
Summary: Python client for Chunkr: open source document intelligence
|
5
|
-
Author-email: Ishaan Kapoor <ishaan@lumina.sh>
|
6
|
-
License: MIT License
|
7
|
-
|
8
|
-
Copyright (c) 2025 Lumina AI INC
|
9
|
-
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
12
|
-
in the Software without restriction, including without limitation the rights
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
15
|
-
furnished to do so, subject to the following conditions:
|
16
|
-
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
18
|
-
copies or substantial portions of the Software.
|
19
|
-
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
-
SOFTWARE.
|
27
|
-
Project-URL: Homepage, https://chunkr.ai
|
28
|
-
Description-Content-Type: text/markdown
|
29
|
-
License-File: LICENSE
|
30
|
-
Requires-Dist: httpx>=0.25.0
|
31
|
-
Requires-Dist: nest-asyncio>=1.6.0
|
32
|
-
Requires-Dist: pillow>=10.0.0
|
33
|
-
Requires-Dist: pydantic>=2.0.0
|
34
|
-
Requires-Dist: python-dotenv>=0.19.0
|
35
|
-
Provides-Extra: test
|
36
|
-
Requires-Dist: pytest>=7.0.0; extra == "test"
|
37
|
-
Requires-Dist: pytest-xdist>=3.0.0; extra == "test"
|
38
|
-
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
39
|
-
Requires-Dist: ruff>=0.9.3; extra == "test"
|
40
|
-
Dynamic: license-file
|
41
|
-
|
42
|
-
# Chunkr Python Client
|
43
|
-
|
44
|
-
This provides a simple interface to interact with the Chunkr API.
|
45
|
-
|
46
|
-
## Getting Started
|
47
|
-
|
48
|
-
You can get an API key from [Chunkr](https://chunkr.ai) or deploy your own Chunkr instance. For self-hosted deployment options, check out our [deployment guide](https://github.com/lumina-ai-inc/chunkr/tree/main?tab=readme-ov-file#self-hosted-deployment-options).
|
49
|
-
|
50
|
-
For more information about the API and its capabilities, visit the [Chunkr API docs](https://docs.chunkr.ai).
|
51
|
-
|
52
|
-
## Installation
|
53
|
-
|
54
|
-
```bash
|
55
|
-
pip install chunkr-ai
|
56
|
-
```
|
57
|
-
|
58
|
-
## Usage
|
59
|
-
|
60
|
-
The `Chunkr` client works seamlessly in both synchronous and asynchronous contexts.
|
61
|
-
|
62
|
-
### Synchronous Usage
|
63
|
-
|
64
|
-
```python
|
65
|
-
from chunkr_ai import Chunkr
|
66
|
-
|
67
|
-
# Initialize client
|
68
|
-
chunkr = Chunkr()
|
69
|
-
|
70
|
-
# Upload a file and wait for processing
|
71
|
-
task = chunkr.upload("document.pdf")
|
72
|
-
print(task.task_id)
|
73
|
-
|
74
|
-
# Create task without waiting
|
75
|
-
task = chunkr.create_task("document.pdf")
|
76
|
-
result = task.poll() # Check status when needed
|
77
|
-
|
78
|
-
# Clean up when done
|
79
|
-
chunkr.close()
|
80
|
-
```
|
81
|
-
|
82
|
-
### Asynchronous Usage
|
83
|
-
|
84
|
-
```python
|
85
|
-
from chunkr_ai import Chunkr
|
86
|
-
import asyncio
|
87
|
-
|
88
|
-
async def process_document():
|
89
|
-
# Initialize client
|
90
|
-
chunkr = Chunkr()
|
91
|
-
|
92
|
-
try:
|
93
|
-
# Upload a file and wait for processing
|
94
|
-
task = await chunkr.upload("document.pdf")
|
95
|
-
print(task.task_id)
|
96
|
-
|
97
|
-
# Create task without waiting
|
98
|
-
task = await chunkr.create_task("document.pdf")
|
99
|
-
result = await task.poll() # Check status when needed
|
100
|
-
finally:
|
101
|
-
await chunkr.close()
|
102
|
-
|
103
|
-
# Run the async function
|
104
|
-
asyncio.run(process_document())
|
105
|
-
```
|
106
|
-
|
107
|
-
### Concurrent Processing
|
108
|
-
|
109
|
-
The client supports both async concurrency and multiprocessing:
|
110
|
-
|
111
|
-
```python
|
112
|
-
# Async concurrency
|
113
|
-
async def process_multiple():
|
114
|
-
chunkr = Chunkr()
|
115
|
-
try:
|
116
|
-
tasks = [
|
117
|
-
chunkr.upload("doc1.pdf"),
|
118
|
-
chunkr.upload("doc2.pdf"),
|
119
|
-
chunkr.upload("doc3.pdf")
|
120
|
-
]
|
121
|
-
results = await asyncio.gather(*tasks)
|
122
|
-
finally:
|
123
|
-
await chunkr.close()
|
124
|
-
|
125
|
-
# Multiprocessing
|
126
|
-
from multiprocessing import Pool
|
127
|
-
|
128
|
-
def process_file(path):
|
129
|
-
chunkr = Chunkr()
|
130
|
-
try:
|
131
|
-
return chunkr.upload(path)
|
132
|
-
finally:
|
133
|
-
chunkr.close()
|
134
|
-
|
135
|
-
with Pool(processes=3) as pool:
|
136
|
-
results = pool.map(process_file, ["doc1.pdf", "doc2.pdf", "doc3.pdf"])
|
137
|
-
```
|
138
|
-
|
139
|
-
### Input Types
|
140
|
-
|
141
|
-
The client supports various input types:
|
142
|
-
|
143
|
-
```python
|
144
|
-
# File path
|
145
|
-
chunkr.upload("document.pdf")
|
146
|
-
|
147
|
-
# Opened file
|
148
|
-
with open("document.pdf", "rb") as f:
|
149
|
-
chunkr.upload(f)
|
150
|
-
|
151
|
-
# PIL Image
|
152
|
-
from PIL import Image
|
153
|
-
img = Image.open("photo.jpg")
|
154
|
-
chunkr.upload(img)
|
155
|
-
```
|
156
|
-
|
157
|
-
### Configuration
|
158
|
-
|
159
|
-
You can customize the processing behavior by passing a `Configuration` object:
|
160
|
-
|
161
|
-
```python
|
162
|
-
from chunkr_ai.models import (
|
163
|
-
Configuration,
|
164
|
-
OcrStrategy,
|
165
|
-
SegmentationStrategy,
|
166
|
-
GenerationStrategy
|
167
|
-
)
|
168
|
-
|
169
|
-
config = Configuration(
|
170
|
-
ocr_strategy=OcrStrategy.AUTO,
|
171
|
-
segmentation_strategy=SegmentationStrategy.LAYOUT_ANALYSIS,
|
172
|
-
high_resolution=True,
|
173
|
-
expires_in=3600, # seconds
|
174
|
-
)
|
175
|
-
|
176
|
-
# Works in both sync and async contexts
|
177
|
-
task = chunkr.upload("document.pdf", config) # sync
|
178
|
-
task = await chunkr.upload("document.pdf", config) # async
|
179
|
-
```
|
180
|
-
|
181
|
-
#### Available Configuration Examples
|
182
|
-
|
183
|
-
- **Chunk Processing**
|
184
|
-
```python
|
185
|
-
from chunkr_ai.models import ChunkProcessing
|
186
|
-
config = Configuration(
|
187
|
-
chunk_processing=ChunkProcessing(target_length=1024)
|
188
|
-
)
|
189
|
-
```
|
190
|
-
- **Expires In**
|
191
|
-
```python
|
192
|
-
config = Configuration(expires_in=3600)
|
193
|
-
```
|
194
|
-
|
195
|
-
- **High Resolution**
|
196
|
-
```python
|
197
|
-
config = Configuration(high_resolution=True)
|
198
|
-
```
|
199
|
-
|
200
|
-
- **JSON Schema**
|
201
|
-
```python
|
202
|
-
config = Configuration(json_schema=JsonSchema(
|
203
|
-
title="Sales Data",
|
204
|
-
properties=[
|
205
|
-
Property(name="Person with highest sales", prop_type="string", description="The person with the highest sales"),
|
206
|
-
Property(name="Person with lowest sales", prop_type="string", description="The person with the lowest sales"),
|
207
|
-
]
|
208
|
-
))
|
209
|
-
```
|
210
|
-
|
211
|
-
- **OCR Strategy**
|
212
|
-
```python
|
213
|
-
config = Configuration(ocr_strategy=OcrStrategy.AUTO)
|
214
|
-
```
|
215
|
-
|
216
|
-
- **Segment Processing**
|
217
|
-
```python
|
218
|
-
from chunkr_ai.models import SegmentProcessing, GenerationConfig, GenerationStrategy
|
219
|
-
config = Configuration(
|
220
|
-
segment_processing=SegmentProcessing(
|
221
|
-
page=GenerationConfig(
|
222
|
-
html=GenerationStrategy.LLM,
|
223
|
-
markdown=GenerationStrategy.LLM
|
224
|
-
)
|
225
|
-
)
|
226
|
-
)
|
227
|
-
```
|
228
|
-
|
229
|
-
- **Segmentation Strategy**
|
230
|
-
```python
|
231
|
-
config = Configuration(
|
232
|
-
segmentation_strategy=SegmentationStrategy.LAYOUT_ANALYSIS # or SegmentationStrategy.PAGE
|
233
|
-
)
|
234
|
-
```
|
235
|
-
|
236
|
-
## Environment Setup
|
237
|
-
|
238
|
-
You can provide your API key and URL in several ways:
|
239
|
-
1. Environment variables: `CHUNKR_API_KEY` and `CHUNKR_URL`
|
240
|
-
2. `.env` file
|
241
|
-
3. Direct initialization:
|
242
|
-
```python
|
243
|
-
chunkr = Chunkr(
|
244
|
-
api_key="your-api-key",
|
245
|
-
url="https://api.chunkr.ai"
|
246
|
-
)
|
247
|
-
```
|
248
|
-
|
249
|
-
## Resource Management
|
250
|
-
|
251
|
-
It's recommended to properly close the client when you're done:
|
252
|
-
|
253
|
-
```python
|
254
|
-
# Sync context
|
255
|
-
chunkr = Chunkr()
|
256
|
-
try:
|
257
|
-
result = chunkr.upload("document.pdf")
|
258
|
-
finally:
|
259
|
-
chunkr.close()
|
260
|
-
|
261
|
-
# Async context
|
262
|
-
async def process():
|
263
|
-
chunkr = Chunkr()
|
264
|
-
try:
|
265
|
-
result = await chunkr.upload("document.pdf")
|
266
|
-
finally:
|
267
|
-
await chunkr.close()
|
268
|
-
```
|
chunkr_ai-0.1.0.dist-info/RECORD
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
chunkr_ai/__init__.py,sha256=6KpYv2lmD6S5z2kc9pqwuLP5VDHmOuu2qDZArUIhb1s,53
|
2
|
-
chunkr_ai/models.py,sha256=1q4l7fSXU7cVfx2ZUcmc5EZ4K0AeUhCbvY9yaBbXL8E,1046
|
3
|
-
chunkr_ai/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
chunkr_ai/api/auth.py,sha256=0RSNFPvHt4Nrg8qtP2xvA2KbR0J_KUe1B_tKynbq9Fc,436
|
5
|
-
chunkr_ai/api/chunkr.py,sha256=uSNYtB_mcs4-QRKsX7wZb8yv6ayXgRrJSDNZ-EbAyvc,3857
|
6
|
-
chunkr_ai/api/chunkr_base.py,sha256=8roSPoCADmaXM2r7zz2iHfZzIcY9NopOfa4j-dfk8RA,6310
|
7
|
-
chunkr_ai/api/configuration.py,sha256=MVAxKe8vTSUMy0AHOPWyJEOgmIL-rPTsAQ8Z83gGXew,10287
|
8
|
-
chunkr_ai/api/decorators.py,sha256=w1l_ZEkl99C-BO3qRTbi74sYwHDFspB1Bjt1Arv9lPc,4384
|
9
|
-
chunkr_ai/api/misc.py,sha256=AaGLxZlMzNgVPwErskDRKc2UVGkC0JwxLXU-enPwzA0,5354
|
10
|
-
chunkr_ai/api/protocol.py,sha256=LjPrYSq52m1afIlAo0yVGXlGZxPRh8J6g7S4PAit3Zo,388
|
11
|
-
chunkr_ai/api/task_response.py,sha256=VYa62E08VlZUyjn2YslnY4cohdK9e53HbEzsaYIXKXM,8028
|
12
|
-
chunkr_ai-0.1.0.dist-info/licenses/LICENSE,sha256=w3R12yNDyZpMiy2lxy_hvNbsldC75ww79sF0u11rkho,1069
|
13
|
-
chunkr_ai-0.1.0.dist-info/METADATA,sha256=nRApqY3sX17_8fqSwfgYUH7Sy4Ahg5ybpxU9ZTXvdH4,7052
|
14
|
-
chunkr_ai-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
15
|
-
chunkr_ai-0.1.0.dist-info/top_level.txt,sha256=0IZY7PZIiS8bw5r4NUQRUQ-ATi-L_3vLQVq3ZLouOW8,10
|
16
|
-
chunkr_ai-0.1.0.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2025 Lumina AI INC
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
@@ -1 +0,0 @@
|
|
1
|
-
chunkr_ai
|
File without changes
|