[Bugfix][Frontend] Raise VLLMValidationError for user-facing errors in chat_utils.py (#50491)
Signed-off-by: latent-9 <296084221+latent-9@users.noreply.github.com> Co-authored-by: latent-9 <296084221+latent-9@users.noreply.github.com>
This commit is contained in:
@@ -2092,7 +2092,7 @@ def test_parse_chat_messages_multiple_images_interleave_with_placeholders(
|
||||
image_url,
|
||||
):
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
VLLMValidationError,
|
||||
match=r"Found more '<|image_1|>' placeholders in input prompt "
|
||||
"than actual multimodal data items.",
|
||||
):
|
||||
|
||||
@@ -316,7 +316,7 @@ _PLACEHOLDER_ERROR_PATTERN: Final[str] = re.sub(
|
||||
def test_parse_chat_messages_rejects_placeholder_in_user_text(content):
|
||||
mc = _make_mock_model_config() # enable_prompt_embeds=True by default
|
||||
messages = [{"role": "user", "content": content}]
|
||||
with pytest.raises(ValueError, match=_PLACEHOLDER_ERROR_PATTERN):
|
||||
with pytest.raises(VLLMValidationError, match=_PLACEHOLDER_ERROR_PATTERN):
|
||||
parse_chat_messages(messages, mc, content_format="openai")
|
||||
|
||||
|
||||
|
||||
@@ -467,7 +467,7 @@ def _merge_embeds(
|
||||
|
||||
first_keys = set(data_items[0].keys())
|
||||
if any(set(item.keys()) != first_keys for item in data_items[1:]):
|
||||
raise ValueError(
|
||||
raise VLLMValidationError(
|
||||
"All dictionaries in the list of embeddings must have the same keys."
|
||||
)
|
||||
|
||||
@@ -746,9 +746,15 @@ def _resolve_items(
|
||||
modality requires a processor, enforced by the guard below.
|
||||
"""
|
||||
if "image" in items_by_modality and "image_embeds" in items_by_modality:
|
||||
raise ValueError("Mixing raw image and embedding inputs is not allowed")
|
||||
raise VLLMValidationError(
|
||||
"Mixing raw image and embedding inputs is not allowed",
|
||||
parameter="image_embeds",
|
||||
)
|
||||
if "audio" in items_by_modality and "audio_embeds" in items_by_modality:
|
||||
raise ValueError("Mixing raw audio and embedding inputs is not allowed")
|
||||
raise VLLMValidationError(
|
||||
"Mixing raw audio and embedding inputs is not allowed",
|
||||
parameter="audio_embeds",
|
||||
)
|
||||
# `prompt_embeds` bypasses HF MM processors. Every other modality requires one.
|
||||
processor_modalities = items_by_modality.keys() - {"prompt_embeds"}
|
||||
if processor_modalities and mm_processor is None:
|
||||
@@ -1448,7 +1454,7 @@ def _get_full_multimodal_text_prompt(
|
||||
interleave_strings,
|
||||
)
|
||||
logger.debug("Input prompt: %s", text_prompt)
|
||||
raise ValueError(
|
||||
raise VLLMValidationError(
|
||||
f"Found more '{placeholder}' placeholders in input prompt than "
|
||||
"actual multimodal data items."
|
||||
)
|
||||
@@ -1696,7 +1702,7 @@ def _reject_reserved_placeholder_in_text(text: str, model_config: ModelConfig) -
|
||||
caller move or inject splice positions via plain text content.
|
||||
"""
|
||||
if model_config.enable_prompt_embeds and PROMPT_EMBEDS_PLACEHOLDER_TOKEN in text:
|
||||
raise ValueError(
|
||||
raise VLLMValidationError(
|
||||
_RESERVED_PLACEHOLDER_IN_TEXT_ERROR.format(
|
||||
token=PROMPT_EMBEDS_PLACEHOLDER_TOKEN
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user