Skip to content

Commit d0b9a74

Browse files
speedstorm1copybara-github
authored andcommitted
chore: internal change to autogenerate list methods in Python, Java, and Go SDKs
PiperOrigin-RevId: 835403349
1 parent 6c37f58 commit d0b9a74

File tree

11 files changed

+172
-161
lines changed

11 files changed

+172
-161
lines changed

src/main/java/com/google/genai/AsyncBatches.java

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,39 @@ public CompletableFuture<DeleteResourceJob> delete(String name, DeleteBatchJobCo
144144
});
145145
}
146146

147+
/**
148+
* Asynchronously makes an API request to list the available batch jobs.
149+
*
150+
* @param config A {@link ListBatchJobsConfig} for configuring the list request.
151+
* @return A CompletableFuture that resolves to a {@link AsyncPager}. The AsyncPager has a
152+
* `forEach` method that can be used to asynchronously process items in the page and
153+
* automatically query the next page once the current page is exhausted.
154+
*/
155+
@SuppressWarnings("PatternMatchingInstanceof")
156+
public CompletableFuture<AsyncPager<BatchJob>> list(ListBatchJobsConfig config) {
157+
if (config == null) {
158+
config = ListBatchJobsConfig.builder().build();
159+
}
160+
ListBatchJobsConfig finalConfig = config;
161+
Function<JsonSerializable, CompletableFuture<JsonNode>> request =
162+
requestConfig -> {
163+
if (!(requestConfig instanceof ListBatchJobsConfig)) {
164+
throw new GenAiIOException(
165+
"Internal error: Pager expected ListBatchJobsConfig but received "
166+
+ requestConfig.getClass().getName());
167+
}
168+
return this.privateList((ListBatchJobsConfig) requestConfig)
169+
.thenApply(JsonSerializable::toJsonNode);
170+
};
171+
return CompletableFuture.supplyAsync(
172+
() ->
173+
new AsyncPager<BatchJob>(
174+
Pager.PagedItem.BATCH_JOBS,
175+
request,
176+
(ObjectNode) JsonSerializable.toJsonNode(finalConfig),
177+
request.apply(finalConfig)));
178+
}
179+
147180
/**
148181
* Asynchronously creates a batch job.
149182
*
@@ -196,33 +229,4 @@ public CompletableFuture<BatchJob> createEmbeddings(
196229
}
197230
return this.privateCreateEmbeddings(model, src, config);
198231
}
199-
200-
/**
201-
* Asynchronously makes an API request to list the available batch jobs.
202-
*
203-
* @param config A {@link ListBatchJobsConfig} for configuring the list request.
204-
* @return A CompletableFuture that resolves to a {@link AsyncPager}. The AsyncPager has a
205-
* `forEach` method that can be used to asynchronously process items in the page and
206-
* automatically query the next page once the current page is exhausted.
207-
*/
208-
@SuppressWarnings("PatternMatchingInstanceof")
209-
public CompletableFuture<AsyncPager<BatchJob>> list(ListBatchJobsConfig config) {
210-
Function<JsonSerializable, CompletableFuture<JsonNode>> request =
211-
requestConfig -> {
212-
if (!(requestConfig instanceof ListBatchJobsConfig)) {
213-
throw new GenAiIOException(
214-
"Internal error: Pager expected ListBatchJobsConfig but received "
215-
+ requestConfig.getClass().getName());
216-
}
217-
return this.privateList((ListBatchJobsConfig) requestConfig)
218-
.thenApply(JsonSerializable::toJsonNode);
219-
};
220-
return CompletableFuture.supplyAsync(
221-
() ->
222-
new AsyncPager<>(
223-
Pager.PagedItem.BATCH_JOBS,
224-
request,
225-
(ObjectNode) JsonSerializable.toJsonNode(config),
226-
request.apply(config)));
227-
}
228232
}

src/main/java/com/google/genai/AsyncCaches.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ CompletableFuture<ListCachedContentsResponse> privateList(ListCachedContentsConf
142142
*/
143143
@SuppressWarnings("PatternMatchingInstanceof")
144144
public CompletableFuture<AsyncPager<CachedContent>> list(ListCachedContentsConfig config) {
145+
if (config == null) {
146+
config = ListCachedContentsConfig.builder().build();
147+
}
148+
ListCachedContentsConfig finalConfig = config;
145149
Function<JsonSerializable, CompletableFuture<JsonNode>> request =
146150
requestConfig -> {
147151
if (!(requestConfig instanceof ListCachedContentsConfig)) {
@@ -154,10 +158,10 @@ public CompletableFuture<AsyncPager<CachedContent>> list(ListCachedContentsConfi
154158
};
155159
return CompletableFuture.supplyAsync(
156160
() ->
157-
new AsyncPager<>(
161+
new AsyncPager<CachedContent>(
158162
Pager.PagedItem.CACHED_CONTENTS,
159163
request,
160-
(ObjectNode) JsonSerializable.toJsonNode(config),
161-
request.apply(config)));
164+
(ObjectNode) JsonSerializable.toJsonNode(finalConfig),
165+
request.apply(finalConfig)));
162166
}
163167
}

src/main/java/com/google/genai/AsyncDocuments.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ CompletableFuture<ListDocumentsResponse> privateList(String parent, ListDocument
7878
/**
7979
* Asynchronously makes an API request to list the available documents.
8080
*
81+
* @param parent The name of the RagStore containing the Documents.
8182
* @param config A {@link ListDocumentsConfig} for configuring the list request.
8283
* @return A CompletableFuture that resolves to a {@link AsyncPager}. The AsyncPager has a
8384
* `forEach` method that can be used to asynchronously process items in the page and
@@ -96,14 +97,12 @@ public CompletableFuture<AsyncPager<Document>> list(String parent, ListDocuments
9697
"Internal error: Pager expected ListDocumentsConfig but received "
9798
+ requestConfig.getClass().getName());
9899
}
99-
return CompletableFuture.supplyAsync(
100-
() ->
101-
JsonSerializable.toJsonNode(
102-
documents.privateList(parent, (ListDocumentsConfig) requestConfig)));
100+
return this.privateList(parent, (ListDocumentsConfig) requestConfig)
101+
.thenApply(JsonSerializable::toJsonNode);
103102
};
104103
return CompletableFuture.supplyAsync(
105104
() ->
106-
new AsyncPager<>(
105+
new AsyncPager<Document>(
107106
Pager.PagedItem.DOCUMENTS,
108107
request,
109108
(ObjectNode) JsonSerializable.toJsonNode(finalConfig),

src/main/java/com/google/genai/AsyncFileSearchStores.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,12 @@ public CompletableFuture<AsyncPager<FileSearchStore>> list(ListFileSearchStoresC
154154
"Internal error: Pager expected ListFileSearchStoresConfig but received "
155155
+ requestConfig.getClass().getName());
156156
}
157-
return CompletableFuture.supplyAsync(
158-
() ->
159-
JsonSerializable.toJsonNode(
160-
fileSearchStores.privateList((ListFileSearchStoresConfig) requestConfig)));
157+
return this.privateList((ListFileSearchStoresConfig) requestConfig)
158+
.thenApply(JsonSerializable::toJsonNode);
161159
};
162160
return CompletableFuture.supplyAsync(
163161
() ->
164-
new AsyncPager<>(
162+
new AsyncPager<FileSearchStore>(
165163
Pager.PagedItem.FILE_SEARCH_STORES,
166164
request,
167165
(ObjectNode) JsonSerializable.toJsonNode(finalConfig),

src/main/java/com/google/genai/AsyncFiles.java

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/java/com/google/genai/AsyncTunings.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,6 @@ CompletableFuture<TuningOperation> privateTuneMldev(
121121
});
122122
}
123123

124-
/**
125-
* Asynchronously makes an API request to get a tuning job.
126-
*
127-
* @param name The resource name of the tuning job.
128-
* @param config A {@link GetTuningJobConfig} for configuring the get request.
129-
* @return A CompletableFuture that resolves to a {@link TuningJob} object.
130-
*/
131-
public CompletableFuture<TuningJob> get(String name, GetTuningJobConfig config) {
132-
return CompletableFuture.supplyAsync(() -> tunings.privateGet(name, config));
133-
}
134-
135124
/**
136125
* Asynchronously makes an API request to list the available tuning jobs.
137126
*
@@ -142,6 +131,10 @@ public CompletableFuture<TuningJob> get(String name, GetTuningJobConfig config)
142131
*/
143132
@SuppressWarnings("PatternMatchingInstanceof")
144133
public CompletableFuture<AsyncPager<TuningJob>> list(ListTuningJobsConfig config) {
134+
if (config == null) {
135+
config = ListTuningJobsConfig.builder().build();
136+
}
137+
ListTuningJobsConfig finalConfig = config;
145138
Function<JsonSerializable, CompletableFuture<JsonNode>> request =
146139
requestConfig -> {
147140
if (!(requestConfig instanceof ListTuningJobsConfig)) {
@@ -154,11 +147,22 @@ public CompletableFuture<AsyncPager<TuningJob>> list(ListTuningJobsConfig config
154147
};
155148
return CompletableFuture.supplyAsync(
156149
() ->
157-
new AsyncPager<>(
150+
new AsyncPager<TuningJob>(
158151
Pager.PagedItem.TUNING_JOBS,
159152
request,
160-
(ObjectNode) JsonSerializable.toJsonNode(config),
161-
request.apply(config)));
153+
(ObjectNode) JsonSerializable.toJsonNode(finalConfig),
154+
request.apply(finalConfig)));
155+
}
156+
157+
/**
158+
* Asynchronously makes an API request to get a tuning job.
159+
*
160+
* @param name The resource name of the tuning job.
161+
* @param config A {@link GetTuningJobConfig} for configuring the get request.
162+
* @return A CompletableFuture that resolves to a {@link TuningJob} object.
163+
*/
164+
public CompletableFuture<TuningJob> get(String name, GetTuningJobConfig config) {
165+
return CompletableFuture.supplyAsync(() -> tunings.privateGet(name, config));
162166
}
163167

164168
/**

src/main/java/com/google/genai/Batches.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,34 @@ public DeleteResourceJob delete(String name, DeleteBatchJobConfig config) {
23292329
}
23302330
}
23312331

2332+
/**
2333+
* Makes an API request to list the available batch jobs.
2334+
*
2335+
* @param config A {@link ListBatchJobsConfig} for configuring the list request.
2336+
* @return A {@link Pager} object that contains the list of batch jobs. The pager is an iterable
2337+
* and automatically queries the next page once the current page is exhausted.
2338+
*/
2339+
@SuppressWarnings("PatternMatchingInstanceof")
2340+
public Pager<BatchJob> list(ListBatchJobsConfig config) {
2341+
if (config == null) {
2342+
config = ListBatchJobsConfig.builder().build();
2343+
}
2344+
Function<JsonSerializable, Object> request =
2345+
requestConfig -> {
2346+
if (!(requestConfig instanceof ListBatchJobsConfig)) {
2347+
throw new GenAiIOException(
2348+
"Internal error: Pager expected ListBatchJobsConfig but received "
2349+
+ requestConfig.getClass().getName());
2350+
}
2351+
return this.privateList((ListBatchJobsConfig) requestConfig);
2352+
};
2353+
return new Pager<>(
2354+
Pager.PagedItem.BATCH_JOBS,
2355+
request,
2356+
(ObjectNode) JsonSerializable.toJsonNode(config),
2357+
JsonSerializable.toJsonNode(privateList(config)));
2358+
}
2359+
23322360
/**
23332361
* Makes an API request to create the batch job.
23342362
*
@@ -2380,29 +2408,4 @@ public BatchJob createEmbeddings(
23802408
}
23812409
return this.privateCreateEmbeddings(model, src, config);
23822410
}
2383-
2384-
/**
2385-
* Makes an API request to list the available batch jobs.
2386-
*
2387-
* @param config A {@link ListBatchJobsConfig} for configuring the list request.
2388-
* @return A {@link Pager} object that contains the list of batch jobs. The pager is an iterable
2389-
* and automatically queries the next page once the current page is exhausted.
2390-
*/
2391-
@SuppressWarnings("PatternMatchingInstanceof")
2392-
public Pager<BatchJob> list(ListBatchJobsConfig config) {
2393-
Function<JsonSerializable, Object> request =
2394-
requestConfig -> {
2395-
if (!(requestConfig instanceof ListBatchJobsConfig)) {
2396-
throw new GenAiIOException(
2397-
"Internal error: Pager expected ListBatchJobsConfig but received "
2398-
+ requestConfig.getClass().getName());
2399-
}
2400-
return this.privateList((ListBatchJobsConfig) requestConfig);
2401-
};
2402-
return new Pager<>(
2403-
Pager.PagedItem.BATCH_JOBS,
2404-
request,
2405-
(ObjectNode) JsonSerializable.toJsonNode(config),
2406-
JsonSerializable.toJsonNode(privateList(config)));
2407-
}
24082411
}

src/main/java/com/google/genai/Caches.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,9 @@ ListCachedContentsResponse privateList(ListCachedContentsConfig config) {
14551455
*/
14561456
@SuppressWarnings("PatternMatchingInstanceof")
14571457
public Pager<CachedContent> list(ListCachedContentsConfig config) {
1458+
if (config == null) {
1459+
config = ListCachedContentsConfig.builder().build();
1460+
}
14581461
Function<JsonSerializable, Object> request =
14591462
requestConfig -> {
14601463
if (!(requestConfig instanceof ListCachedContentsConfig)) {

src/main/java/com/google/genai/Documents.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ ListDocumentsResponse privateList(String parent, ListDocumentsConfig config) {
368368
/**
369369
* Makes an API request to list the available documents.
370370
*
371+
* @param parent The name of the RagStore containing the Documents.
371372
* @param config A {@link ListDocumentsConfig} for configuring the list request.
372373
* @return A {@link Pager} object that contains the list of documents. The pager is an iterable
373374
* and automatically queries the next page once the current page is exhausted.

0 commit comments

Comments
 (0)