From 2771686124365899a35e8e43d0ca09fca167dabc Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 28 Feb 2024 17:32:01 -0800 Subject: [PATCH] (feat) helpers for supports_function_calling --- litellm/utils.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 94d1040b99..1106d2fec9 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3729,6 +3729,54 @@ def completion_cost( raise e +def supports_function_calling(model: str): + """ + Check if the given model supports function calling and return a boolean value. + + Parameters: + model (str): The model name to be checked. + + Returns: + bool: True if the model supports function calling, False otherwise. + + Raises: + Exception: If the given model is not found in model_prices_and_context_window.json. + """ + if model in litellm.model_cost: + model_info = litellm.model_cost[model] + if model_info.get("supports_function_calling", False): + return True + return False + else: + raise Exception( + f"Model not in model_prices_and_context_window.json. You passed model={model}." + ) + + +def supports_parallel_function_calling(model: str): + """ + Check if the given model supports parallel function calling and return True if it does, False otherwise. + + Parameters: + model (str): The model to check for support of parallel function calling. + + Returns: + bool: True if the model supports parallel function calling, False otherwise. + + Raises: + Exception: If the model is not found in the model_cost dictionary. + """ + if model in litellm.model_cost: + model_info = litellm.model_cost[model] + if model_info.get("supports_parallel_function_calling", False): + return True + return False + else: + raise Exception( + f"Model not in model_prices_and_context_window.json. You passed model={model}." + ) + + ####### HELPER FUNCTIONS ################ def register_model(model_cost: Union[str, dict]): """