@@ -409,6 +409,22 @@ public GenerateContentResponse generateContent(String text) throws IOException {
409
409
return generateContent (text , null , null );
410
410
}
411
411
412
+ /**
413
+ * Generates content from generative model given a text and configs.
414
+ *
415
+ * @param text a text message to send to the generative model
416
+ * @param config a {@link GenerateContentConfig} that contains all the configs in making a
417
+ * generate content api call
418
+ * @return a {@link com.google.cloud.vertexai.api.GenerateContentResponse} instance that contains
419
+ * response contents and other metadata
420
+ * @throws IOException if an I/O error occurs while making the API call
421
+ */
422
+ @ BetaApi
423
+ public GenerateContentResponse generateContent (String text , GenerateContentConfig config )
424
+ throws IOException {
425
+ return generateContent (ContentMaker .fromString (text ), config );
426
+ }
427
+
412
428
/**
413
429
* Generate content from generative model given a text and generation config.
414
430
*
@@ -511,6 +527,41 @@ public GenerateContentResponse generateContent(
511
527
return generateContent (contents , null , safetySettings );
512
528
}
513
529
530
+ /**
531
+ * Generates content from generative model given a list of contents and configs.
532
+ *
533
+ * @param contents a list of {@link com.google.cloud.vertexai.api.Content} to send to the
534
+ * generative model
535
+ * @param config a {@link GenerateContentConfig} that contains all the configs in making a
536
+ * generate content api call
537
+ * @return a {@link com.google.cloud.vertexai.api.GenerateContentResponse} instance that contains
538
+ * response contents and other metadata
539
+ * @throws IOException if an I/O error occurs while making the API call
540
+ */
541
+ @ BetaApi
542
+ public GenerateContentResponse generateContent (
543
+ List <Content > contents , GenerateContentConfig config ) throws IOException {
544
+ GenerateContentRequest .Builder requestBuilder =
545
+ GenerateContentRequest .newBuilder ().addAllContents (contents );
546
+ if (config .getGenerationConfig () != null ) {
547
+ requestBuilder .setGenerationConfig (config .getGenerationConfig ());
548
+ } else if (this .generationConfig != null ) {
549
+ requestBuilder .setGenerationConfig (this .generationConfig );
550
+ }
551
+ if (config .getSafetySettings ().isEmpty () == false ) {
552
+ requestBuilder .addAllSafetySettings (config .getSafetySettings ());
553
+ } else if (this .safetySettings != null ) {
554
+ requestBuilder .addAllSafetySettings (this .safetySettings );
555
+ }
556
+ if (config .getTools ().isEmpty () == false ) {
557
+ requestBuilder .addAllTools (config .getTools ());
558
+ } else if (this .tools != null ) {
559
+ requestBuilder .addAllTools (this .tools );
560
+ }
561
+
562
+ return generateContent (requestBuilder );
563
+ }
564
+
514
565
/**
515
566
* Generate content from generative model given a list of contents, generation config, and safety
516
567
* settings.
@@ -581,6 +632,22 @@ public GenerateContentResponse generateContent(Content content) throws IOExcepti
581
632
return generateContent (content , null , null );
582
633
}
583
634
635
+ /**
636
+ * Generates content from generative model given a single content and configs.
637
+ *
638
+ * @param content a {@link com.google.cloud.vertexai.api.Content} to send to the generative model
639
+ * @param config a {@link GenerateContentConfig} that contains all the configs in making a
640
+ * generate content api call
641
+ * @return a {@link com.google.cloud.vertexai.api.GenerateContentResponse} instance that contains
642
+ * response contents and other metadata
643
+ * @throws IOException if an I/O error occurs while making the API call
644
+ */
645
+ @ BetaApi
646
+ public GenerateContentResponse generateContent (Content content , GenerateContentConfig config )
647
+ throws IOException {
648
+ return generateContent (Arrays .asList (content ), config );
649
+ }
650
+
584
651
/**
585
652
* Generate content from this model given a single content and generation config.
586
653
*
0 commit comments