@@ -193,11 +193,59 @@ class OllamaRateLimitConfig(RateLimitConfig):
193193 )
194194
195195
196+ class TransformersRateLimitConfig (RateLimitConfig ):
197+ """HuggingFace Transformers-specific rate limit configuration.
198+
199+ Local inference with Transformers doesn't face API rate limits, but
200+ may encounter hardware-related failures (CUDA OOM, generation errors).
201+ This config uses minimal retries focused on recoverable errors.
202+ """
203+
204+ max_retries : int = Field (
205+ default = 2 ,
206+ ge = 0 ,
207+ le = 5 ,
208+ description = "Minimal retries for local model inference" ,
209+ )
210+ base_delay : float = Field (
211+ default = 1.0 ,
212+ ge = 0.1 ,
213+ le = 10.0 ,
214+ description = "Base delay for local inference retry" ,
215+ )
216+ max_delay : float = Field (
217+ default = 10.0 ,
218+ ge = 1.0 ,
219+ le = 60.0 ,
220+ description = "Max delay for local inference retry" ,
221+ )
222+ backoff_strategy : BackoffStrategy = Field (
223+ default = BackoffStrategy .LINEAR ,
224+ description = "Linear backoff for hardware issues" ,
225+ )
226+ jitter : bool = Field (
227+ default = False ,
228+ description = "No jitter needed for local inference" ,
229+ )
230+ respect_retry_after : bool = Field (
231+ default = False ,
232+ description = "No retry-after headers from local models" ,
233+ )
234+ retry_on_status_codes : set [int ] = Field (
235+ default_factory = set ,
236+ description = "No HTTP status codes for local inference" ,
237+ )
238+ retry_on_exceptions : list [str ] = Field (
239+ default_factory = lambda : ["cuda" , "out of memory" , "generation" ],
240+ description = "Exception keywords specific to local model inference" ,
241+ )
242+
243+
196244def get_default_rate_limit_config (provider : str ) -> RateLimitConfig :
197245 """Get the default rate limit configuration for a provider.
198246
199247 Args:
200- provider: Provider name (openai, anthropic, gemini, ollama)
248+ provider: Provider name (openai, anthropic, gemini, ollama, transformers )
201249
202250 Returns:
203251 Provider-specific rate limit configuration with sensible defaults
@@ -207,6 +255,7 @@ def get_default_rate_limit_config(provider: str) -> RateLimitConfig:
207255 "anthropic" : AnthropicRateLimitConfig (),
208256 "gemini" : GeminiRateLimitConfig (),
209257 "ollama" : OllamaRateLimitConfig (),
258+ "transformers" : TransformersRateLimitConfig (),
210259 }
211260 return configs .get (provider , RateLimitConfig ())
212261
@@ -218,7 +267,7 @@ def create_rate_limit_config(
218267 """Create a rate limit configuration from a dictionary.
219268
220269 Args:
221- provider: Provider name (openai, anthropic, gemini, ollama)
270+ provider: Provider name (openai, anthropic, gemini, ollama, transformers )
222271 config_dict: Configuration parameters as dictionary
223272
224273 Returns:
@@ -235,6 +284,7 @@ def create_rate_limit_config(
235284 "anthropic" : AnthropicRateLimitConfig ,
236285 "gemini" : GeminiRateLimitConfig ,
237286 "ollama" : OllamaRateLimitConfig ,
287+ "transformers" : TransformersRateLimitConfig ,
238288 }
239289
240290 config_class = config_classes .get (provider , RateLimitConfig )
0 commit comments