@@ -49,12 +49,6 @@ public AsyncFiles(ApiClient apiClient) {
4949 this .files = new Files (apiClient );
5050 }
5151
52- /**
53- * Asynchronously lists all files from the service.
54- *
55- * @param config - Optional, configuration for the list method.
56- * @return The ListFilesResponse, the response for the list method.
57- */
5852 CompletableFuture <ListFilesResponse > privateList (ListFilesConfig config ) {
5953 BuiltRequest builtRequest = files .buildRequestForPrivateList (config );
6054 return this .apiClient
@@ -117,6 +111,39 @@ public CompletableFuture<DeleteFileResponse> delete(String name, DeleteFileConfi
117111 });
118112 }
119113
114+ /**
115+ * Asynchronously makes an API request to list the available files.
116+ *
117+ * @param config A {@link ListFilesConfig} for configuring the list request.
118+ * @return A CompletableFuture that resolves to a {@link AsyncPager}. The AsyncPager has a
119+ * `forEach` method that can be used to asynchronously process items in the page and
120+ * automatically query the next page once the current page is exhausted.
121+ */
122+ @ SuppressWarnings ("PatternMatchingInstanceof" )
123+ public CompletableFuture <AsyncPager <File >> list (ListFilesConfig config ) {
124+ if (config == null ) {
125+ config = ListFilesConfig .builder ().build ();
126+ }
127+ ListFilesConfig finalConfig = config ;
128+ Function <JsonSerializable , CompletableFuture <JsonNode >> request =
129+ requestConfig -> {
130+ if (!(requestConfig instanceof ListFilesConfig )) {
131+ throw new GenAiIOException (
132+ "Internal error: Pager expected ListFilesConfig but received "
133+ + requestConfig .getClass ().getName ());
134+ }
135+ return this .privateList ((ListFilesConfig ) requestConfig )
136+ .thenApply (JsonSerializable ::toJsonNode );
137+ };
138+ return CompletableFuture .supplyAsync (
139+ () ->
140+ new AsyncPager <File >(
141+ Pager .PagedItem .FILES ,
142+ request ,
143+ (ObjectNode ) JsonSerializable .toJsonNode (finalConfig ),
144+ request .apply (finalConfig )));
145+ }
146+
120147 /**
121148 * Asynchronously uploads a file to the GenAI API.
122149 *
@@ -213,33 +240,4 @@ public CompletableFuture<Void> download(
213240 File file , String downloadPath , DownloadFileConfig config ) {
214241 return CompletableFuture .runAsync (() -> files .download (file , downloadPath , config ));
215242 }
216-
217- /**
218- * Asynchronously makes an API request to list the available files.
219- *
220- * @param config A {@link ListFilesConfig} for configuring the list request.
221- * @return A CompletableFuture that resolves to a {@link AsyncPager}. The AsyncPager has a
222- * `forEach` method that can be used to asynchronously process items in the page and
223- * automatically query the next page once the current page is exhausted.
224- */
225- @ SuppressWarnings ("PatternMatchingInstanceof" )
226- public CompletableFuture <AsyncPager <File >> list (ListFilesConfig config ) {
227- Function <JsonSerializable , CompletableFuture <JsonNode >> request =
228- requestConfig -> {
229- if (!(requestConfig instanceof ListFilesConfig )) {
230- throw new GenAiIOException (
231- "Internal error: Pager expected ListFilesConfig but received "
232- + requestConfig .getClass ().getName ());
233- }
234- return this .privateList ((ListFilesConfig ) requestConfig )
235- .thenApply (JsonSerializable ::toJsonNode );
236- };
237- return CompletableFuture .supplyAsync (
238- () ->
239- new AsyncPager <>(
240- Pager .PagedItem .FILES ,
241- request ,
242- (ObjectNode ) JsonSerializable .toJsonNode (config ),
243- request .apply (config )));
244- }
245243}
0 commit comments