MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / wrapper

Function wrapper

utils/llm_client.py:231–264  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

229
230 The actual delay is randomly chosen between retry_min_delay and retry_max_delay
231 (jitter strategy) to avoid thundering herd problem.
232 """
233 def decorator(func):
234 @wraps(func)
235 def wrapper(*args, **kwargs):
236 last_exception = None
237
238 for attempt in range(1, max_retries + 1):
239 try:
240 return func(*args, **kwargs)
241 except Exception as exc:
242 last_exception = exc
243 is_retryable, reason = _is_retryable_exception(exc)
244
245 if not is_retryable:
246 # Non-retryable exception, raise immediately
247 logger.error(f"API call failed (non-retryable): {type(exc).__name__}: {exc}")
248 raise
249
250 if attempt < max_retries:
251 # Calculate delay with jitter
252 delay = _get_retry_delay(retry_min_delay, retry_max_delay)
253 # Log and wait for retry
254 _log_retry_attempt(attempt, max_retries, delay, exc, reason)
255 time.sleep(delay)
256 else:
257 # Retry exhausted
258 logger.error(
259 f"API call retry exhausted ({max_retries} attempts): "
260 f"{type(exc).__name__}: {exc}"
261 )
262
263 # Raise retry exhausted exception
264 raise LLMRetryExhaustedError(
265 f"API call still failed after {max_retries} retries",
266 last_exception=last_exception,
267 attempts=max_retries,

Callers

nothing calls this directly

Calls 5

_is_retryable_exceptionFunction · 0.85
_get_retry_delayFunction · 0.85
_log_retry_attemptFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected