Fix err 500

parent c52a65d7
...@@ -953,9 +953,9 @@ class RotationHandler: ...@@ -953,9 +953,9 @@ class RotationHandler:
"rotation_id": rotation_id, "rotation_id": rotation_id,
"error_details": error_details "error_details": error_details
} }
# Return as StreamingResponse if original request was streaming, otherwise return dict # For streaming requests, wrap in a simple streaming response
if stream: if stream:
return self._create_streaming_response(error_response, rotation_id) return self._create_error_streaming_response(error_response)
else: else:
return error_response return error_response
else: else:
...@@ -1312,9 +1312,9 @@ class RotationHandler: ...@@ -1312,9 +1312,9 @@ class RotationHandler:
"last_error": last_error, "last_error": last_error,
"error_details": error_details "error_details": error_details
} }
# Return as StreamingResponse if original request was streaming, otherwise return dict # For streaming requests, wrap in a simple streaming response
if stream: if stream:
return self._create_streaming_response(error_response, rotation_id) return self._create_error_streaming_response(error_response)
else: else:
return error_response return error_response
else: else:
...@@ -1331,6 +1331,28 @@ class RotationHandler: ...@@ -1331,6 +1331,28 @@ class RotationHandler:
} }
) )
def _create_error_streaming_response(self, error_response: Dict):
"""
Create a simple StreamingResponse for error messages.
This is used when notifyerrors is enabled and we need to return
an error as a streaming response instead of raising an HTTPException.
Args:
error_response: The error response dict to stream
Returns:
StreamingResponse with the error response as a single chunk
"""
import json
import time
async def error_stream_generator():
# Send the error response as a single chunk
yield f"data: {json.dumps(error_response)}\n\n".encode('utf-8')
return StreamingResponse(error_stream_generator(), media_type="text/event-stream")
def _create_streaming_response(self, response, provider_type: str, provider_id: str, model_name: str, handler, request_data: Dict, effective_context: int): def _create_streaming_response(self, response, provider_type: str, provider_id: str, model_name: str, handler, request_data: Dict, effective_context: int):
""" """
Create a StreamingResponse with proper handling based on provider type. Create a StreamingResponse with proper handling based on provider type.
......
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