mirror of
https://github.com/open-webui/open-webui
synced 2025-05-17 12:03:41 +00:00
feat: native tool calling frontend
This commit is contained in:
parent
533b62f062
commit
ec9be0d20d
@ -861,6 +861,7 @@ async def chat_completion(
|
|||||||
if model_id not in request.app.state.MODELS:
|
if model_id not in request.app.state.MODELS:
|
||||||
raise Exception("Model not found")
|
raise Exception("Model not found")
|
||||||
model = request.app.state.MODELS[model_id]
|
model = request.app.state.MODELS[model_id]
|
||||||
|
model_info = Models.get_model_by_id(model_id)
|
||||||
|
|
||||||
# Check if user has access to the model
|
# Check if user has access to the model
|
||||||
if not BYPASS_MODEL_ACCESS_CONTROL and user.role == "user":
|
if not BYPASS_MODEL_ACCESS_CONTROL and user.role == "user":
|
||||||
@ -878,6 +879,13 @@ async def chat_completion(
|
|||||||
"files": form_data.get("files", None),
|
"files": form_data.get("files", None),
|
||||||
"features": form_data.get("features", None),
|
"features": form_data.get("features", None),
|
||||||
"variables": form_data.get("variables", None),
|
"variables": form_data.get("variables", None),
|
||||||
|
"model": model_info,
|
||||||
|
**(
|
||||||
|
{"function_calling": "native"}
|
||||||
|
if form_data.get("params", {}).get("function_calling") == "native"
|
||||||
|
or model_info.params.model_dump().get("function_calling") == "native"
|
||||||
|
else {}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
form_data["metadata"] = metadata
|
form_data["metadata"] = metadata
|
||||||
|
|
||||||
|
@ -702,6 +702,7 @@ def apply_params_to_form_data(form_data, model):
|
|||||||
|
|
||||||
|
|
||||||
async def process_chat_payload(request, form_data, metadata, user, model):
|
async def process_chat_payload(request, form_data, metadata, user, model):
|
||||||
|
|
||||||
form_data = apply_params_to_form_data(form_data, model)
|
form_data = apply_params_to_form_data(form_data, model)
|
||||||
log.debug(f"form_data: {form_data}")
|
log.debug(f"form_data: {form_data}")
|
||||||
|
|
||||||
@ -808,13 +809,15 @@ async def process_chat_payload(request, form_data, metadata, user, model):
|
|||||||
}
|
}
|
||||||
form_data["metadata"] = metadata
|
form_data["metadata"] = metadata
|
||||||
|
|
||||||
try:
|
if not form_data["metadata"].get("function_calling") == "native":
|
||||||
form_data, flags = await chat_completion_tools_handler(
|
# If the function calling is not native, then call the tools function calling handler
|
||||||
request, form_data, user, models, extra_params
|
try:
|
||||||
)
|
form_data, flags = await chat_completion_tools_handler(
|
||||||
sources.extend(flags.get("sources", []))
|
request, form_data, user, models, extra_params
|
||||||
except Exception as e:
|
)
|
||||||
log.exception(e)
|
sources.extend(flags.get("sources", []))
|
||||||
|
except Exception as e:
|
||||||
|
log.exception(e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
form_data, flags = await chat_completion_files_handler(request, form_data, user)
|
form_data, flags = await chat_completion_files_handler(request, form_data, user)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
export let params = {
|
export let params = {
|
||||||
// Advanced
|
// Advanced
|
||||||
stream_response: null, // Set stream responses for this model individually
|
stream_response: null, // Set stream responses for this model individually
|
||||||
|
function_calling: null,
|
||||||
seed: null,
|
seed: null,
|
||||||
stop: null,
|
stop: null,
|
||||||
temperature: null,
|
temperature: null,
|
||||||
@ -81,6 +82,35 @@
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<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.'
|
||||||
|
)}
|
||||||
|
placement="top-start"
|
||||||
|
className="inline-tooltip"
|
||||||
|
>
|
||||||
|
<div class=" py-0.5 flex w-full justify-between">
|
||||||
|
<div class=" self-center text-xs font-medium">
|
||||||
|
{$i18n.t('Function Calling')}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
class="p-1 px-3 text-xs flex rounded transition"
|
||||||
|
on:click={() => {
|
||||||
|
params.function_calling = (params?.function_calling ?? null) === null ? 'native' : null;
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{#if params.function_calling === 'native'}
|
||||||
|
<span class="ml-2 self-center">{$i18n.t('Native')}</span>
|
||||||
|
{:else}
|
||||||
|
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class=" py-0.5 w-full justify-between">
|
<div class=" py-0.5 w-full justify-between">
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={$i18n.t(
|
content={$i18n.t(
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
let params = {
|
let params = {
|
||||||
// Advanced
|
// Advanced
|
||||||
stream_response: null,
|
stream_response: null,
|
||||||
|
function_calling: null,
|
||||||
seed: null,
|
seed: null,
|
||||||
temperature: null,
|
temperature: null,
|
||||||
frequency_penalty: null,
|
frequency_penalty: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user