This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-05 16:58:16 -04:00
1 parent 1a97751e37
commit b1d40f3409
3 files changed
+21 -16

No files matched your search

+3 -6
View File
@@ -1790,12 +1790,9 @@ async def chat_completion(
'stream_delta_chunk_size': stream_delta_chunk_size, 'stream_delta_chunk_size': stream_delta_chunk_size,
'reasoning_tags': reasoning_tags, 'reasoning_tags': reasoning_tags,
'function_calling': ( 'function_calling': (
'native' form_data.get('params', {}).get('function_calling')
if ( or model_info_params.get('function_calling')
form_data.get('params', {}).get('function_calling') == 'native' or 'native'
or model_info_params.get('function_calling') == 'native'
)
else 'default'
), ),
}, },
} }
+8 -8
View File
@@ -2471,7 +2471,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
if 'files' in folder.data: if 'files' in folder.data:
# Defensive: filter to entries the caller can still read. # Defensive: filter to entries the caller can still read.
allowed_files = await get_accessible_folder_files(folder.data['files'], user) allowed_files = await get_accessible_folder_files(folder.data['files'], user)
if metadata.get('params', {}).get('function_calling') != 'native': if metadata.get('params', {}).get('function_calling') == 'legacy':
form_data['files'] = [ form_data['files'] = [
*allowed_files, *allowed_files,
*form_data.get('files', []), *form_data.get('files', []),
@@ -2485,7 +2485,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
user_message = get_last_user_message(form_data['messages']) user_message = get_last_user_message(form_data['messages'])
model_knowledge = model.get('info', {}).get('meta', {}).get('knowledge', False) model_knowledge = model.get('info', {}).get('meta', {}).get('knowledge', False)
if model_knowledge and metadata.get('params', {}).get('function_calling') != 'native': if model_knowledge and metadata.get('params', {}).get('function_calling') == 'legacy':
await event_emitter( await event_emitter(
{ {
'type': 'status', 'type': 'status',
@@ -2563,17 +2563,17 @@ async def process_chat_payload(request, form_data, user, metadata, model):
if 'memory' in features and features['memory']: if 'memory' in features and features['memory']:
# Skip forced memory injection when native FC is enabled - model can use memory tools # Skip forced memory injection when native FC is enabled - model can use memory tools
if metadata.get('params', {}).get('function_calling') != 'native': if metadata.get('params', {}).get('function_calling') == 'legacy':
form_data = await chat_memory_handler(request, form_data, extra_params, user) form_data = await chat_memory_handler(request, form_data, extra_params, user)
if 'web_search' in features and features['web_search']: if 'web_search' in features and features['web_search']:
# Skip forced RAG web search when native FC is enabled - model can use web_search tool # Skip forced RAG web search when native FC is enabled - model can use web_search tool
if metadata.get('params', {}).get('function_calling') != 'native': if metadata.get('params', {}).get('function_calling') == 'legacy':
form_data = await chat_web_search_handler(request, form_data, extra_params, user) form_data = await chat_web_search_handler(request, form_data, extra_params, user)
if 'image_generation' in features and features['image_generation']: if 'image_generation' in features and features['image_generation']:
# Skip forced image generation when native FC is enabled - model can use generate_image tool # Skip forced image generation when native FC is enabled - model can use generate_image tool
if metadata.get('params', {}).get('function_calling') != 'native': if metadata.get('params', {}).get('function_calling') == 'legacy':
form_data = await chat_image_generation_handler(request, form_data, extra_params, user) form_data = await chat_image_generation_handler(request, form_data, extra_params, user)
if 'code_interpreter' in features and features['code_interpreter']: if 'code_interpreter' in features and features['code_interpreter']:
@@ -2581,7 +2581,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
# Skip XML-tag prompt injection when native FC is enabled — # Skip XML-tag prompt injection when native FC is enabled —
# execute_code will be injected as a builtin tool instead # execute_code will be injected as a builtin tool instead
if metadata.get('params', {}).get('function_calling') != 'native': if metadata.get('params', {}).get('function_calling') == 'legacy':
prompt = ( prompt = (
request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE
if request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE != '' if request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE != ''
@@ -2843,7 +2843,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
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') == 'native' and builtin_tools_enabled: if 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)
@@ -2866,7 +2866,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
# (e.g. pipe functions) can access all tools including MCP and builtins. # (e.g. pipe functions) can access all tools including MCP and builtins.
metadata['tools'] = tools_dict metadata['tools'] = tools_dict
if metadata.get('params', {}).get('function_calling') == 'native': if metadata.get('params', {}).get('function_calling') != 'legacy':
# If the function calling is native, then call the tools function calling handler # If the function calling is native, then call the tools function calling handler
form_data['tools'] = [ form_data['tools'] = [
{'type': 'function', 'function': tool.get('spec', {})} for tool in tools_dict.values() {'type': 'function', 'function': tool.get('spec', {})} for tool in tools_dict.values()
@@ -150,7 +150,7 @@
<div> <div>
<Tooltip <Tooltip
content={$i18n.t( content={$i18n.t(
"Default mode works with a wider range of models by calling tools once before execution. Native mode leverages the model's built-in tool-calling capabilities, but requires the model to inherently support this feature." "Native mode (default) leverages the model's built-in tool-calling capabilities. Legacy mode works with a wider range of models by calling tools once before execution via prompt injection."
)} )}
placement="top-start" placement="top-start"
className="inline-tooltip" className="inline-tooltip"
@@ -162,12 +162,20 @@
<button <button
class="p-1 px-3 text-xs flex rounded-sm transition" class="p-1 px-3 text-xs flex rounded-sm transition"
on:click={() => { on:click={() => {
params.function_calling = (params?.function_calling ?? null) === null ? 'native' : null; if ((params?.function_calling ?? null) === null) {
params.function_calling = 'native';
} else if (params.function_calling === 'native') {
params.function_calling = 'legacy';
} else {
params.function_calling = null;
}
}} }}
type="button" type="button"
> >
{#if params.function_calling === 'native'} {#if params.function_calling === 'native'}
<span class="ml-2 self-center">{$i18n.t('Native')}</span> <span class="ml-2 self-center">{$i18n.t('Native')}</span>
{:else if params.function_calling === 'legacy'}
<span class="ml-2 self-center">{$i18n.t('Legacy')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{/if} {/if}