UNPKG

@nomyx/assistant

Version:

A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)

25 lines (21 loc) 755 B
import { RetryStrategy } from '../types'; export class ExponentialBackoffRetryStrategy implements RetryStrategy { private maxRetries: number; private baseDelay: number; constructor(maxRetries: number = 3, baseDelay: number = 1000) { this.maxRetries = maxRetries; this.baseDelay = baseDelay; } shouldRetry(error: Error, attemptNumber: number): boolean { // Implement logic to determine if a retry should be attempted // For example, retry on network errors or rate limiting return attemptNumber < this.maxRetries; } getDelay(attemptNumber: number): number { // Implement exponential backoff return Math.min( this.baseDelay * Math.pow(2, attemptNumber), 30000 // Max delay of 30 seconds ); } }