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
3a629ffe
"git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "e3d253b0403cd55950a37a95a24e1dee1a96bc94"
Commit
3a629ffe
authored
Jun 23, 2024
by
Timothy J. Baek
Browse files
feat: global filter
parent
d8c112d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
56 deletions
+65
-56
backend/main.py
backend/main.py
+63
-55
src/lib/components/workspace/Functions.svelte
src/lib/components/workspace/Functions.svelte
+2
-1
No files found.
backend/main.py
View file @
3a629ffe
...
@@ -376,70 +376,77 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
...
@@ -376,70 +376,77 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
)
)
model
=
app
.
state
.
MODELS
[
model_id
]
model
=
app
.
state
.
MODELS
[
model_id
]
filter_ids
=
[
function
.
id
for
function
in
Functions
.
get_functions_by_type
(
"filter"
,
active_only
=
True
)
]
# Check if the model has any filters
# 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"
]:
for
filter_id
in
model
[
"info"
][
"meta"
].
get
(
"filterIds"
,
[]):
filter_ids
.
extend
(
model
[
"info"
][
"meta"
].
get
(
"filterIds"
,
[]))
filter
=
Functions
.
get_function_by_id
(
filter_id
)
filter_ids
=
list
(
set
(
filter_ids
))
if
filter
:
if
filter_id
in
webui_app
.
state
.
FUNCTIONS
:
for
filter_id
in
filter_ids
:
function_module
=
webui_app
.
state
.
FUNCTIONS
[
filter_id
]
filter
=
Functions
.
get_function_by_id
(
filter_id
)
else
:
if
filter
:
function_module
,
function_type
=
load_function_module_by_id
(
if
filter_id
in
webui_app
.
state
.
FUNCTIONS
:
filter_id
function_module
=
webui_app
.
state
.
FUNCTIONS
[
filter_id
]
)
else
:
webui_app
.
state
.
FUNCTIONS
[
filter_id
]
=
function_module
function_module
,
function_type
=
load_function_module_by_id
(
filter_id
)
webui_app
.
state
.
FUNCTIONS
[
filter_id
]
=
function_module
# Check if the function has a file_handler variable
# Check if the function has a file_handler variable
if
hasattr
(
function_module
,
"file_handler"
):
if
hasattr
(
function_module
,
"file_handler"
):
skip_files
=
function_module
.
file_handler
skip_files
=
function_module
.
file_handler
try
:
try
:
if
hasattr
(
function_module
,
"inlet"
):
if
hasattr
(
function_module
,
"inlet"
):
inlet
=
function_module
.
inlet
inlet
=
function_module
.
inlet
# Get the signature of the function
# Get the signature of the function
sig
=
inspect
.
signature
(
inlet
)
sig
=
inspect
.
signature
(
inlet
)
params
=
{
"body"
:
data
}
params
=
{
"body"
:
data
}
if
"__user__"
in
sig
.
parameters
:
if
"__user__"
in
sig
.
parameters
:
__user__
=
{
__user__
=
{
"id"
:
user
.
id
,
"id"
:
user
.
id
,
"email"
:
user
.
email
,
"email"
:
user
.
email
,
"name"
:
user
.
name
,
"name"
:
user
.
name
,
"role"
:
user
.
role
,
"role"
:
user
.
role
,
}
}
try
:
try
:
if
hasattr
(
function_module
,
"UserValves"
):
if
hasattr
(
function_module
,
"UserValves"
):
__user__
[
"valves"
]
=
(
__user__
[
"valves"
]
=
function_module
.
UserValves
(
function_module
.
UserValves
(
**
Functions
.
get_user_valves_by_id_and_user_id
(
**
Functions
.
get_user_valves_by_id_and_user_id
(
filter_id
,
user
.
id
filter_id
,
user
.
id
)
)
)
)
except
Exception
as
e
:
)
print
(
e
)
except
Exception
as
e
:
print
(
e
)
params
=
{
**
params
,
"__user__"
:
__user__
}
params
=
{
**
params
,
"__user__"
:
__user__
}
if
"__id__"
in
sig
.
parameters
:
if
"__id__"
in
sig
.
parameters
:
params
=
{
params
=
{
**
params
,
**
params
,
"__id__"
:
filter_id
,
"__id__"
:
filter_id
,
}
}
if
inspect
.
iscoroutinefunction
(
inlet
):
if
inspect
.
iscoroutinefunction
(
inlet
):
data
=
await
inlet
(
**
params
)
data
=
await
inlet
(
**
params
)
else
:
else
:
data
=
inlet
(
**
params
)
data
=
inlet
(
**
params
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"Error:
{
e
}
"
)
print
(
f
"Error:
{
e
}
"
)
return
JSONResponse
(
return
JSONResponse
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
content
=
{
"detail"
:
str
(
e
)},
content
=
{
"detail"
:
str
(
e
)},
)
)
# Set the task model
# Set the task model
task_model_id
=
data
[
"model"
]
task_model_id
=
data
[
"model"
]
...
@@ -863,6 +870,7 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
...
@@ -863,6 +870,7 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
pipe
=
model
.
get
(
"pipe"
)
pipe
=
model
.
get
(
"pipe"
)
if
pipe
:
if
pipe
:
async
def
job
():
async
def
job
():
pipe_id
=
form_data
[
"model"
]
pipe_id
=
form_data
[
"model"
]
if
"."
in
pipe_id
:
if
"."
in
pipe_id
:
...
...
src/lib/components/workspace/Functions.svelte
View file @
3a629ffe
...
@@ -227,8 +227,9 @@
...
@@ -227,8 +227,9 @@
<div class=" self-center mx-1">
<div class=" self-center mx-1">
<Switch
<Switch
bind:state={func.is_active}
bind:state={func.is_active}
on:change={(e) => {
on:change={
async
(e) => {
toggleFunctionById(localStorage.token, func.id);
toggleFunctionById(localStorage.token, func.id);
models.set(await getModels(localStorage.token));
}}
}}
/>
/>
</div>
</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