mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 11:02:37 +00:00
fix: update tool_choice logic for Azure-hosted models
Modified the tool_choice assignment in BaseChatOpenAI to set a default value based on the API base URL. If the base URL indicates an Azure-hosted model, the tool_choice is set to "required"; otherwise, it defaults to the tool name. This change enhances compatibility with Azure deployments.
This commit is contained in:
@@ -1870,11 +1870,22 @@ class BaseChatOpenAI(BaseChatModel):
|
|||||||
"schema must be specified when method is not 'json_mode'. "
|
"schema must be specified when method is not 'json_mode'. "
|
||||||
"Received None."
|
"Received None."
|
||||||
)
|
)
|
||||||
|
|
||||||
tool_name = convert_to_openai_tool(schema)["function"]["name"]
|
tool_name = convert_to_openai_tool(schema)["function"]["name"]
|
||||||
|
base_url = (
|
||||||
|
getattr(self, "openai_api_base", "") or getattr(self, "api_base", "") or ""
|
||||||
|
).lower()
|
||||||
|
# The Azure-Hosted Models routes to this function
|
||||||
|
# so we need to set the tool_choice to required
|
||||||
|
if "azure.com" in base_url:
|
||||||
|
tool_choice_default = "required"
|
||||||
|
else:
|
||||||
|
tool_choice_default = tool_name
|
||||||
|
|
||||||
bind_kwargs = self._filter_disabled_params(
|
bind_kwargs = self._filter_disabled_params(
|
||||||
**{
|
**{
|
||||||
**dict(
|
**dict(
|
||||||
tool_choice=tool_name,
|
tool_choice=tool_choice_default,
|
||||||
parallel_tool_calls=False,
|
parallel_tool_calls=False,
|
||||||
strict=strict,
|
strict=strict,
|
||||||
ls_structured_output_format={
|
ls_structured_output_format={
|
||||||
|
Reference in New Issue
Block a user