refactor: Centralize retry timeout and use consistent value

This commit is contained in:
Paul Gauthier 2024-10-15 12:25:05 -07:00 committed by Paul Gauthier (aider)
parent 26058c89fe
commit 6bb9b2567f
2 changed files with 5 additions and 3 deletions

View file

@ -27,7 +27,7 @@ from aider.llm import litellm
from aider.repo import ANY_GIT_ERROR, GitRepo
from aider.repomap import RepoMap
from aider.run_cmd import run_cmd
from aider.sendchat import retry_exceptions, send_completion
from aider.sendchat import RETRY_TIMEOUT, retry_exceptions, send_completion
from aider.utils import format_content, format_messages, format_tokens, is_image_file
from ..dump import dump # noqa: F401
@ -1131,7 +1131,7 @@ class Coder:
except retry_exceptions() as err:
self.io.tool_warning(str(err))
retry_delay *= 2
if retry_delay > 60:
if retry_delay > RETRY_TIMEOUT:
break
self.io.tool_output(f"Retrying in {retry_delay:.1f} seconds...")
time.sleep(retry_delay)

View file

@ -13,6 +13,8 @@ CACHE_PATH = "~/.aider.send.cache.v1"
CACHE = None
# CACHE = Cache(CACHE_PATH)
RETRY_TIMEOUT = 60
def retry_exceptions():
import httpx
@ -36,7 +38,7 @@ def lazy_litellm_retry_decorator(func):
decorated_func = backoff.on_exception(
backoff.expo,
retry_exceptions(),
max_time=60,
max_time=RETRY_TIMEOUT,
on_backoff=lambda details: print(
f"{details.get('exception', 'Exception')}\nRetry in {details['wait']:.1f} seconds."
),