From cb5456c9f5410068d59d3984eeeb1ce7ce0ac6f4 Mon Sep 17 00:00:00 2001 From: James Braza Date: Tue, 11 Jun 2024 14:41:57 -0700 Subject: [PATCH 1/3] Allowing inferring custom LLM provider from model inside get_supported_openai_params --- litellm/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 98461d58bd2..3ad7ea312ee 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -6226,7 +6226,7 @@ def get_first_chars_messages(kwargs: dict) -> str: def get_supported_openai_params( model: str, - custom_llm_provider: str, + custom_llm_provider: Optional[str] = None, request_type: Literal["chat_completion", "embeddings"] = "chat_completion", ) -> Optional[list]: """ @@ -6241,6 +6241,8 @@ def get_supported_openai_params( - List if custom_llm_provider is mapped - None if unmapped """ + if not custom_llm_provider: + custom_llm_provider = litellm.get_llm_provider(model=model)[1] if custom_llm_provider == "bedrock": return litellm.AmazonConverseConfig().get_supported_openai_params(model=model) elif custom_llm_provider == "ollama": From 8be37bee043af315d5567abb3f640d47e58cf347 Mon Sep 17 00:00:00 2001 From: James Braza Date: Tue, 11 Jun 2024 18:18:21 -0700 Subject: [PATCH 2/3] Added simple test of get_supported_openai_params with no custom provider --- litellm/tests/test_utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/tests/test_utils.py b/litellm/tests/test_utils.py index 8f99bd665c9..9f2e99a8055 100644 --- a/litellm/tests/test_utils.py +++ b/litellm/tests/test_utils.py @@ -23,6 +23,7 @@ from litellm.utils import ( create_pretrained_tokenizer, create_tokenizer, get_max_tokens, + get_supported_openai_params, ) # Assuming your trim_messages, shorten_message_to_fit_limit, and get_token_count functions are all in a module named 'message_utils' @@ -386,3 +387,7 @@ def test_get_max_token_unit_test(): ) # Returns a number instead of throwing an Exception assert isinstance(max_tokens, int) + + +def test_get_supported_openai_params() -> None: + assert isinstance(get_supported_openai_params("gpt-4"), list) From ef6e9201614aeddd1fa17d3f82f7bef8fc06f0d3 Mon Sep 17 00:00:00 2001 From: James Braza Date: Tue, 11 Jun 2024 18:34:10 -0700 Subject: [PATCH 3/3] Added handling of unmapped provider, with test --- litellm/tests/test_utils.py | 4 ++++ litellm/utils.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/tests/test_utils.py b/litellm/tests/test_utils.py index 9f2e99a8055..491283eeda8 100644 --- a/litellm/tests/test_utils.py +++ b/litellm/tests/test_utils.py @@ -390,4 +390,8 @@ def test_get_max_token_unit_test(): def test_get_supported_openai_params() -> None: + # Mapped provider assert isinstance(get_supported_openai_params("gpt-4"), list) + + # Unmapped provider + assert get_supported_openai_params("nonexistent") is None diff --git a/litellm/utils.py b/litellm/utils.py index 3ad7ea312ee..3595ca0bd1c 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -6242,7 +6242,10 @@ def get_supported_openai_params( - None if unmapped """ if not custom_llm_provider: - custom_llm_provider = litellm.get_llm_provider(model=model)[1] + try: + custom_llm_provider = litellm.get_llm_provider(model=model)[1] + except BadRequestError: + return None if custom_llm_provider == "bedrock": return litellm.AmazonConverseConfig().get_supported_openai_params(model=model) elif custom_llm_provider == "ollama":