mirror of
https://github.com/open-webui/open-webui.git
synced 2025-04-22 22:47:28 +02:00
refac
This commit is contained in:
parent
c262d9ad4f
commit
c8c85ba7fc
@ -416,15 +416,19 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
|
||||
)
|
||||
return 0
|
||||
|
||||
filter_ids = [
|
||||
function.id
|
||||
for function in Functions.get_functions_by_type(
|
||||
"filter", active_only=True
|
||||
)
|
||||
]
|
||||
# Check if the model has any filters
|
||||
filter_ids = []
|
||||
if "info" in model and "meta" in model["info"]:
|
||||
filter_ids.extend(model["info"]["meta"].get("filterIds", []))
|
||||
enabled_filter_ids = [
|
||||
function.id
|
||||
for function in Functions.get_functions_by_type(
|
||||
"filter", active_only=True
|
||||
)
|
||||
]
|
||||
filter_ids = [
|
||||
filter_id
|
||||
for filter_id in enabled_filter_ids
|
||||
if filter_id in model["info"]["meta"].get("filterIds", [])
|
||||
]
|
||||
filter_ids = list(set(filter_ids))
|
||||
|
||||
filter_ids.sort(key=get_priority)
|
||||
@ -1006,13 +1010,19 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
|
||||
return (function.valves if function.valves else {}).get("priority", 0)
|
||||
return 0
|
||||
|
||||
filter_ids = [
|
||||
function.id
|
||||
for function in Functions.get_functions_by_type("filter", active_only=True)
|
||||
]
|
||||
# Check if the model has any filters
|
||||
filter_ids = []
|
||||
if "info" in model and "meta" in model["info"]:
|
||||
filter_ids.extend(model["info"]["meta"].get("filterIds", []))
|
||||
enabled_filter_ids = [
|
||||
function.id
|
||||
for function in Functions.get_functions_by_type(
|
||||
"filter", active_only=True
|
||||
)
|
||||
]
|
||||
filter_ids = [
|
||||
filter_id
|
||||
for filter_id in enabled_filter_ids
|
||||
if filter_id in model["info"]["meta"].get("filterIds", [])
|
||||
]
|
||||
filter_ids = list(set(filter_ids))
|
||||
|
||||
# Sort filter_ids by priority, using the get_priority function
|
||||
|
@ -286,13 +286,15 @@
|
||||
</FunctionMenu>
|
||||
|
||||
<div class=" self-center mx-1">
|
||||
<Switch
|
||||
bind:state={func.is_active}
|
||||
on:change={async (e) => {
|
||||
toggleFunctionById(localStorage.token, func.id);
|
||||
models.set(await getModels(localStorage.token));
|
||||
}}
|
||||
/>
|
||||
<Tooltip content={func.is_active ? 'Enabled' : 'Disabled'}>
|
||||
<Switch
|
||||
bind:state={func.is_active}
|
||||
on:change={async (e) => {
|
||||
toggleFunctionById(localStorage.token, func.id);
|
||||
models.set(await getModels(localStorage.token));
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { goto } from '$app/navigation';
|
||||
import { settings, user, config, models, tools } from '$lib/stores';
|
||||
import { settings, user, config, models, tools, functions } from '$lib/stores';
|
||||
|
||||
import TurndownService from 'turndown';
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
|
||||
import { stringify } from 'postcss';
|
||||
import { parseFile } from '$lib/utils/characters';
|
||||
import FiltersSelector from '$lib/components/workspace/Models/FiltersSelector.svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
@ -61,6 +62,7 @@
|
||||
|
||||
let toolIds = [];
|
||||
let knowledge = [];
|
||||
let filterIds = [];
|
||||
|
||||
$: if (name) {
|
||||
id = name
|
||||
@ -105,6 +107,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (filterIds.length > 0) {
|
||||
info.meta.filterIds = filterIds;
|
||||
} else {
|
||||
if (info.meta.filterIds) {
|
||||
delete info.meta.filterIds;
|
||||
}
|
||||
}
|
||||
|
||||
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
|
||||
Object.keys(info.params).forEach((key) => {
|
||||
if (info.params[key] === '' || info.params[key] === null) {
|
||||
@ -173,6 +183,10 @@
|
||||
capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
|
||||
toolIds = model?.info?.meta?.toolIds ?? [];
|
||||
|
||||
if (model?.info?.meta?.filterIds) {
|
||||
filterIds = [...model?.info?.meta?.filterIds];
|
||||
}
|
||||
|
||||
info = {
|
||||
...info,
|
||||
...model.info
|
||||
@ -604,6 +618,13 @@
|
||||
<ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
|
||||
</div>
|
||||
|
||||
<div class="my-2">
|
||||
<FiltersSelector
|
||||
bind:selectedFilterIds={filterIds}
|
||||
filters={$functions.filter((func) => func.type === 'filter')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="my-1">
|
||||
<div class="flex w-full justify-between mb-1">
|
||||
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user