[LLM Translation] Added model name formats (#12745)

* Added model supports

* invert logic

* Added gpt 35 turbo check

* add test check

* fix ruff check
This commit is contained in:
Jugal D. Bhatt 2025-07-19 05:38:35 +05:30 committed by GitHub
parent be60d12ff7
commit 8d35a00974
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 12 deletions

View File

@ -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

View File

@ -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")