Skip to content

datarobot_genai.drtools.pagination

pagination

clamp_limit

clamp_limit(limit: int) -> tuple[int, str | None]

Clamp page size to [1, PAGINATION_MAX] and an optional user-facing note.

Source code in datarobot_genai/drtools/pagination.py
def clamp_limit(limit: int) -> tuple[int, str | None]:
    """Clamp page size to [1, PAGINATION_MAX] and an optional user-facing note."""
    if limit < 1:
        return (
            PAGINATION_MAX,
            f"""Limit must be at least 1. The maximum limit of """
            f"""{PAGINATION_MAX} was applied.""",
        )
    if limit > PAGINATION_MAX:
        return (
            PAGINATION_MAX,
            f"""Limit cannot exceed {PAGINATION_MAX}. """
            f"""The maximum limit of {PAGINATION_MAX} was applied.""",
        )
    return (limit, None)

merge_pagination_metadata

merge_pagination_metadata(final_results: dict[str, Any], api_response: dict[str, Any] | list, message: str | None = None, *, offset: int | None = None, limit: int | None = None) -> dict[str, Any]

Add offset/limit echo and DataRobot list pagination (next, previous, total) when present.

Source code in datarobot_genai/drtools/pagination.py
def merge_pagination_metadata(
    final_results: dict[str, Any],
    api_response: dict[str, Any] | list,
    message: str | None = None,
    *,
    offset: int | None = None,
    limit: int | None = None,
) -> dict[str, Any]:
    """Add offset/limit echo and DataRobot list pagination (next, previous, total) when present."""
    if offset is not None:
        final_results["offset"] = offset
    if limit is not None:
        final_results["limit"] = limit
    if message is not None:
        final_results["note"] = message
    if isinstance(api_response, dict):
        for key in ("next", "previous"):
            if key in api_response and api_response[key] is not None:
                final_results[key] = api_response[key]
        for total_key in ("total_count", "totalCount", "total"):
            if total_key in api_response and api_response[total_key] is not None:
                final_results["total_count"] = api_response[total_key]
                break
    return final_results