Skip to content

Commit cdd63f8

Browse files
jaycee-licopybara-github
authored andcommitted
chore: Fix compilation error and clean up the FileSearchStoresAsync example
PiperOrigin-RevId: 833437742
1 parent f5ee8b7 commit cdd63f8

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

examples/src/main/java/com/google/genai/examples/FileSearchStores.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ public static void main(String[] args) {
8787
System.out.println("Created file store: " + fileSearchStore.name().get());
8888

8989
// Get the uploaded file search store.
90-
FileSearchStore retrievedFile =
90+
FileSearchStore retrievedFileStore =
9191
client.fileSearchStores.get(fileSearchStore.name().get(), null);
92-
System.out.println("Retrieved file: " + retrievedFile.name().get());
92+
System.out.println("Retrieved file store: " + retrievedFileStore.name().get());
9393

9494
// List all file stores.
9595
System.out.println("List file stores: ");
9696
for (FileSearchStore f :
9797
client.fileSearchStores.list(ListFileSearchStoresConfig.builder().pageSize(10).build())) {
98-
System.out.println("File store name: " + f.name().get());
98+
System.out.println(" File store name: " + f.name().get());
9999
}
100100

101101
// Upload a file to the Files Service.
@@ -145,7 +145,7 @@ public static void main(String[] args) {
145145
System.out.println("List documents: ");
146146
for (Document d :
147147
client.fileSearchStores.documents.list(fileSearchStore.name().get(), null)) {
148-
System.out.println("Document name: " + d.name().get());
148+
System.out.println(" Document name: " + d.name().get());
149149
}
150150

151151
// Delete the imported document

examples/src/main/java/com/google/genai/examples/FileSearchStoresAsync.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* <p>mvn clean compile
3939
*
40-
* <p>mvn exec:java -Dexec.mainClass="com.google.genai.examples.FileSearchStores"
40+
* <p>mvn exec:java -Dexec.mainClass="com.google.genai.examples.FileSearchStoresAsync"
4141
* -Dexec.args="path/to/file"
4242
*/
4343
package com.google.genai.examples;
@@ -79,7 +79,7 @@ private static <R, T extends Operation<R, T>> CompletableFuture<T> awaitOperatio
7979
.thenCompose(newOp -> awaitOperationComplete(client, (T) newOp));
8080
}
8181

82-
public static void main(String[] args) throws ExecutionException, InterruptedException {
82+
public static void main(String[] args) throws Exception {
8383
String filePath = args.length > 0 ? args[0] : Constants.UPLOAD_FILE_PATH;
8484

8585
try (Client client = new Client()) {
@@ -97,7 +97,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
9797
.create(null)
9898
.thenCompose(
9999
store -> {
100-
System.out.println("\n--- Created Store: " + store.name().get() + " ---");
100+
System.out.println("Created file store: " + store.name().get());
101101

102102
// Get store
103103
return client
@@ -107,20 +107,20 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
107107
.thenAccept(
108108
retrievedStore ->
109109
System.out.println(
110-
"Get Store: Success (" + retrievedStore.name().get() + ")"))
110+
"Retrieved file store: " + retrievedStore.name().get() + ")"))
111111

112112
// List stores.
113113
.thenCompose(
114114
v ->
115115
client.async.fileSearchStores.list(
116116
ListFileSearchStoresConfig.builder().pageSize(10).build()))
117-
.thenAccept(
117+
.thenCompose(
118118
pager -> {
119-
System.out.println("List all stores names: ");
120-
var unused =
121-
pager.forEach(
122-
item ->
123-
System.out.println("Store name: " + item.name().get()));
119+
System.out.println("List file stores: ");
120+
return pager.forEach(
121+
item ->
122+
System.out.println(
123+
" File store name: " + item.name().get()));
124124
})
125125
.thenApply(v -> store);
126126
})
@@ -133,9 +133,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
133133
.upload(filePath, UploadFileConfig.builder().mimeType("text/plain").build())
134134
.thenApply(
135135
file -> {
136-
System.out.println(
137-
"Upload File (Files Service): " + file.name().get());
138-
return new Object[] {store, file}; // Pass both
136+
System.out.println("Uploaded file: " + file.name().get());
137+
return new Object[] {store, file};
139138
});
140139
})
141140
.thenCompose(
@@ -190,14 +189,12 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
190189
v ->
191190
client.async.fileSearchStores.documents.list(
192191
store.name().get(), null))
193-
.thenAccept(
192+
.thenCompose(
194193
pager -> {
195194
System.out.println("List all document names: ");
196-
var unused =
197-
pager.forEach(
198-
item ->
199-
System.out.println(
200-
"document name: " + item.name().get()));
195+
return pager.forEach(
196+
item ->
197+
System.out.println(" document name: " + item.name().get()));
201198
})
202199

203200
// Delete document
@@ -211,9 +208,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
211208
.thenAccept(v -> System.out.println("Delete Store: Success."));
212209
});
213210
finalFuture.get();
214-
} catch (Exception e) {
215-
System.err.println("An error occurred during async execution: " + e.getMessage());
216211
}
212+
System.out.println("Async execution for file search stores completed successfully.");
217213
}
218214

219215
private FileSearchStoresAsync() {}

0 commit comments

Comments
 (0)