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
39bce7bd
Unverified
Commit
39bce7bd
authored
Dec 13, 2023
by
Timothy Jaeryang Baek
Committed by
GitHub
Dec 13, 2023
Browse files
Merge pull request #214 from ollama-webui/server-error-handling
feat: better error handling for ollama reverse proxy
parents
346b0df8
25987fe3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
21 deletions
+26
-21
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+26
-21
No files found.
backend/apps/ollama/main.py
View file @
39bce7bd
...
...
@@ -59,27 +59,32 @@ def proxy(path):
else
:
pass
# Make a request to the target server
target_response
=
requests
.
request
(
method
=
request
.
method
,
url
=
target_url
,
data
=
data
,
headers
=
headers
,
stream
=
True
,
# Enable streaming for server-sent events
)
# Proxy the target server's response to the client
def
generate
():
for
chunk
in
target_response
.
iter_content
(
chunk_size
=
8192
):
yield
chunk
response
=
Response
(
generate
(),
status
=
target_response
.
status_code
)
# Copy headers from the target server's response to the client's response
for
key
,
value
in
target_response
.
headers
.
items
():
response
.
headers
[
key
]
=
value
return
response
try
:
# Make a request to the target server
target_response
=
requests
.
request
(
method
=
request
.
method
,
url
=
target_url
,
data
=
data
,
headers
=
headers
,
stream
=
True
,
# Enable streaming for server-sent events
)
target_response
.
raise_for_status
()
# Proxy the target server's response to the client
def
generate
():
for
chunk
in
target_response
.
iter_content
(
chunk_size
=
8192
):
yield
chunk
response
=
Response
(
generate
(),
status
=
target_response
.
status_code
)
# Copy headers from the target server's response to the client's response
for
key
,
value
in
target_response
.
headers
.
items
():
response
.
headers
[
key
]
=
value
return
response
except
Exception
as
e
:
return
jsonify
({
"detail"
:
"Server Connection Error"
,
"message"
:
str
(
e
)}),
400
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