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
ec36493d
Commit
ec36493d
authored
May 27, 2024
by
Timothy J. Baek
Browse files
feat: pipeline filter wildcard support
parent
966f10e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
backend/main.py
backend/main.py
+16
-12
No files found.
backend/main.py
View file @
ec36493d
...
@@ -249,21 +249,23 @@ class PipelineMiddleware(BaseHTTPMiddleware):
...
@@ -249,21 +249,23 @@ class PipelineMiddleware(BaseHTTPMiddleware):
data
=
json
.
loads
(
body_str
)
if
body_str
else
{}
data
=
json
.
loads
(
body_str
)
if
body_str
else
{}
model_id
=
data
[
"model"
]
model_id
=
data
[
"model"
]
valve
s
=
[
filter
s
=
[
model
model
for
model
in
app
.
state
.
MODELS
.
values
()
for
model
in
app
.
state
.
MODELS
.
values
()
if
"pipeline"
in
model
if
"pipeline"
in
model
and
model
[
"pipeline"
][
"type"
]
==
"filter"
and
model
[
"pipeline"
][
"type"
]
==
"filter"
and
model_id
and
(
in
[
model
[
"pipeline"
][
"pipelines"
]
==
[
"*"
]
target_model
[
"id"
]
or
any
(
for
target_model
in
model
[
"pipeline"
][
"pipelines"
]
model_id
==
target_model
[
"id"
]
]
for
target_model
in
model
[
"pipeline"
][
"pipelines"
]
)
)
]
]
sorted_
valve
s
=
sorted
(
valve
s
,
key
=
lambda
x
:
x
[
"pipeline"
][
"priority"
])
sorted_
filter
s
=
sorted
(
filter
s
,
key
=
lambda
x
:
x
[
"pipeline"
][
"priority"
])
user
=
None
user
=
None
if
len
(
sorted_
valve
s
)
>
0
:
if
len
(
sorted_
filter
s
)
>
0
:
try
:
try
:
user
=
get_current_user
(
user
=
get_current_user
(
get_http_authorization_cred
(
get_http_authorization_cred
(
...
@@ -274,10 +276,12 @@ class PipelineMiddleware(BaseHTTPMiddleware):
...
@@ -274,10 +276,12 @@ class PipelineMiddleware(BaseHTTPMiddleware):
except
:
except
:
pass
pass
for
valve
in
sorted_valves
:
print
(
sorted_filters
)
for
filter
in
sorted_filters
:
try
:
try
:
urlIdx
=
valve
[
"urlIdx"
]
urlIdx
=
filter
[
"urlIdx"
]
url
=
openai_app
.
state
.
config
.
OPENAI_API_BASE_URLS
[
urlIdx
]
url
=
openai_app
.
state
.
config
.
OPENAI_API_BASE_URLS
[
urlIdx
]
key
=
openai_app
.
state
.
config
.
OPENAI_API_KEYS
[
urlIdx
]
key
=
openai_app
.
state
.
config
.
OPENAI_API_KEYS
[
urlIdx
]
...
@@ -289,7 +293,7 @@ class PipelineMiddleware(BaseHTTPMiddleware):
...
@@ -289,7 +293,7 @@ class PipelineMiddleware(BaseHTTPMiddleware):
headers
=
headers
,
headers
=
headers
,
json
=
{
json
=
{
"user"
:
user
,
"user"
:
user
,
"model"
:
valve
[
"id"
],
"model"
:
filter
[
"id"
],
"body"
:
data
,
"body"
:
data
,
},
},
)
)
...
@@ -298,7 +302,7 @@ class PipelineMiddleware(BaseHTTPMiddleware):
...
@@ -298,7 +302,7 @@ class PipelineMiddleware(BaseHTTPMiddleware):
data
=
r
.
json
()
data
=
r
.
json
()
except
Exception
as
e
:
except
Exception
as
e
:
# Handle connection error here
# Handle connection error here
log
.
error
(
f
"Connection error:
{
e
}
"
)
print
(
f
"Connection error:
{
e
}
"
)
pass
pass
modified_body_bytes
=
json
.
dumps
(
data
).
encode
(
"utf-8"
)
modified_body_bytes
=
json
.
dumps
(
data
).
encode
(
"utf-8"
)
...
...
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