def max_pdf_page_count_validator()

in aidial_adapter_vertexai/chat/gemini/processor.py [0:0]


def max_pdf_page_count_validator(limit: int) -> PostValidator:
    count = 0

    async def validator(resource: Resource):
        nonlocal count
        try:
            pages = await get_pdf_page_count(resource.data)
            log.debug(f"PDF page count: {pages}")
            count += pages
        except Exception:
            log.exception("Failed to get PDF page count")
            raise ValidationError("Failed to get PDF page count")

        if count > limit:
            raise ValidationError(
                f"The total number of PDF pages exceeds the limit ({limit})"
            )

    return validator