chunkr-ai 0.0.47__py3-none-any.whl → 0.0.48__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/api/chunkr.py +2 -2
- chunkr_ai/api/misc.py +49 -17
- {chunkr_ai-0.0.47.dist-info → chunkr_ai-0.0.48.dist-info}/METADATA +1 -1
- {chunkr_ai-0.0.47.dist-info → chunkr_ai-0.0.48.dist-info}/RECORD +7 -7
- {chunkr_ai-0.0.47.dist-info → chunkr_ai-0.0.48.dist-info}/WHEEL +1 -1
- {chunkr_ai-0.0.47.dist-info → chunkr_ai-0.0.48.dist-info}/licenses/LICENSE +0 -0
- {chunkr_ai-0.0.47.dist-info → chunkr_ai-0.0.48.dist-info}/top_level.txt +0 -0
chunkr_ai/api/chunkr.py
CHANGED
@@ -16,7 +16,7 @@ class Chunkr(ChunkrBase):
|
|
16
16
|
@ensure_client()
|
17
17
|
async def upload(
|
18
18
|
self,
|
19
|
-
file: Union[str, Path, BinaryIO, Image.Image],
|
19
|
+
file: Union[str, Path, BinaryIO, Image.Image, bytes, bytearray, memoryview],
|
20
20
|
config: Optional[Configuration] = None,
|
21
21
|
filename: Optional[str] = None,
|
22
22
|
) -> TaskResponse:
|
@@ -34,7 +34,7 @@ class Chunkr(ChunkrBase):
|
|
34
34
|
@retry_on_429()
|
35
35
|
async def create_task(
|
36
36
|
self,
|
37
|
-
file: Union[str, Path, BinaryIO, Image.Image],
|
37
|
+
file: Union[str, Path, BinaryIO, Image.Image, bytes, bytearray, memoryview],
|
38
38
|
config: Optional[Configuration] = None,
|
39
39
|
filename: Optional[str] = None,
|
40
40
|
) -> TaskResponse:
|
chunkr_ai/api/misc.py
CHANGED
@@ -3,9 +3,9 @@ import base64
|
|
3
3
|
import io
|
4
4
|
from pathlib import Path
|
5
5
|
from PIL import Image
|
6
|
-
from typing import Union, Tuple, BinaryIO, Optional
|
6
|
+
from typing import Union, Tuple, BinaryIO, Optional, Any
|
7
7
|
|
8
|
-
async def prepare_file(file: Union[str, Path, BinaryIO, Image.Image]) -> Tuple[Optional[str], str]:
|
8
|
+
async def prepare_file(file: Union[str, Path, BinaryIO, Image.Image, bytes, bytearray, memoryview]) -> Tuple[Optional[str], str]:
|
9
9
|
"""Convert various file types into a tuple of (filename, file content).
|
10
10
|
|
11
11
|
Args:
|
@@ -15,6 +15,7 @@ async def prepare_file(file: Union[str, Path, BinaryIO, Image.Image]) -> Tuple[O
|
|
15
15
|
- Local file path (will be converted to base64)
|
16
16
|
- Opened binary file (will be converted to base64)
|
17
17
|
- PIL/Pillow Image object (will be converted to base64)
|
18
|
+
- Bytes object (will be converted to base64)
|
18
19
|
|
19
20
|
Returns:
|
20
21
|
Tuple[Optional[str], str]: (filename, content) where content is either a URL or base64 string
|
@@ -26,22 +27,54 @@ async def prepare_file(file: Union[str, Path, BinaryIO, Image.Image]) -> Tuple[O
|
|
26
27
|
ValueError: If the URL is invalid or unreachable
|
27
28
|
ValueError: If the MIME type is unsupported
|
28
29
|
"""
|
29
|
-
# Handle
|
30
|
+
# Handle bytes-like objects
|
31
|
+
if isinstance(file, (bytes, bytearray, memoryview)):
|
32
|
+
# Convert to bytes first if it's not already
|
33
|
+
file_bytes = bytes(file)
|
34
|
+
|
35
|
+
# Check if this might be an already-encoded base64 string in bytes form
|
36
|
+
try:
|
37
|
+
# Try to decode the bytes to a string and see if it's valid base64
|
38
|
+
potential_base64 = file_bytes.decode('utf-8', errors='strict')
|
39
|
+
base64.b64decode(potential_base64)
|
40
|
+
# If we get here, it was a valid base64 string in bytes form
|
41
|
+
return None, potential_base64
|
42
|
+
except:
|
43
|
+
# Not a base64 string in bytes form, encode it as base64
|
44
|
+
base64_str = base64.b64encode(file_bytes).decode()
|
45
|
+
return None, base64_str
|
46
|
+
|
47
|
+
# Handle strings - urls or paths or base64
|
30
48
|
if isinstance(file, str):
|
49
|
+
# Handle URLs
|
31
50
|
if file.startswith(('http://', 'https://')):
|
32
51
|
return None, file
|
33
|
-
|
34
|
-
|
35
|
-
if
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
52
|
+
|
53
|
+
# Handle data URLs
|
54
|
+
if file.startswith('data:'):
|
55
|
+
return None, file
|
56
|
+
|
57
|
+
# Try to handle as a file path
|
58
|
+
try:
|
59
|
+
path = Path(file)
|
60
|
+
if path.exists():
|
61
|
+
# It's a valid file path, convert to Path object and continue processing
|
62
|
+
file = path
|
63
|
+
else:
|
64
|
+
# If not a valid file path, try treating as base64
|
65
|
+
try:
|
66
|
+
# Just test if it's valid base64, don't store the result
|
67
|
+
base64.b64decode(file)
|
68
|
+
return None, file
|
69
|
+
except:
|
70
|
+
raise ValueError(f"File not found: {file} and it's not a valid base64 string")
|
71
|
+
except Exception as e:
|
72
|
+
# If string can't be converted to Path or decoded as base64, it might still be a base64 string
|
40
73
|
try:
|
41
74
|
base64.b64decode(file)
|
42
75
|
return None, file
|
43
76
|
except:
|
44
|
-
raise ValueError(f"
|
77
|
+
raise ValueError(f"Unable to process file: {e}")
|
45
78
|
|
46
79
|
# Handle file paths - convert to base64
|
47
80
|
if isinstance(file, Path):
|
@@ -71,17 +104,16 @@ async def prepare_file(file: Union[str, Path, BinaryIO, Image.Image]) -> Tuple[O
|
|
71
104
|
file.seek(0)
|
72
105
|
file_content = file.read()
|
73
106
|
name = getattr(file, "name", "document")
|
74
|
-
|
75
|
-
|
76
|
-
raise ValueError("File must have an extension")
|
107
|
+
if not name or not isinstance(name, str):
|
108
|
+
name = None
|
77
109
|
base64_str = base64.b64encode(file_content).decode()
|
78
|
-
return
|
110
|
+
return name, base64_str
|
79
111
|
|
80
112
|
raise TypeError(f"Unsupported file type: {type(file)}")
|
81
113
|
|
82
114
|
|
83
115
|
async def prepare_upload_data(
|
84
|
-
file: Optional[Union[str, Path, BinaryIO, Image.Image]] = None,
|
116
|
+
file: Optional[Union[str, Path, BinaryIO, Image.Image, bytes, bytearray, memoryview]] = None,
|
85
117
|
filename: Optional[str] = None,
|
86
118
|
config: Optional[Configuration] = None,
|
87
119
|
) -> dict:
|
@@ -89,8 +121,8 @@ async def prepare_upload_data(
|
|
89
121
|
|
90
122
|
Args:
|
91
123
|
file: The file to upload
|
124
|
+
filename: Optional filename to use (overrides any filename from the file)
|
92
125
|
config: Optional configuration settings
|
93
|
-
client: HTTP client for downloading remote files
|
94
126
|
|
95
127
|
Returns:
|
96
128
|
dict: JSON-serializable data dictionary ready for upload
|
@@ -2,15 +2,15 @@ chunkr_ai/__init__.py,sha256=6KpYv2lmD6S5z2kc9pqwuLP5VDHmOuu2qDZArUIhb1s,53
|
|
2
2
|
chunkr_ai/models.py,sha256=L0L9CjY8SgSh9_Fzvo_nJXqKf_2urZHngMWtBVlAQAo,1006
|
3
3
|
chunkr_ai/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
chunkr_ai/api/auth.py,sha256=0RSNFPvHt4Nrg8qtP2xvA2KbR0J_KUe1B_tKynbq9Fc,436
|
5
|
-
chunkr_ai/api/chunkr.py,sha256=
|
5
|
+
chunkr_ai/api/chunkr.py,sha256=uSNYtB_mcs4-QRKsX7wZb8yv6ayXgRrJSDNZ-EbAyvc,3857
|
6
6
|
chunkr_ai/api/chunkr_base.py,sha256=8roSPoCADmaXM2r7zz2iHfZzIcY9NopOfa4j-dfk8RA,6310
|
7
7
|
chunkr_ai/api/configuration.py,sha256=aCYi_NjuTDynDc6g_N94jVGTb8SQQaUQ4LM8_a5v29g,9882
|
8
8
|
chunkr_ai/api/decorators.py,sha256=w1l_ZEkl99C-BO3qRTbi74sYwHDFspB1Bjt1Arv9lPc,4384
|
9
|
-
chunkr_ai/api/misc.py,sha256=
|
9
|
+
chunkr_ai/api/misc.py,sha256=AaGLxZlMzNgVPwErskDRKc2UVGkC0JwxLXU-enPwzA0,5354
|
10
10
|
chunkr_ai/api/protocol.py,sha256=LjPrYSq52m1afIlAo0yVGXlGZxPRh8J6g7S4PAit3Zo,388
|
11
11
|
chunkr_ai/api/task_response.py,sha256=VYa62E08VlZUyjn2YslnY4cohdK9e53HbEzsaYIXKXM,8028
|
12
|
-
chunkr_ai-0.0.
|
13
|
-
chunkr_ai-0.0.
|
14
|
-
chunkr_ai-0.0.
|
15
|
-
chunkr_ai-0.0.
|
16
|
-
chunkr_ai-0.0.
|
12
|
+
chunkr_ai-0.0.48.dist-info/licenses/LICENSE,sha256=w3R12yNDyZpMiy2lxy_hvNbsldC75ww79sF0u11rkho,1069
|
13
|
+
chunkr_ai-0.0.48.dist-info/METADATA,sha256=s63jhAgp5pet4y06Ntq3zMsSkEJPIj4-JmW0aCRSN7w,7053
|
14
|
+
chunkr_ai-0.0.48.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
15
|
+
chunkr_ai-0.0.48.dist-info/top_level.txt,sha256=0IZY7PZIiS8bw5r4NUQRUQ-ATi-L_3vLQVq3ZLouOW8,10
|
16
|
+
chunkr_ai-0.0.48.dist-info/RECORD,,
|
File without changes
|
File without changes
|