refac
This commit is contained in:
1 parent
4210cae68e
commit
c205d3a353
1 file changed
+10
-8
@@ -2617,7 +2617,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
|||||||
|
|
||||||
# If the original caller provided tools, use them as-is (skip resolution).
|
# If the original caller provided tools, use them as-is (skip resolution).
|
||||||
# Otherwise, save any tools that filter inlets added for merging later.
|
# Otherwise, save any tools that filter inlets added for merging later.
|
||||||
inlet_filter_tools = None if payload_tools else form_data.get('tools', None)
|
inlet_filter_tools = None if payload_tools is not None else form_data.get('tools', None)
|
||||||
|
|
||||||
# Skills — extract IDs from message content (<$skillId|label> tags) so
|
# Skills — extract IDs from message content (<$skillId|label> tags) so
|
||||||
# persisted chats work without relying on the frontend to send skill_ids.
|
# persisted chats work without relying on the frontend to send skill_ids.
|
||||||
@@ -2704,10 +2704,10 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
|||||||
}
|
}
|
||||||
form_data['metadata'] = metadata
|
form_data['metadata'] = metadata
|
||||||
|
|
||||||
# When the caller provides an explicit OpenAI-style `tools` array in the
|
# When the caller provides an explicit `tools` key in the request body,
|
||||||
# request body, skip all server-side tool resolution and pass the caller's
|
# skip all server-side tool resolution and pass the caller's tools through
|
||||||
# tools through to the model unchanged.
|
# unchanged. Sending `tools: []` explicitly opts out of builtin injection.
|
||||||
if not payload_tools:
|
if payload_tools is None:
|
||||||
# Server side tools
|
# Server side tools
|
||||||
tool_ids = metadata.get('tool_ids', None)
|
tool_ids = metadata.get('tool_ids', None)
|
||||||
# Client side tools
|
# Client side tools
|
||||||
@@ -2838,12 +2838,14 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
|||||||
if mcp_clients:
|
if mcp_clients:
|
||||||
metadata['mcp_clients'] = mcp_clients
|
metadata['mcp_clients'] = mcp_clients
|
||||||
|
|
||||||
# Inject builtin tools for native function calling based on enabled features and model capability
|
# Inject builtin tools for native function calling based on enabled features and model capability.
|
||||||
# Check if builtin_tools capability is enabled for this model (defaults to True if not specified)
|
# Only inject when the request originates from the UI (identified by session_id).
|
||||||
|
# API callers don't expect hidden tools; they can explicitly request tools via tool_ids.
|
||||||
builtin_tools_enabled = (model.get('info', {}).get('meta', {}).get('capabilities') or {}).get(
|
builtin_tools_enabled = (model.get('info', {}).get('meta', {}).get('capabilities') or {}).get(
|
||||||
'builtin_tools', True
|
'builtin_tools', True
|
||||||
)
|
)
|
||||||
if metadata.get('params', {}).get('function_calling') != 'legacy' and builtin_tools_enabled:
|
has_session = bool(metadata.get('session_id'))
|
||||||
|
if has_session and metadata.get('params', {}).get('function_calling') != 'legacy' and builtin_tools_enabled:
|
||||||
# Add file context to user messages
|
# Add file context to user messages
|
||||||
chat_id = metadata.get('chat_id')
|
chat_id = metadata.get('chat_id')
|
||||||
form_data['messages'] = await add_file_context(form_data.get('messages', []), chat_id, user)
|
form_data['messages'] = await add_file_context(form_data.get('messages', []), chat_id, user)
|
||||||
|
|||||||
Reference in new issue
Block a user