Classify malformed-multimodal rejects as invalid_request (#27451)
Co-authored-by: cctry <cctry@meta.com> Co-authored-by: cctry <cctry@fb.com>
This commit is contained in:
co-authored by
cctry
cctry
parent
bd7fea0740
commit
88a7b0fd30
@@ -726,7 +726,21 @@ async def generate_request(obj: GenerateReqInput, request: Request):
|
|||||||
):
|
):
|
||||||
yield b"data: " + dumps_json(out) + b"\n\n"
|
yield b"data: " + dumps_json(out) + b"\n\n"
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
out = {"error": {"message": str(e)}}
|
# A client disconnect also surfaces here. It's a client-side
|
||||||
|
# cancellation, not a server error or bad input -- log it and
|
||||||
|
# stop (the request was already aborted upstream) instead of
|
||||||
|
# emitting a 400.
|
||||||
|
if request is not None and await request.is_disconnected():
|
||||||
|
logger.info(f"[http_server] Client disconnected: {e}")
|
||||||
|
return
|
||||||
|
out = {
|
||||||
|
"error": {
|
||||||
|
"message": str(e),
|
||||||
|
"type": "invalid_request_error",
|
||||||
|
"code": 400,
|
||||||
|
"retryable": False,
|
||||||
|
}
|
||||||
|
}
|
||||||
logger.error(f"[http_server] Error: {e}")
|
logger.error(f"[http_server] Error: {e}")
|
||||||
yield b"data: " + dumps_json(out) + b"\n\n"
|
yield b"data: " + dumps_json(out) + b"\n\n"
|
||||||
yield b"data: [DONE]\n\n"
|
yield b"data: [DONE]\n\n"
|
||||||
|
|||||||
@@ -549,8 +549,17 @@ class BaseMultimodalProcessor(ABC):
|
|||||||
elif modality == Modality.AUDIO:
|
elif modality == Modality.AUDIO:
|
||||||
return load_audio(data, audio_sample_rate)
|
return load_audio(data, audio_sample_rate)
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
# Bad input (e.g. invalid base64) -> 400, not 500.
|
||||||
|
data_str = str(data)
|
||||||
|
if len(data_str) > 100:
|
||||||
|
data_str = data_str[:100] + "..."
|
||||||
|
raise ValueError(f"Error while loading data {data_str}: {e}") from e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(f"Error while loading data {data}: {e}")
|
data_str = str(data)
|
||||||
|
if len(data_str) > 100:
|
||||||
|
data_str = data_str[:100] + "..."
|
||||||
|
raise RuntimeError(f"Error while loading data {data_str}: {e}") from e
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_preprocessed_input_format(data):
|
def _get_preprocessed_input_format(data):
|
||||||
|
|||||||
Reference in New Issue
Block a user