"...composable_kernel_rocm.git" did not exist on "ccf10794dad5aa37545508aa81a80067089dec13"
Unverified Commit 39bce7bd authored by Timothy Jaeryang Baek's avatar Timothy Jaeryang Baek Committed by GitHub
Browse files

Merge pull request #214 from ollama-webui/server-error-handling

feat: better error handling for ollama reverse proxy
parents 346b0df8 25987fe3
...@@ -59,27 +59,32 @@ def proxy(path): ...@@ -59,27 +59,32 @@ def proxy(path):
else: else:
pass pass
# Make a request to the target server try:
target_response = requests.request( # Make a request to the target server
method=request.method, target_response = requests.request(
url=target_url, method=request.method,
data=data, url=target_url,
headers=headers, data=data,
stream=True, # Enable streaming for server-sent events headers=headers,
) stream=True, # Enable streaming for server-sent events
)
# Proxy the target server's response to the client
def generate(): target_response.raise_for_status()
for chunk in target_response.iter_content(chunk_size=8192):
yield chunk # Proxy the target server's response to the client
def generate():
response = Response(generate(), status=target_response.status_code) for chunk in target_response.iter_content(chunk_size=8192):
yield chunk
# Copy headers from the target server's response to the client's response
for key, value in target_response.headers.items(): response = Response(generate(), status=target_response.status_code)
response.headers[key] = value
# Copy headers from the target server's response to the client's response
return 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__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment