|
6 | 6 | from replicate.exceptions import ReplicateException |
7 | 7 | from replicate.files import upload_file |
8 | 8 | from replicate.json import encode_json |
| 9 | +from replicate.pagination import Page |
9 | 10 | from replicate.resource import Namespace, Resource |
10 | 11 | from replicate.version import Version |
11 | 12 |
|
@@ -90,21 +91,25 @@ class CreateParams(TypedDict): |
90 | 91 | webhook_completed: NotRequired[str] |
91 | 92 | webhook_events_filter: NotRequired[List[str]] |
92 | 93 |
|
93 | | - def list(self) -> List[Training]: |
| 94 | + def list(self, cursor: Union[str, "ellipsis"] = ...) -> Page[Training]: # noqa: F821 |
94 | 95 | """ |
95 | 96 | List your trainings. |
96 | 97 |
|
| 98 | + Parameters: |
| 99 | + cursor: The cursor to use for pagination. Use the value of `Page.next` or `Page.previous`. |
97 | 100 | Returns: |
98 | | - List[Training]: A list of training objects. |
| 101 | + Page[Training]: A page of trainings. |
| 102 | + Raises: |
| 103 | + ValueError: If `cursor` is `None`. |
99 | 104 | """ |
100 | 105 |
|
101 | | - resp = self._client._request("GET", "/v1/trainings") |
102 | | - # TODO: paginate |
103 | | - trainings = resp.json()["results"] |
104 | | - for training in trainings: |
105 | | - # HACK: resolve this? make it lazy somehow? |
106 | | - del training["version"] |
107 | | - return [self._prepare_model(obj) for obj in trainings] |
| 106 | + if cursor is None: |
| 107 | + raise ValueError("cursor cannot be None") |
| 108 | + |
| 109 | + resp = self._client._request( |
| 110 | + "GET", "/v1/trainings" if cursor is ... else cursor |
| 111 | + ) |
| 112 | + return Page[Training](self._client, self, **resp.json()) |
108 | 113 |
|
109 | 114 | def get(self, id: str) -> Training: # pylint: disable=invalid-name |
110 | 115 | """ |
|
0 commit comments