@@ -41,6 +41,9 @@ class LiteLLMSettings(OpenAILLMSettings, total=False):
4141 thinking : AnthropicThinkingParam | None
4242
4343
44+ LiteLLMModelName = str
45+
46+
4447@dataclass (frozen = True )
4548class LiteLLM (CloudLLM ):
4649 llm_settings : LiteLLMSettings | None = None
@@ -55,6 +58,10 @@ class LiteLLM(CloudLLM):
5558 allowed_openai_params : list [str ] | None = None
5659 # Mock LLM response for testing
5760 mock_response : str | None = None
61+ # Fallback models to use if the main model fails
62+ fallbacks : list [LiteLLMModelName ] = field (default_factory = list [LiteLLMModelName ])
63+ # Mock falling back to other models in the fallbacks list for testing
64+ mock_testing_fallbacks : bool = False
5865
5966 router : Router = field (init = False )
6067
@@ -71,6 +78,7 @@ def __post_init__(self) -> None:
7178 "additional_drop_params" : self .additional_drop_params ,
7279 "allowed_openai_params" : self .allowed_openai_params ,
7380 "mock_response" : self .mock_response ,
81+ "mock_testing_fallbacks" : self .mock_testing_fallbacks ,
7482 # "max_retries": self.max_client_retries,
7583 # "timeout": self.client_timeout,
7684 # "deployment_id": deployment_id,
@@ -114,13 +122,17 @@ def __post_init__(self) -> None:
114122 "Custom HTTP clients are not yet supported when using LiteLLM."
115123 )
116124
125+ main_litellm_model = {
126+ "model_name" : self .model_name ,
127+ "litellm_params" : {"model" : self .model_name },
128+ }
129+ fallback_litellm_models = [
130+ {"model_name" : fb , "litellm_params" : {"model" : fb }} for fb in self .fallbacks
131+ ]
132+
117133 _router = Router (
118- model_list = [
119- {
120- "model_name" : self .model_name ,
121- "litellm_params" : {"model" : self .model_name },
122- }
123- ],
134+ model_list = [main_litellm_model , * fallback_litellm_models ],
135+ fallbacks = [{self .model_name : self .fallbacks }],
124136 num_retries = self .max_client_retries ,
125137 timeout = self .client_timeout ,
126138 )
0 commit comments