File tree 2 files changed +11
-20
lines changed
openai-java-example/src/main/java/com/openai/example
2 files changed +11
-20
lines changed Original file line number Diff line number Diff line change @@ -109,18 +109,14 @@ private static CompletableFuture<Void> listThreadMessages(OpenAIClientAsync clie
109
109
.order (MessageListParams .Order .ASC )
110
110
.build ());
111
111
return pageFuture .thenComposeAsync (page -> page .autoPager ()
112
- .forEach (
113
- currentMessage -> {
114
- System .out .println (currentMessage .role ().toString ().toUpperCase ());
115
- currentMessage .content ().stream ()
116
- .flatMap (content -> content .text ().stream ())
117
- .forEach (textBlock ->
118
- System .out .println (textBlock .text ().value ()));
119
- System .out .println ();
120
-
121
- // Keep iterating
122
- return true ;
123
- },
124
- pageFuture .defaultExecutor ()));
112
+ .subscribe (currentMessage -> {
113
+ System .out .println (currentMessage .role ().toString ().toUpperCase ());
114
+ currentMessage .content ().stream ()
115
+ .flatMap (content -> content .text ().stream ())
116
+ .forEach (textBlock ->
117
+ System .out .println (textBlock .text ().value ()));
118
+ System .out .println ();
119
+ })
120
+ .onCompleteFuture ());
125
121
}
126
122
}
Original file line number Diff line number Diff line change @@ -17,13 +17,8 @@ public static void main(String[] args) {
17
17
CompletableFuture <ModelListPageAsync > pageFuture = client .models ().list ();
18
18
pageFuture
19
19
.thenComposeAsync (page -> page .autoPager ()
20
- .forEach (
21
- model -> {
22
- System .out .println (model .id ());
23
- // Keep iterating
24
- return true ;
25
- },
26
- pageFuture .defaultExecutor ()))
20
+ .subscribe (model -> System .out .println (model .id ()))
21
+ .onCompleteFuture ())
27
22
.join ();
28
23
}
29
24
}
You can’t perform that action at this time.
0 commit comments