fix(deepseek): Tool Choice to required for Azure Deployment in case specific function dict is given (#34848)

This commit is contained in:
Mohammad Mohtashim
2026-02-20 22:50:25 +05:00
committed by GitHub
parent 0081deae96
commit 03826061be
2 changed files with 127 additions and 0 deletions

View File

@@ -194,6 +194,11 @@ class ChatDeepSeek(BaseChatOpenAI):
model_config = ConfigDict(populate_by_name=True)
@property
def _is_azure_endpoint(self) -> bool:
"""Check if the configured endpoint is an Azure deployment."""
return "azure.com" in (self.api_base or "").lower()
@property
def _llm_type(self) -> str:
"""Return type of chat model."""
@@ -276,6 +281,17 @@ class ChatDeepSeek(BaseChatOpenAI):
if isinstance(block, dict) and block.get("type") == "text"
]
message["content"] = "".join(text_parts) if text_parts else ""
# Azure-hosted DeepSeek does not support the dict/object form of
# tool_choice (e.g. {"type": "function", "function": {"name": "..."}}).
# It only accepts string values: "none", "auto", or "required".
# Convert the unsupported dict form to "required", which is the closest
# string equivalent — it forces the model to call a tool without
# constraining which one. In the common with_structured_output() case
# only a single tool is bound, so the behavior is effectively identical.
if self._is_azure_endpoint and isinstance(payload.get("tool_choice"), dict):
payload["tool_choice"] = "required"
return payload
def _create_chat_result(