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
d10e3676
Commit
d10e3676
authored
Dec 14, 2023
by
Timothy J. Baek
Browse files
feat: improved backend error message
parent
c87a80f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+23
-6
No files found.
backend/apps/ollama/main.py
View file @
d10e3676
...
@@ -59,9 +59,11 @@ def proxy(path):
...
@@ -59,9 +59,11 @@ def proxy(path):
else
:
else
:
pass
pass
r
=
None
try
:
try
:
# Make a request to the target server
# Make a request to the target server
target_response
=
requests
.
request
(
r
=
requests
.
request
(
method
=
request
.
method
,
method
=
request
.
method
,
url
=
target_url
,
url
=
target_url
,
data
=
data
,
data
=
data
,
...
@@ -69,22 +71,37 @@ def proxy(path):
...
@@ -69,22 +71,37 @@ def proxy(path):
stream
=
True
,
# Enable streaming for server-sent events
stream
=
True
,
# Enable streaming for server-sent events
)
)
target_response
.
raise_for_status
()
r
.
raise_for_status
()
# Proxy the target server's response to the client
# Proxy the target server's response to the client
def
generate
():
def
generate
():
for
chunk
in
target_response
.
iter_content
(
chunk_size
=
8192
):
for
chunk
in
r
.
iter_content
(
chunk_size
=
8192
):
yield
chunk
yield
chunk
response
=
Response
(
generate
(),
status
=
target_response
.
status_code
)
response
=
Response
(
generate
(),
status
=
r
.
status_code
)
# Copy headers from the target server's response to the client's response
# Copy headers from the target server's response to the client's response
for
key
,
value
in
target_response
.
headers
.
items
():
for
key
,
value
in
r
.
headers
.
items
():
response
.
headers
[
key
]
=
value
response
.
headers
[
key
]
=
value
return
response
return
response
except
Exception
as
e
:
except
Exception
as
e
:
return
jsonify
({
"detail"
:
"Server Connection Error"
,
"message"
:
str
(
e
)}),
400
error_detail
=
"Ollama WebUI: Server Connection Error"
if
r
!=
None
:
res
=
r
.
json
()
if
"error"
in
res
:
error_detail
=
f
"Ollama:
{
res
[
'error'
]
}
"
print
(
res
)
return
(
jsonify
(
{
"detail"
:
error_detail
,
"message"
:
str
(
e
),
}
),
400
,
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
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