11"""Function retry utilities."""
22import logging
33import time
4- from typing import cast , Callable , Type , TypeVar
4+ from typing import Optional , cast , Callable , Type , TypeVar
55from typing_extensions import ParamSpec
66
77from hume .error .hume_client_exception import HumeClientException
@@ -24,6 +24,7 @@ def retry(
2424 max_delay : int = 300 ,
2525 backoff_factor : int = 2 ,
2626 error_type : Type [Exception ] = RetryIterError ,
27+ timeout_message : Optional [str ] = None ,
2728) -> Callable [[Callable [P , R ]], Callable [P , R ]]:
2829 """Retry decorator for exponential backoff retry.
2930
@@ -34,6 +35,8 @@ def retry(
3435 error_type (Type[Exception]): Class of exception to expect from decorated function when
3536 the function fails. Raise this exception type if the retry iteration has failed.
3637 Defaults to RetryIterError.
38+ timeout_message (Optional[str]): A message that will be used when raising a
39+ HumeClientException on timeout.
3740
3841 Returns:
3942 Callable[[Callable[P, R]], Callable[P, R]]: Function decorator.
@@ -67,7 +70,10 @@ def func_wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
6770
6871 retry_timeout = retry_kwargs ["timeout" ]
6972 if total_await_time >= retry_timeout :
70- raise HumeClientException (f"Request timed out after { retry_timeout } s" )
73+ message = timeout_message
74+ if timeout_message is None :
75+ message = f"Request timed out after { retry_timeout } s"
76+ raise HumeClientException (message )
7177
7278 time .sleep (delay )
7379 total_await_time += delay
0 commit comments