From c2480db73dd1ab11a48fcaf3ee8fcd5f315073fa Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 26 Apr 2025 17:42:06 -0700 Subject: [PATCH] [Bug Fix] UI QA - Fix wildcard model test connection not working (#10347) * fix setFieldsValue for wildcard * fix async_completion_with_fallbacks * fix ahealth_check_wildcard_models --- litellm/litellm_core_utils/fallback_utils.py | 15 ++++++++++++--- litellm/main.py | 7 ++++++- .../components/add_model/litellm_model_name.tsx | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/litellm/litellm_core_utils/fallback_utils.py b/litellm/litellm_core_utils/fallback_utils.py index 90c55246e5..d5610d5fdd 100644 --- a/litellm/litellm_core_utils/fallback_utils.py +++ b/litellm/litellm_core_utils/fallback_utils.py @@ -1,5 +1,6 @@ import uuid from copy import deepcopy +from typing import Optional import litellm from litellm._logging import verbose_logger @@ -31,13 +32,16 @@ async def async_completion_with_fallbacks(**kwargs): kwargs.pop("acompletion", None) # Remove to prevent keyword conflicts litellm_call_id = str(uuid.uuid4()) base_kwargs = {**kwargs, **nested_kwargs, "litellm_call_id": litellm_call_id} + + # fields to remove base_kwargs.pop("model", None) # Remove model as it will be set per fallback + litellm_logging_obj = base_kwargs.pop("litellm_logging_obj", None) # Try each fallback model + most_recent_exception_str: Optional[str] = None for fallback in fallbacks: try: completion_kwargs = deepcopy(base_kwargs) - # Handle dictionary fallback configurations if isinstance(fallback, dict): model = fallback.pop("model", original_model) @@ -45,7 +49,11 @@ async def async_completion_with_fallbacks(**kwargs): else: model = fallback - response = await litellm.acompletion(**completion_kwargs, model=model) + response = await litellm.acompletion( + **completion_kwargs, + model=model, + litellm_logging_obj=litellm_logging_obj, + ) if response is not None: return response @@ -54,10 +62,11 @@ async def async_completion_with_fallbacks(**kwargs): verbose_logger.exception( f"Fallback attempt failed for model {model}: {str(e)}" ) + most_recent_exception_str = str(e) continue raise Exception( - "All fallback attempts failed. Enable verbose logging with `litellm.set_verbose=True` for details." + f"{most_recent_exception_str}. All fallback attempts failed. Enable verbose logging with `litellm.set_verbose=True` for details." ) diff --git a/litellm/main.py b/litellm/main.py index de0716fd96..c8a3ce55ac 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -5511,7 +5511,10 @@ def speech( # noqa: PLR0915 async def ahealth_check_wildcard_models( - model: str, custom_llm_provider: str, model_params: dict + model: str, + custom_llm_provider: str, + model_params: dict, + litellm_logging_obj: Logging, ) -> dict: # this is a wildcard model, we need to pick a random model from the provider cheapest_models = pick_cheapest_chat_models_from_llm_provider( @@ -5528,6 +5531,7 @@ async def ahealth_check_wildcard_models( else: fallback_models = None model_params["model"] = cheapest_models[0] + model_params["litellm_logging_obj"] = litellm_logging_obj model_params["fallbacks"] = fallback_models model_params["max_tokens"] = 1 await acompletion(**model_params) @@ -5594,6 +5598,7 @@ async def ahealth_check( model=model, custom_llm_provider=custom_llm_provider, model_params=model_params, + litellm_logging_obj=litellm_logging_obj, ) model_params["litellm_logging_obj"] = litellm_logging_obj diff --git a/ui/litellm-dashboard/src/components/add_model/litellm_model_name.tsx b/ui/litellm-dashboard/src/components/add_model/litellm_model_name.tsx index f5c92f8df5..278456317b 100644 --- a/ui/litellm-dashboard/src/components/add_model/litellm_model_name.tsx +++ b/ui/litellm-dashboard/src/components/add_model/litellm_model_name.tsx @@ -23,7 +23,7 @@ const LiteLLMModelNameField: React.FC = ({ // If "all-wildcard" is selected, clear the model_name field if (values.includes("all-wildcard")) { - form.setFieldsValue({ model: undefined, model_mappings: [] }); + form.setFieldsValue({ model_name: undefined, model_mappings: [] }); } else { // Get current model value to check if we need to update const currentModel = form.getFieldValue('model');