Coverage for src/fastoai/pagination.py: 89%
19 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-06 09:34 +0800
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-06 09:34 +0800
1from typing import Generic, Literal, TypeVar, cast
3from openai.pagination import AsyncCursorPage, CursorPageItem
4from pydantic import computed_field
6_T = TypeVar("_T")
9class AsyncCursorPage(AsyncCursorPage[_T], Generic[_T]):
10 object: Literal["list"] = "list"
12 @computed_field
13 def has_more(self) -> bool:
14 return self.has_next_page()
16 @computed_field
17 def first_id(self) -> str | None:
18 if not self.data:
19 return None
20 return cast(CursorPageItem, self.data[0]).id
22 @computed_field
23 def last_id(self) -> str | None:
24 if not self.data:
25 return None
26 return cast(CursorPageItem, self.data[-1]).id