refac
Some checks failed
Python CI / Ruff Format (3.11) (push) Has been cancelled
Python CI / Ruff Format (3.12) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args: free_disk:false name:main suffix:]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args: free_disk:false name:main suffix:]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Has been cancelled
Frontend Build / Format & Build (push) Has been cancelled
Frontend Build / Unit Tests (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:cuda suffix:-cuda]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:cuda126 suffix:-cuda126]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:main suffix:]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:ollama suffix:-ollama]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:slim suffix:-slim]) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (, main) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda, cuda) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda126, cuda126) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-ollama, ollama) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-slim, slim) (push) Has been cancelled

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

View file

@ -1790,12 +1790,9 @@ async def chat_completion(
'stream_delta_chunk_size': stream_delta_chunk_size,
'reasoning_tags': reasoning_tags,
'function_calling': (
'native'
if (
form_data.get('params', {}).get('function_calling') == 'native'
or model_info_params.get('function_calling') == 'native'
)
else 'default'
form_data.get('params', {}).get('function_calling')
or model_info_params.get('function_calling')
or 'native'
),
},
}

View file

@ -2471,7 +2471,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
if 'files' in folder.data:
# Defensive: filter to entries the caller can still read.
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'] = [
*allowed_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'])
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(
{
'type': 'status',
@ -2563,17 +2563,17 @@ async def process_chat_payload(request, form_data, user, metadata, model):
if 'memory' in features and features['memory']:
# 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)
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
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)
if 'image_generation' in features and features['image_generation']:
# 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)
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 —
# 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 = (
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', 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
chat_id = metadata.get('chat_id')
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.
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
form_data['tools'] = [
{'type': 'function', 'function': tool.get('spec', {})} for tool in tools_dict.values()

View file

@ -150,7 +150,7 @@
<div>
<Tooltip
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"
className="inline-tooltip"
@ -162,12 +162,20 @@
<button
class="p-1 px-3 text-xs flex rounded-sm transition"
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"
>
{#if params.function_calling === 'native'}
<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}
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
{/if}