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
afd27052
Commit
afd27052
authored
Jun 20, 2024
by
Timothy J. Baek
Browse files
feat: filter func outlet
parent
3101ff14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
12 deletions
+45
-12
backend/main.py
backend/main.py
+42
-11
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+3
-1
No files found.
backend/main.py
View file @
afd27052
...
@@ -474,10 +474,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
...
@@ -474,10 +474,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
],
],
]
]
response
=
await
call_next
(
request
)
response
=
await
call_next
(
request
)
# If there are data_items to inject into the response
if
len
(
data_items
)
>
0
:
if
isinstance
(
response
,
StreamingResponse
):
if
isinstance
(
response
,
StreamingResponse
):
# If it's a streaming response, inject it as SSE event or NDJSON line
# If it's a streaming response, inject it as SSE event or NDJSON line
content_type
=
response
.
headers
.
get
(
"Content-Type"
)
content_type
=
response
.
headers
.
get
(
"Content-Type"
)
...
@@ -489,7 +486,11 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
...
@@ -489,7 +486,11 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
return
StreamingResponse
(
return
StreamingResponse
(
self
.
ollama_stream_wrapper
(
response
.
body_iterator
,
data_items
),
self
.
ollama_stream_wrapper
(
response
.
body_iterator
,
data_items
),
)
)
else
:
return
response
# If it's not a chat completion request, just pass it through
response
=
await
call_next
(
request
)
return
response
return
response
async
def
_receive
(
self
,
body
:
bytes
):
async
def
_receive
(
self
,
body
:
bytes
):
...
@@ -800,6 +801,12 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
...
@@ -800,6 +801,12 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
async
def
chat_completed
(
form_data
:
dict
,
user
=
Depends
(
get_verified_user
)):
async
def
chat_completed
(
form_data
:
dict
,
user
=
Depends
(
get_verified_user
)):
data
=
form_data
data
=
form_data
model_id
=
data
[
"model"
]
model_id
=
data
[
"model"
]
if
model_id
not
in
app
.
state
.
MODELS
:
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
detail
=
"Model not found"
,
)
model
=
app
.
state
.
MODELS
[
model_id
]
filters
=
[
filters
=
[
model
model
...
@@ -815,14 +822,10 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
...
@@ -815,14 +822,10 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
)
)
)
)
]
]
sorted_filters
=
sorted
(
filters
,
key
=
lambda
x
:
x
[
"pipeline"
][
"priority"
])
print
(
model_id
)
sorted_filters
=
sorted
(
filters
,
key
=
lambda
x
:
x
[
"pipeline"
][
"priority"
])
if
"pipeline"
in
model
:
if
model_id
in
app
.
state
.
MODELS
:
sorted_filters
=
[
model
]
+
sorted_filters
model
=
app
.
state
.
MODELS
[
model_id
]
if
"pipeline"
in
model
:
sorted_filters
=
[
model
]
+
sorted_filters
for
filter
in
sorted_filters
:
for
filter
in
sorted_filters
:
r
=
None
r
=
None
...
@@ -863,6 +866,34 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
...
@@ -863,6 +866,34 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
else
:
else
:
pass
pass
# Check if the model has any filters
for
filter_id
in
model
[
"info"
][
"meta"
].
get
(
"filterIds"
,
[]):
filter
=
Functions
.
get_function_by_id
(
filter_id
)
if
filter
:
if
filter_id
in
webui_app
.
state
.
FUNCTIONS
:
function_module
=
webui_app
.
state
.
FUNCTIONS
[
filter_id
]
else
:
function_module
,
function_type
=
load_function_module_by_id
(
filter_id
)
webui_app
.
state
.
FUNCTIONS
[
filter_id
]
=
function_module
try
:
if
hasattr
(
function_module
,
"outlet"
):
data
=
function_module
.
outlet
(
data
,
{
"id"
:
user
.
id
,
"email"
:
user
.
email
,
"name"
:
user
.
name
,
"role"
:
user
.
role
,
},
)
except
Exception
as
e
:
print
(
f
"Error:
{
e
}
"
)
return
JSONResponse
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
content
=
{
"detail"
:
str
(
e
)},
)
return
data
return
data
...
...
src/lib/components/chat/Chat.svelte
View file @
afd27052
...
@@ -278,7 +278,9 @@
...
@@ -278,7 +278,9 @@
})),
})),
chat_id: $chatId
chat_id: $chatId
}).catch((error) => {
}).catch((error) => {
console.error(error);
toast.error(error);
messages.at(-1).error = { content: error };
return null;
return null;
});
});
...
...
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