mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
fix(deepseek): Tool Choice to required for Azure Deployment in case specific function dict is given (#34848)
This commit is contained in:
committed by
GitHub
parent
0081deae96
commit
03826061be
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user