Add support for fallback models

This commit is contained in:
Ori Kotek
2023-07-23 16:39:25 +03:00
parent 02a1d8dbfc
commit 1e97236a15

View File

@ -203,8 +203,10 @@ async def retry_with_fallback_models(f: Callable):
if not isinstance(fallback_models, list): if not isinstance(fallback_models, list):
fallback_models = [fallback_models] fallback_models = [fallback_models]
all_models = [model] + fallback_models all_models = [model] + fallback_models
for model in all_models: for i, model in enumerate(all_models):
try: try:
return await f(model) return await f(model)
except Exception as e: except Exception as e:
logging.warning(f"Failed to generate prediction with {model}: {e}") logging.warning(f"Failed to generate prediction with {model}: {e}")
if i == len(all_models) - 1: # If it's the last iteration
raise # Re-raise the last exception