chunkr-ai 0.0.31__tar.gz → 0.0.33__tar.gz
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-0.0.31/src/chunkr_ai.egg-info → chunkr_ai-0.0.33}/PKG-INFO +1 -1
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/pyproject.toml +1 -1
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/decorators.py +12 -5
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33/src/chunkr_ai.egg-info}/PKG-INFO +1 -1
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/tests/test_chunkr.py +11 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/LICENSE +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/README.md +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/setup.cfg +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/__init__.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/__init__.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/auth.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/chunkr.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/chunkr_base.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/configuration.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/misc.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/protocol.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/api/task_response.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai/models.py +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai.egg-info/SOURCES.txt +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai.egg-info/dependency_links.txt +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai.egg-info/requires.txt +0 -0
- {chunkr_ai-0.0.31 → chunkr_ai-0.0.33}/src/chunkr_ai.egg-info/top_level.txt +0 -0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "chunkr-ai"
|
7
|
-
version = "0.0.
|
7
|
+
version = "0.0.33"
|
8
8
|
authors = [{"name" = "Ishaan Kapoor", "email" = "ishaan@lumina.sh"}]
|
9
9
|
description = "Python client for Chunkr: open source document intelligence"
|
10
10
|
readme = "README.md"
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import functools
|
2
1
|
import asyncio
|
2
|
+
import functools
|
3
3
|
import httpx
|
4
|
+
import nest_asyncio
|
4
5
|
from typing import Callable, Any, TypeVar, Awaitable, Union, overload
|
5
6
|
try:
|
6
7
|
from typing import ParamSpec
|
@@ -21,6 +22,12 @@ def anywhere():
|
|
21
22
|
@functools.wraps(async_func)
|
22
23
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Union[Awaitable[T], T]:
|
23
24
|
global _sync_loop
|
25
|
+
|
26
|
+
try:
|
27
|
+
nest_asyncio.apply()
|
28
|
+
except ImportError:
|
29
|
+
pass
|
30
|
+
|
24
31
|
try:
|
25
32
|
asyncio.get_running_loop()
|
26
33
|
return async_func(*args, **kwargs)
|
@@ -61,11 +68,11 @@ def require_task() -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitabl
|
|
61
68
|
return wrapper
|
62
69
|
return decorator
|
63
70
|
|
64
|
-
def retry_on_429(max_retries: int =
|
71
|
+
def retry_on_429(max_retries: int = 3, initial_delay: float = 0.5) -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]:
|
65
72
|
"""Decorator that retries the request when encountering 429 Too Many Requests errors.
|
66
73
|
|
67
74
|
Args:
|
68
|
-
max_retries: Maximum number of retry attempts (default:
|
75
|
+
max_retries: Maximum number of retry attempts (default: 3)
|
69
76
|
initial_delay: Initial delay in seconds, will be exponentially increased with jitter (default: 0.5)
|
70
77
|
"""
|
71
78
|
def decorator(async_func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
|
@@ -78,10 +85,10 @@ def retry_on_429(max_retries: int = 25, initial_delay: float = 0.5) -> Callable[
|
|
78
85
|
return await async_func(*args, **kwargs)
|
79
86
|
except httpx.HTTPStatusError as e:
|
80
87
|
if e.response.status_code != 429:
|
81
|
-
raise
|
88
|
+
raise e
|
82
89
|
if retries >= max_retries:
|
83
90
|
print("Max retries reached")
|
84
|
-
raise
|
91
|
+
raise e
|
85
92
|
retries += 1
|
86
93
|
delay = initial_delay * (2 ** retries)
|
87
94
|
# Use Retry-After header if available
|
@@ -24,6 +24,10 @@ def sample_path():
|
|
24
24
|
def sample_image():
|
25
25
|
return Image.open("tests/files/test.jpg")
|
26
26
|
|
27
|
+
@pytest.fixture
|
28
|
+
def sample_url():
|
29
|
+
return "https://chunkr-web.s3.us-east-1.amazonaws.com/landing_page/input/science.pdf"
|
30
|
+
|
27
31
|
@pytest.fixture
|
28
32
|
def client():
|
29
33
|
client = Chunkr()
|
@@ -36,6 +40,13 @@ async def test_send_file_path(client, sample_path):
|
|
36
40
|
assert response.status == "Succeeded"
|
37
41
|
assert response.output is not None
|
38
42
|
|
43
|
+
@pytest.mark.asyncio
|
44
|
+
async def test_send_file_url(client, sample_url):
|
45
|
+
response = await client.upload(sample_url)
|
46
|
+
assert response.task_id is not None
|
47
|
+
assert response.status == "Succeeded"
|
48
|
+
assert response.output is not None
|
49
|
+
|
39
50
|
@pytest.mark.asyncio
|
40
51
|
async def test_send_file_path_str(client, sample_path):
|
41
52
|
response = await client.upload(str(sample_path))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|