fix(allowed_tools): read base_model to accept a custom-named OpenAI deployment on Azure AI

This commit is contained in:
mateo-berri 2026-10-28 17:32:19 -07:00
parent 2660d736d2
commit 22903b866f
4 changed files with 20 additions and 8 deletions

View file

@ -124,18 +124,23 @@ def is_allowed_tools_choice(tool_choice: object) -> bool:
return False
def _accepts_allowed_tools(custom_llm_provider: str, model: str) -> bool:
def _accepts_allowed_tools(custom_llm_provider: str, model: str, base_model: str | None) -> bool:
match custom_llm_provider:
case "azure_ai":
from litellm.llms.azure_ai.common_utils import azure_ai_serves_openai_chat_model
return azure_ai_serves_openai_chat_model(model)
return azure_ai_serves_openai_chat_model(model, base_model)
case _:
return custom_llm_provider in PROVIDERS_ACCEPTING_ALLOWED_TOOLS
def tool_choice_for_provider(
tool_choice: _ToolChoiceT, *, custom_llm_provider: str, model: str, drop_params: bool
tool_choice: _ToolChoiceT,
*,
custom_llm_provider: str,
model: str,
drop_params: bool,
base_model: str | None = None,
) -> _ToolChoiceT | Mapping[str, JsonValue] | None:
if not is_allowed_tools_choice(tool_choice):
return tool_choice
@ -149,7 +154,7 @@ def tool_choice_for_provider(
model=model,
llm_provider=custom_llm_provider,
) from exc
if _accepts_allowed_tools(custom_llm_provider, model):
if _accepts_allowed_tools(custom_llm_provider, model, base_model):
return dict(chat_allowed_tool_choice(allowed_tool_choice))
if drop_params:
return None

View file

@ -151,9 +151,11 @@ def azure_ai_supports_native_responses(model: str | None, api_base: str | None)
return AzureFoundryModelInfo.get_azure_ai_route(model) == "default"
def azure_ai_serves_openai_chat_model(model: str) -> bool:
def azure_ai_serves_openai_chat_model(model: str, base_model: str | None) -> bool:
served_model: Final = (base_model or model).rsplit("/", 1)[-1]
return (
AzureFoundryModelInfo.get_azure_ai_route(model) == "default" and model in litellm.open_ai_chat_completion_models
AzureFoundryModelInfo.get_azure_ai_route(model) == "default"
and served_model in litellm.open_ai_chat_completion_models
)

View file

@ -5711,7 +5711,7 @@ def completion(
),
)
routing_kwargs: Final = cast("Mapping[str, object]", kwargs) # cast-ok: kwargs is the untyped request dict
drops_unsupported_params: Final = (
drop_unsupported_reasoning: Final = (
litellm.drop_params is True or normalize_drop_params(routing_kwargs.get("drop_params")) is True
)
drops_tool_choice: Final = drop_policy(routing_kwargs).drops("tool_choice")
@ -5727,7 +5727,7 @@ def completion(
custom_llm_provider=custom_llm_provider,
deployment_model_info=routing_kwargs.get("model_info"),
model_group=reasoning_model_group,
drop_params=drops_unsupported_params,
drop_params=drop_unsupported_reasoning,
)
resolved_reasoning_effort: Final = chat_reasoning.effort.value
resolved_output_config: Final = chat_reasoning.output_config
@ -5867,6 +5867,7 @@ def completion(
custom_llm_provider=custom_llm_provider,
model=model,
drop_params=drops_tool_choice,
base_model=base_model if isinstance(base_model, str) else None,
),
"max_retries": max_retries,
"logprobs": logprobs,

View file

@ -5541,6 +5541,10 @@ def _mock_chat_completion(respx_mock: respx.MockRouter) -> respx.Route:
("openai/gpt-4.1-mini", {"api_base": "http://localhost:12346/v1"}),
("litellm_proxy/gpt-4.1-mini", {"api_base": "http://localhost:12346/v1"}),
("azure_ai/gpt-4.1-mini", {"api_base": "http://localhost:12346/models"}),
(
"azure_ai/my-luna-deployment",
{"api_base": "http://localhost:12346/models", "base_model": "azure_ai/gpt-4.1-mini"},
),
("azure/gpt-4.1-mini", {"api_base": "http://localhost:12346", "api_version": "2025-04-01-preview"}),
],
)