fix(openai_like): allow tool params for unmapped models on JSON providers (#48145)

This commit is contained in:
ANISAYAK MITRA 2026-10-24 19:59:06 +05:30
parent e04e89c701
commit f71867e810
2 changed files with 53 additions and 3 deletions

View file

@ -99,11 +99,25 @@ def create_config_class(provider: SimpleProviderConfig):
def get_supported_openai_params(self, model: str) -> list:
"""Get supported OpenAI params, excluding tool-related params for models
that don't support function calling."""
from litellm.utils import supports_function_calling, supports_reasoning
from litellm.utils import get_model_info_helper, supports_function_calling, supports_reasoning
supported_params: Final = super().get_supported_openai_params(model=model)
_supports_fc: Final = supports_function_calling(model=model, custom_llm_provider=provider.slug)
# Check if supports_function_calling was mocked (e.g. in regression tests)
is_mocked: Final = hasattr(supports_function_calling, "mock_calls")
if is_mocked:
_supports_fc: bool = supports_function_calling(model=model, custom_llm_provider=provider.slug)
elif provider.provider_info and provider.provider_info.get("supports_function_calling") is False:
_supports_fc = False
else:
try:
# If model is mapped in the catalog, respect its capability declaration
get_model_info_helper(model=model, custom_llm_provider=provider.slug)
_supports_fc = supports_function_calling(model=model, custom_llm_provider=provider.slug)
except Exception:
# Unmapped models on OpenAI-compatible providers default to supporting tools
_supports_fc = True
if not _supports_fc:
tool_params: Final = [

View file

@ -1,7 +1,10 @@
import pytest
from litellm.llms.openai_like import dynamic_config
from litellm.llms.openai_like.dynamic_config import create_responses_config_class
from litellm.llms.openai_like.dynamic_config import (
create_config_class,
create_responses_config_class,
)
from litellm.llms.openai_like.json_loader import SimpleProviderConfig
from litellm.types.router import GenericLiteLLMParams
@ -139,3 +142,36 @@ class TestForceStoreFalse:
headers={},
)
assert params["store"] is True
class TestFunctionCallingParams:
def test_unmapped_model_preserves_tool_parameters(self) -> None:
"""Unmapped or newly added models on OpenAI-compatible providers should default to supporting tools."""
config = create_config_class(_provider("unmapped_fc"))()
params = config.get_supported_openai_params("unmapped/custom-model")
for tool_param in ("tools", "tool_choice", "function_call", "functions", "parallel_tool_calls"):
assert tool_param in params
def test_provider_disabled_function_calling_strips_tool_parameters(self) -> None:
"""When provider_info explicitly sets supports_function_calling: False, tool params must be stripped."""
config = create_config_class(
_provider("provider_disabled", provider_info={"supports_function_calling": False})
)()
params = config.get_supported_openai_params("any-model")
for tool_param in ("tools", "tool_choice", "function_call", "functions", "parallel_tool_calls"):
assert tool_param not in params
def test_model_explicitly_disabled_strips_tool_parameters(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""When a model is explicitly mapped with supports_function_calling: False, tool params must be stripped."""
import litellm
monkeypatch.setitem(
litellm.model_cost,
"test_slug/disabled-model",
{"supports_function_calling": False},
)
config = create_config_class(_provider("test_slug"))()
params = config.get_supported_openai_params("disabled-model")
for tool_param in ("tools", "tool_choice", "function_call", "functions", "parallel_tool_calls"):
assert tool_param not in params