From bb1489eced60c7982c79c3afdf49109f6bbd8abb Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sun, 12 Jan 2025 16:21:23 -0800 Subject: [PATCH] fix optimize get llm provider --- litellm/cost_calculator.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index ecddcc0eef..14b1f036c1 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -629,17 +629,17 @@ def completion_cost( # noqa: PLR0915 raise ValueError( f"Model is None and does not exist in passed completion_response. Passed completion_response={completion_response}, model={model}" ) - - try: - model, custom_llm_provider, _, _ = litellm.get_llm_provider( - model=model - ) # strip the llm provider from the model name -> for image gen cost calculation - except Exception as e: - verbose_logger.debug( - "litellm.cost_calculator.py::completion_cost() - Error inferring custom_llm_provider - {}".format( - str(e) + if custom_llm_provider is None: + try: + model, custom_llm_provider, _, _ = litellm.get_llm_provider( + model=model + ) # strip the llm provider from the model name -> for image gen cost calculation + except Exception as e: + verbose_logger.debug( + "litellm.cost_calculator.py::completion_cost() - Error inferring custom_llm_provider - {}".format( + str(e) + ) ) - ) if ( call_type == CallTypes.image_generation.value or call_type == CallTypes.aimage_generation.value