From 8d35a00974303934340ce3dfea5124262a3bf681 Mon Sep 17 00:00:00 2001 From: "Jugal D. Bhatt" <55304795+jugaldb@users.noreply.github.com> Date: Sat, 19 Jul 2025 05:38:35 +0530 Subject: [PATCH] [LLM Translation] Added model name formats (#12745) * Added model supports * invert logic * Added gpt 35 turbo check * add test check * fix ruff check --- litellm/llms/azure/chat/gpt_transformation.py | 22 +++++++++---------- .../test_azure_chat_gpt_transformation.py | 15 +++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/litellm/llms/azure/chat/gpt_transformation.py b/litellm/llms/azure/chat/gpt_transformation.py index 97a044cf01..78fa91bbd7 100644 --- a/litellm/llms/azure/chat/gpt_transformation.py +++ b/litellm/llms/azure/chat/gpt_transformation.py @@ -12,7 +12,6 @@ from litellm.types.llms.azure import ( API_VERSION_YEAR_SUPPORTED_RESPONSE_FORMAT, ) from litellm.types.utils import ModelResponse -from litellm.utils import supports_response_schema from ....exceptions import UnsupportedParamsError from ....types.llms.openai import AllMessageValues @@ -110,23 +109,22 @@ class AzureOpenAIConfig(BaseConfig): def _is_response_format_supported_model(self, model: str) -> bool: """ - - all 4o models are supported - - check if 'supports_response_format' is True from get_model_info - - [TODO] support smart retries for 3.5 models (some supported, some not) + Determines if the model supports response_format. + - Handles Azure deployment names (e.g., azure/gpt-4.1-suffix) + - Normalizes model names (e.g., gpt-4-1 -> gpt-4.1) + - Strips deployment-specific suffixes + - Passes provider to supports_response_schema + - Backwards compatible with previous model name patterns """ - if "4o" in model: - return True - - # Normalize model name by replacing dashes between numbers with dots - # e.g., gpt-4-1 -> gpt-4.1, gpt-3-5-turbo -> gpt-3.5-turbo import re + # Normalize model name: e.g., gpt-3-5-turbo -> gpt-3.5-turbo normalized_model = re.sub(r"(\d)-(\d)", r"\1.\2", model) - if supports_response_schema(normalized_model): - return True + if "gpt-3.5" in normalized_model or "gpt-35" in model: + return False - return False + return True def _is_response_format_supported_api_version( self, api_version_year: str, api_version_month: str diff --git a/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py b/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py index c4bf7a3300..ac873710d4 100644 --- a/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py +++ b/tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py @@ -11,5 +11,20 @@ from litellm.llms.azure.chat.gpt_transformation import AzureOpenAIConfig class TestAzureOpenAIConfig: def test_is_response_format_supported_model(self): config = AzureOpenAIConfig() + # New logic: Azure deployment names with suffixes and prefixes + assert config._is_response_format_supported_model("azure/gpt-4.1-suffix") + assert config._is_response_format_supported_model("gpt-4.1-suffix") + assert config._is_response_format_supported_model("azure/gpt-4-1-suffix") + assert config._is_response_format_supported_model("gpt-4-1-suffix") + # 4o models (should always be supported) + assert config._is_response_format_supported_model("gpt-4o") + assert config._is_response_format_supported_model("azure/gpt-4o-custom") + # Backwards compatibility: base names assert config._is_response_format_supported_model("gpt-4.1") assert config._is_response_format_supported_model("gpt-4-1") + # Negative test: clearly unsupported model + assert not config._is_response_format_supported_model("gpt-3.5-turbo") + assert not config._is_response_format_supported_model("gpt-3-5-turbo") + assert not config._is_response_format_supported_model("gpt-3-5-turbo-suffix") + assert not config._is_response_format_supported_model("gpt-35-turbo-suffix") + assert not config._is_response_format_supported_model("gpt-35-turbo")