Files
vllm-omni/vllm_omni/inputs/parse.py
T
tzhouam 52d0122fb5 [Enhancement] Refactor OmniInputProcessor and related classes for improved prompt handling
- Updated OmniInputProcessor to streamline input processing, including enhanced handling of prompt embeddings and additional information.
- Introduced OmniTextPrompt and OmniEmbedsInputs to support new input structures with optional metadata.
- Modified input preprocessing methods to accommodate new prompt types and ensure compatibility with multimodal inputs.
- Improved error handling and type checking for data parallel configurations.

Signed-off-by: [Your Name] <your.email@example.com>

Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
2026-01-28 15:42:05 +08:00

46 lines
1.7 KiB
Python

from vllm.inputs.parse import (
ParsedEmbedsPrompt,
ParsedSingletonPrompt,
ParsedStrPrompt,
ParsedTextPrompt,
ParsedTokensPrompt,
)
from vllm_omni.inputs.data import OmniSingletonPrompt
def parse_singleton_prompt_omni(
prompt: OmniSingletonPrompt,
) -> ParsedSingletonPrompt:
"""Parse a singleton prompt into a typed parsed prompt.
Handles omni-specific prompt types including tokens prompts with
embeddings and additional information. Supports string, text,
tokens, and embeddings prompts.
Args:
prompt: Singleton prompt to parse. Can be a string, TextPrompt,
TokensPrompt (with optional prompt_embeds and additional_information),
or EmbedsPrompt.
Returns:
ParsedSingletonPrompt containing the parsed prompt with type information
Raises:
TypeError: If the prompt type is not supported
"""
if isinstance(prompt, str):
return ParsedStrPrompt(type="str", content=prompt)
elif isinstance(prompt, dict):
# Type ignores are because mypy does not correctly infer the TypedDicts
# Pyright does succeed.
# Priority tokens: When both tokens and embeds exist, keep both and
# follow the tokens path
if "prompt_token_ids" in prompt:
return ParsedTokensPrompt(type="tokens", content=prompt) # type: ignore[typeddict-item]
elif "prompt_embeds" in prompt:
return ParsedEmbedsPrompt(type="embeds", content=prompt) # type: ignore[typeddict-item]
elif "prompt" in prompt:
return ParsedTextPrompt(type="text", content=prompt)
raise TypeError("inputs must be a string, TextPrompt, TokensPrompt, or EmbedsPrompt")