Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
c8c85ba7
Commit
c8c85ba7
authored
Jun 27, 2024
by
Timothy J. Baek
Browse files
refac
parent
c262d9ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
22 deletions
+55
-22
backend/main.py
backend/main.py
+24
-14
src/lib/components/workspace/Functions.svelte
src/lib/components/workspace/Functions.svelte
+9
-7
src/routes/(app)/workspace/models/create/+page.svelte
src/routes/(app)/workspace/models/create/+page.svelte
+22
-1
No files found.
backend/main.py
View file @
c8c85ba7
...
@@ -416,15 +416,19 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
...
@@ -416,15 +416,19 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
)
)
return
0
return
0
filter_ids
=
[
filter_ids
=
[]
function
.
id
for
function
in
Functions
.
get_functions_by_type
(
"filter"
,
active_only
=
True
)
]
# Check if the model has any filters
if
"info"
in
model
and
"meta"
in
model
[
"info"
]:
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
=
list
(
set
(
filter_ids
))
filter_ids
.
sort
(
key
=
get_priority
)
filter_ids
.
sort
(
key
=
get_priority
)
...
@@ -1006,13 +1010,19 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
...
@@ -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
(
function
.
valves
if
function
.
valves
else
{}).
get
(
"priority"
,
0
)
return
0
return
0
filter_ids
=
[
filter_ids
=
[]
function
.
id
for
function
in
Functions
.
get_functions_by_type
(
"filter"
,
active_only
=
True
)
]
# Check if the model has any filters
if
"info"
in
model
and
"meta"
in
model
[
"info"
]:
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
=
list
(
set
(
filter_ids
))
# Sort filter_ids by priority, using the get_priority function
# Sort filter_ids by priority, using the get_priority function
...
...
src/lib/components/workspace/Functions.svelte
View file @
c8c85ba7
...
@@ -286,13 +286,15 @@
...
@@ -286,13 +286,15 @@
</FunctionMenu>
</FunctionMenu>
<div class=" self-center mx-1">
<div class=" self-center mx-1">
<Switch
<Tooltip content={func.is_active ? 'Enabled' : 'Disabled'}>
bind:state={func.is_active}
<Switch
on:change={async (e) => {
bind:state={func.is_active}
toggleFunctionById(localStorage.token, func.id);
on:change={async (e) => {
models.set(await getModels(localStorage.token));
toggleFunctionById(localStorage.token, func.id);
}}
models.set(await getModels(localStorage.token));
/>
}}
/>
</Tooltip>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
src/routes/(app)/workspace/models/create/+page.svelte
View file @
c8c85ba7
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation';
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';
import TurndownService from 'turndown';
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
import { stringify } from 'postcss';
import { stringify } from 'postcss';
import { parseFile } from '$lib/utils/characters';
import { parseFile } from '$lib/utils/characters';
import FiltersSelector from '$lib/components/workspace/Models/FiltersSelector.svelte';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -61,6 +62,7 @@
...
@@ -61,6 +62,7 @@
let toolIds = [];
let toolIds = [];
let knowledge = [];
let knowledge = [];
let filterIds = [];
$: if (name) {
$: if (name) {
id = name
id = name
...
@@ -105,6 +107,14 @@
...
@@ -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;
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
Object.keys(info.params).forEach((key) => {
Object.keys(info.params).forEach((key) => {
if (info.params[key] === '' || info.params[key] === null) {
if (info.params[key] === '' || info.params[key] === null) {
...
@@ -173,6 +183,10 @@
...
@@ -173,6 +183,10 @@
capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
toolIds = model?.info?.meta?.toolIds ?? [];
toolIds = model?.info?.meta?.toolIds ?? [];
if (model?.info?.meta?.filterIds) {
filterIds = [...model?.info?.meta?.filterIds];
}
info = {
info = {
...info,
...info,
...model.info
...model.info
...
@@ -604,6 +618,13 @@
...
@@ -604,6 +618,13 @@
<ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
<ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
</div>
</div>
<div class="my-2">
<FiltersSelector
bind:selectedFilterIds={filterIds}
filters={$functions.filter((func) => func.type === 'filter')}
/>
</div>
<div class="my-1">
<div class="my-1">
<div class="flex w-full justify-between mb-1">
<div class="flex w-full justify-between mb-1">
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment