-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Feature requestNew feature requestNew feature request
Description
Description
The Fallback model allows for requests to be sent to different model on the event of a request failure.
However, in the event the model is temporarily down (service outage or rate-limiting), pydantic-ai will continue to retry the failing model first on every request.
It would be nice if there were a built in way to "time out" a model (potentially using a circuit breaker pattern or just something simple):
def handle_fallback(e: Exception) -> bool:
fallback = isinstance(e, (ModelHTTPError, ThrottlingException))
return fallback
def curcuit_breaker(model, e: Exception):
if isinstance(e, ThrottlingException)
return {"state": "open", "expires": e.retry_after}
default_model = FallbackModel(
primary_model, fallback_model, fallback_on=handle_fallback, circuit_breaker=curcuit_breaker
)If a model state was set to "open" it would effectively be removed from the FallbackModel sequence until the expires.
A less opinioned interface might just be to allow for a enabled(model) -> boolean hook check before selecting the model. That would give the user flexibility to implement with whatever strategy they choose.
References
No response
Metadata
Metadata
Assignees
Labels
Feature requestNew feature requestNew feature request