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
cf6447eb
Commit
cf6447eb
authored
Jun 22, 2024
by
Timothy J. Baek
Browse files
feat: function exception handler
parent
9205b90a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
backend/main.py
backend/main.py
+19
-4
No files found.
backend/main.py
View file @
cf6447eb
...
...
@@ -913,10 +913,15 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
if
form_data
[
"stream"
]:
async
def
stream_content
():
try
:
if
inspect
.
iscoroutinefunction
(
pipe
):
res
=
await
pipe
(
**
param
)
else
:
res
=
pipe
(
**
param
)
except
Exception
as
e
:
print
(
f
"Error:
{
e
}
"
)
yield
f
"data:
{
json
.
dumps
(
{
'error'
:
{
'detail'
:
str
(
e
)
}}
)
}
\n\n
"
return
if
isinstance
(
res
,
str
):
message
=
stream_message_template
(
form_data
[
"model"
],
res
)
...
...
@@ -961,6 +966,16 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
stream_content
(),
media_type
=
"text/event-stream"
)
else
:
try
:
if
inspect
.
iscoroutinefunction
(
pipe
):
res
=
await
pipe
(
**
param
)
else
:
res
=
pipe
(
**
param
)
except
Exception
as
e
:
print
(
f
"Error:
{
e
}
"
)
return
{
"error"
:
{
"detail"
:
str
(
e
)}}
if
inspect
.
iscoroutinefunction
(
pipe
):
res
=
await
pipe
(
**
param
)
else
:
...
...
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