3131import com .google .genai .types .Image ;
3232import com .google .genai .types .UpscaleImageConfig ;
3333import com .google .genai .types .UpscaleImageResponse ;
34- import java .io .IOException ;
3534import java .util .List ;
3635import java .util .concurrent .CompletableFuture ;
37- import org .apache .http .HttpException ;
3836
3937public final class AsyncModels {
4038 Models models ;
@@ -46,14 +44,7 @@ public AsyncModels(ApiClient apiClient) {
4644 @ BetaApi
4745 public CompletableFuture <GenerateVideosOperation > generateVideos (
4846 String model , String prompt , Image image , GenerateVideosConfig config ) {
49- return CompletableFuture .supplyAsync (
50- () -> {
51- try {
52- return models .generateVideos (model , prompt , image , config );
53- } catch (IOException | HttpException e ) {
54- throw new RuntimeException (e );
55- }
56- });
47+ return CompletableFuture .supplyAsync (() -> models .generateVideos (model , prompt , image , config ));
5748 }
5849
5950 /**
@@ -65,19 +56,10 @@ public CompletableFuture<GenerateVideosOperation> generateVideos(
6556 * the optional configurations
6657 * @return a {@link com.google.genai.types.GenerateContentResponse} instance that contains
6758 * response contents and other metadata
68- * @throws IOException if an I/O error occurs while making the API call
69- * @throws HttpException if an HTTP error occurs while making the API call
7059 */
7160 public CompletableFuture <GenerateContentResponse > generateContent (
7261 String model , List <Content > contents , GenerateContentConfig config ) {
73- return CompletableFuture .supplyAsync (
74- () -> {
75- try {
76- return models .generateContent (model , contents , config );
77- } catch (IOException | HttpException e ) {
78- throw new RuntimeException (e );
79- }
80- });
62+ return CompletableFuture .supplyAsync (() -> models .generateContent (model , contents , config ));
8163 }
8264
8365 /**
@@ -89,12 +71,9 @@ public CompletableFuture<GenerateContentResponse> generateContent(
8971 * the optional configurations
9072 * @return a {@link com.google.genai.types.GenerateContentResponse} instance that contains
9173 * response contents and other metadata
92- * @throws IOException if an I/O error occurs while making the API call
93- * @throws HttpException if an HTTP error occurs while making the API call
9474 */
9575 public CompletableFuture <GenerateContentResponse > generateContent (
96- String model , Content content , GenerateContentConfig config )
97- throws IOException , HttpException {
76+ String model , Content content , GenerateContentConfig config ) {
9877 return generateContent (model , Transformers .tContents (null , (Object ) content ), config );
9978 }
10079
@@ -107,11 +86,9 @@ public CompletableFuture<GenerateContentResponse> generateContent(
10786 * the optional configurations
10887 * @return a {@link com.google.genai.types.GenerateContentResponse} instance that contains
10988 * response contents and other metadata
110- * @throws IOException if an I/O error occurs while making the API call
111- * @throws HttpException if an HTTP error occurs while making the API call
11289 */
11390 public CompletableFuture <GenerateContentResponse > generateContent (
114- String model , String text , GenerateContentConfig config ) throws IOException , HttpException {
91+ String model , String text , GenerateContentConfig config ) {
11592 return generateContent (model , Transformers .tContents (null , (Object ) text ), config );
11693 }
11794
@@ -125,19 +102,11 @@ public CompletableFuture<GenerateContentResponse> generateContent(
125102 * the optional configurations
126103 * @return a {@link com.google.genai.types.GenerateContentResponse} instance that contains
127104 * response contents and other metadata
128- * @throws IOException if an I/O error occurs while making the API call
129- * @throws HttpException if an HTTP error occurs while making the API call
130105 */
131106 public CompletableFuture <ResponseStream <GenerateContentResponse >> generateContentStream (
132107 String model , List <Content > contents , GenerateContentConfig config ) {
133108 return CompletableFuture .supplyAsync (
134- () -> {
135- try {
136- return models .generateContentStream (model , contents , config );
137- } catch (IOException | HttpException e ) {
138- throw new RuntimeException (e );
139- }
140- });
109+ () -> models .generateContentStream (model , contents , config ));
141110 }
142111
143112 /**
@@ -150,12 +119,9 @@ public CompletableFuture<ResponseStream<GenerateContentResponse>> generateConten
150119 * the optional configurations
151120 * @return a {@link com.google.genai.types.GenerateContentResponse} instance that contains
152121 * response contents and other metadata
153- * @throws IOException if an I/O error occurs while making the API call
154- * @throws HttpException if an HTTP error occurs while making the API call
155122 */
156123 public CompletableFuture <ResponseStream <GenerateContentResponse >> generateContentStream (
157- String model , Content content , GenerateContentConfig config )
158- throws IOException , HttpException {
124+ String model , Content content , GenerateContentConfig config ) {
159125 return generateContentStream (model , Transformers .tContents (null , (Object ) content ), config );
160126 }
161127
@@ -168,11 +134,9 @@ public CompletableFuture<ResponseStream<GenerateContentResponse>> generateConten
168134 * the optional configurations
169135 * @return a {@link com.google.genai.types.GenerateContentResponse} instance that contains
170136 * response contents and other metadata
171- * @throws IOException if an I/O error occurs while making the API call
172- * @throws HttpException if an HTTP error occurs while making the API call
173137 */
174138 public CompletableFuture <ResponseStream <GenerateContentResponse >> generateContentStream (
175- String model , String text , GenerateContentConfig config ) throws IOException , HttpException {
139+ String model , String text , GenerateContentConfig config ) {
176140 return generateContentStream (model , Transformers .tContents (null , (Object ) text ), config );
177141 }
178142
@@ -185,19 +149,10 @@ public CompletableFuture<ResponseStream<GenerateContentResponse>> generateConten
185149 * optional configurations
186150 * @return a {@link com.google.genai.types.GenerateImagesResponse} instance that contains the
187151 * generated images.
188- * @throws IOException if an I/O error occurs while making the API call
189- * @throws HttpException if an HTTP error occurs while making the API call
190152 */
191153 public CompletableFuture <GenerateImagesResponse > generateImages (
192- String model , String prompt , GenerateImagesConfig config ) throws IOException , HttpException {
193- return CompletableFuture .supplyAsync (
194- () -> {
195- try {
196- return models .generateImages (model , prompt , config );
197- } catch (IOException | HttpException e ) {
198- throw new RuntimeException (e );
199- }
200- });
154+ String model , String prompt , GenerateImagesConfig config ) {
155+ return CompletableFuture .supplyAsync (() -> models .generateImages (model , prompt , config ));
201156 }
202157
203158 /**
@@ -210,20 +165,11 @@ public CompletableFuture<GenerateImagesResponse> generateImages(
210165 * optional configurations
211166 * @return a {@link com.google.genai.types.UpscaleImageResponse} instance that contains the
212167 * upscaled image.
213- * @throws IOException if an I/O error occurs while making the API call
214- * @throws HttpException if an HTTP error occurs while making the API call
215168 */
216169 public CompletableFuture <UpscaleImageResponse > upscaleImage (
217- String model , Image image , String upscaleFactor , UpscaleImageConfig config )
218- throws IOException , HttpException {
170+ String model , Image image , String upscaleFactor , UpscaleImageConfig config ) {
219171 return CompletableFuture .supplyAsync (
220- () -> {
221- try {
222- return models .upscaleImage (model , image , upscaleFactor , config );
223- } catch (IOException | HttpException e ) {
224- throw new RuntimeException (e );
225- }
226- });
172+ () -> models .upscaleImage (model , image , upscaleFactor , config ));
227173 }
228174
229175 /**
@@ -233,19 +179,10 @@ public CompletableFuture<UpscaleImageResponse> upscaleImage(
233179 * @param text the text string to send to the embedding model
234180 * @return a {@link com.google.genai.types.EmbedContentResponse} instance that contains the
235181 * embedding.
236- * @throws IOException if an I/O error occurs while making the API call
237- * @throws HttpException if an HTTP error occurs while making the API call
238182 */
239183 public CompletableFuture <EmbedContentResponse > embedContent (
240- String model , String text , EmbedContentConfig config ) throws IOException , HttpException {
241- return CompletableFuture .supplyAsync (
242- () -> {
243- try {
244- return models .embedContent (model , text , config );
245- } catch (IOException | HttpException e ) {
246- throw new RuntimeException (e );
247- }
248- });
184+ String model , String text , EmbedContentConfig config ) {
185+ return CompletableFuture .supplyAsync (() -> models .embedContent (model , text , config ));
249186 }
250187
251188 /**
@@ -255,19 +192,9 @@ public CompletableFuture<EmbedContentResponse> embedContent(
255192 * @param texts the list of text strings to send to the embedding model
256193 * @return a {@link com.google.genai.types.EmbedContentResponse} instance that contains the
257194 * embedding.
258- * @throws IOException if an I/O error occurs while making the API call
259- * @throws HttpException if an HTTP error occurs while making the API call
260195 */
261196 public CompletableFuture <EmbedContentResponse > embedContent (
262- String model , List <String > texts , EmbedContentConfig config )
263- throws IOException , HttpException {
264- return CompletableFuture .supplyAsync (
265- () -> {
266- try {
267- return models .embedContent (model , texts , config );
268- } catch (IOException | HttpException e ) {
269- throw new RuntimeException (e );
270- }
271- });
197+ String model , List <String > texts , EmbedContentConfig config ) {
198+ return CompletableFuture .supplyAsync (() -> models .embedContent (model , texts , config ));
272199 }
273200}
0 commit comments