Skip to content

Commit

Permalink
updated max retries
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshsharma99 committed Feb 3, 2025
1 parent f5c7161 commit 8de431e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion clients/python-client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ build-backend = "setuptools.build_meta"

[project]
name = "chunkr-ai"
version = "0.0.32"
version = "0.0.34"
authors = [{"name" = "Ishaan Kapoor", "email" = "ishaan@lumina.sh"}]
description = "Python client for Chunkr: open source document intelligence"
readme = "README.md"
license = {"file" = "LICENSE"}
urls = {Homepage = "https://chunkr.ai"}
dependencies = [
"httpx>=0.25.0",
"nest-asyncio>=1.6.0",
"pillow>=10.0.0",
"pydantic>=2.0.0",
"python-dotenv>=0.19.0",
Expand Down
8 changes: 4 additions & 4 deletions clients/python-client/src/chunkr_ai/api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ async def wrapper(self: Any, *args: P.args, **kwargs: P.kwargs) -> T:
return wrapper
return decorator

def retry_on_429(max_retries: int = 25, initial_delay: float = 0.5) -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]:
def retry_on_429(max_retries: int = 3, initial_delay: float = 0.5) -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]:
"""Decorator that retries the request when encountering 429 Too Many Requests errors.
Args:
max_retries: Maximum number of retry attempts (default: 25)
max_retries: Maximum number of retry attempts (default: 3)
initial_delay: Initial delay in seconds, will be exponentially increased with jitter (default: 0.5)
"""
def decorator(async_func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
Expand All @@ -85,10 +85,10 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
return await async_func(*args, **kwargs)
except httpx.HTTPStatusError as e:
if e.response.status_code != 429:
raise
raise e
if retries >= max_retries:
print("Max retries reached")
raise
raise e
retries += 1
delay = initial_delay * (2 ** retries)
# Use Retry-After header if available
Expand Down

0 comments on commit 8de431e

Please sign in to comment.