Don't retry on gemini RECITATION error

This commit is contained in:
Paul Gauthier 2024-04-30 14:40:15 -07:00
parent d6783636c5
commit 7b14d77e9e

View file

@ -18,6 +18,12 @@ CACHE = None
litellm.suppress_debug_info = True litellm.suppress_debug_info = True
def giveup_on_recitiation(ex):
if not isinstance(ex, litellm.exceptions.BadRequestError):
return
return "RECITATION" in str(ex)
@backoff.on_exception( @backoff.on_exception(
backoff.expo, backoff.expo,
( (
@ -27,6 +33,7 @@ litellm.suppress_debug_info = True
httpx.ConnectError, httpx.ConnectError,
litellm.exceptions.BadRequestError, litellm.exceptions.BadRequestError,
), ),
giveup=giveup_on_recitiation,
max_tries=10, max_tries=10,
on_backoff=lambda details: print( on_backoff=lambda details: print(
f"{details.get('exception','Exception')}\nRetry in {details['wait']:.1f} seconds." f"{details.get('exception','Exception')}\nRetry in {details['wait']:.1f} seconds."
@ -50,6 +57,8 @@ def send_with_retries(model_name, messages, functions, stream):
if not stream and CACHE is not None and key in CACHE: if not stream and CACHE is not None and key in CACHE:
return hash_object, CACHE[key] return hash_object, CACHE[key]
# del kwargs['stream']
res = litellm.completion(**kwargs) res = litellm.completion(**kwargs)
if not stream and CACHE is not None: if not stream and CACHE is not None: