跳到内容

vllm_gaudi.extension.validation

Checker module-attribute

Error module-attribute

Error: TypeAlias = str

choice

choice(*options: Any) -> Checker

验证输入是否为可用选项之一

源代码位于 vllm_gaudi/extension/validation.py
def choice(*options: Any) -> Checker:
    """Validates if input is one of the available choices"""

    def choice_impl(x):
        if x not in options:
            return f'{x} is not in allowed options: [{", ".join(map(str, options))}]!'

    return choice_impl

for_all

for_all(checker: Checker) -> Checker

验证所有值是否根据给定校验器有效

源代码位于 vllm_gaudi/extension/validation.py
def for_all(checker: Checker) -> Checker:
    """Validates if all values are valid according to given checker"""

    def for_all_impl(values: list) -> Optional[Error]:
        errors = [checker(v) for v in values if checker(v)]
        if errors:
            return 'Errors:\n' + '\n'.join(f"- {e}" for e in errors)
        return None

    return for_all_impl

regex

regex(pattern, hint='') -> Checker

验证输入是否匹配模式,可选地在出错时提供提示

源代码位于 vllm_gaudi/extension/validation.py
def regex(pattern, hint='') -> Checker:
    """Validates if input matches pattern, optionally providing a hint in case of error"""

    def regex_impl(value: str):
        if not re.match(pattern, value):
            return f"'{value}' doesn't match pattern '{pattern}'! {hint}"

    return regex_impl

skip_validation

skip_validation(_) -> None

用于跳过验证的虚拟 Checker

源代码位于 vllm_gaudi/extension/validation.py
def skip_validation(_) -> None:
    """Dummy Checker used to skip validation"""
    return None