diff --git a/litellm/tests/test_get_model_info.py b/litellm/tests/test_get_model_info.py new file mode 100644 index 00000000000..ec6843df80b --- /dev/null +++ b/litellm/tests/test_get_model_info.py @@ -0,0 +1,25 @@ +# What is this? +## Unit testing for the 'get_model_info()' function +import os, sys, traceback + +sys.path.insert( + 0, os.path.abspath("../..") +) # Adds the parent directory to the system path +import litellm +from litellm import get_model_info + + +def test_get_model_info_simple_model_name(): + """ + tests if model name given, and model exists in model info - the object is returned + """ + model = "claude-3-opus-20240229" + litellm.get_model_info(model) + + +def test_get_model_info_custom_llm_with_model_name(): + """ + Tests if {custom_llm_provider}/{model_name} name given, and model exists in model info, the object is returned + """ + model = "anthropic/claude-3-opus-20240229" + litellm.get_model_info(model) diff --git a/litellm/utils.py b/litellm/utils.py index dd538c7d04c..2ae1467d076 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -6134,7 +6134,13 @@ def get_model_info(model: str): "mode": "chat", } else: - raise Exception() + """ + Check if model in model cost map + """ + if model in litellm.model_cost: + return litellm.model_cost[model] + else: + raise Exception() except: raise Exception( "This model isn't mapped yet. Add it here - https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json" @@ -10595,7 +10601,9 @@ def trim_messages( if max_tokens is None: # Check if model is valid if model in litellm.model_cost: - max_tokens_for_model = litellm.model_cost[model].get("max_input_tokens", litellm.model_cost[model]["max_tokens"]) + max_tokens_for_model = litellm.model_cost[model].get( + "max_input_tokens", litellm.model_cost[model]["max_tokens"] + ) max_tokens = int(max_tokens_for_model * trim_ratio) else: # if user did not specify max (input) tokens