Skip to content

Commit

Permalink
modify exp backoff implementation (#1513)
Browse files Browse the repository at this point in the history
* Feature/tweak actions (#1507)

* up

* tweak actions

* modify exp backoff impl

---------

Co-authored-by: emrgnt-cmplxty <[email protected]>
  • Loading branch information
shreyaspimpalgaonkar and emrgnt-cmplxty authored Oct 28, 2024
1 parent 080d8cb commit f46d4bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions py/core/base/providers/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
VectorSearchResult,
default_embedding_prefixes,
)
import random
from .base import Provider, ProviderConfig

logger = logging.getLogger()
Expand Down Expand Up @@ -79,7 +80,7 @@ async def _execute_with_backoff_async(self, task: dict[str, Any]):
retries += 1
if retries == self.config.max_retries:
raise
await asyncio.sleep(backoff)
await asyncio.sleep(random.uniform(0, backoff))
backoff = min(backoff * 2, self.config.max_backoff)

def _execute_with_backoff_sync(self, task: dict[str, Any]):
Expand All @@ -97,7 +98,7 @@ def _execute_with_backoff_sync(self, task: dict[str, Any]):
retries += 1
if retries == self.config.max_retries:
raise
time.sleep(backoff)
time.sleep(random.uniform(0, backoff))
backoff = min(backoff * 2, self.config.max_backoff)

@abstractmethod
Expand Down
10 changes: 5 additions & 5 deletions py/core/base/providers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import abstractmethod
from concurrent.futures import ThreadPoolExecutor
from typing import Any, AsyncGenerator, Generator, Optional

import random
from litellm import AuthenticationError

from core.base.abstractions import (
Expand Down Expand Up @@ -67,7 +67,7 @@ async def _execute_with_backoff_async(self, task: dict[str, Any]):
retries += 1
if retries == self.config.max_retries:
raise
await asyncio.sleep(backoff)
await asyncio.sleep(random.uniform(0, backoff))
backoff = min(backoff * 2, self.config.max_backoff)

async def _execute_with_backoff_async_stream(
Expand All @@ -90,7 +90,7 @@ async def _execute_with_backoff_async_stream(
retries += 1
if retries == self.config.max_retries:
raise
await asyncio.sleep(backoff)
await asyncio.sleep(random.uniform(0, backoff))
backoff = min(backoff * 2, self.config.max_backoff)

def _execute_with_backoff_sync(self, task: dict[str, Any]):
Expand All @@ -106,7 +106,7 @@ def _execute_with_backoff_sync(self, task: dict[str, Any]):
retries += 1
if retries == self.config.max_retries:
raise
time.sleep(backoff)
time.sleep(random.uniform(0, backoff))
backoff = min(backoff * 2, self.config.max_backoff)

def _execute_with_backoff_sync_stream(
Expand All @@ -125,7 +125,7 @@ def _execute_with_backoff_sync_stream(
retries += 1
if retries == self.config.max_retries:
raise
time.sleep(backoff)
time.sleep(random.uniform(0, backoff))
backoff = min(backoff * 2, self.config.max_backoff)

@abstractmethod
Expand Down

0 comments on commit f46d4bf

Please sign in to comment.