5757import com .google .firebase .ai .type .PublicPreviewAPI ;
5858import com .google .firebase .ai .type .ResponseModality ;
5959import com .google .firebase .ai .type .SafetyRating ;
60+ import com .google .firebase .ai .type .Schema ;
6061import com .google .firebase .ai .type .SpeechConfig ;
6162import com .google .firebase .ai .type .TextPart ;
6263import com .google .firebase .ai .type .UsageMetadata ;
6364import com .google .firebase .ai .type .Voices ;
6465import com .google .firebase .concurrent .FirebaseExecutors ;
66+ import java .util .ArrayList ;
6567import java .util .Calendar ;
6668import java .util .List ;
6769import java .util .Map ;
@@ -92,8 +94,37 @@ public void initializeJava() throws Exception {
9294 }
9395
9496 private GenerationConfig getConfig () {
95- return new GenerationConfig .Builder ().build ();
96- // TODO b/406558430 GenerationConfig.Builder.setParts returns void
97+ return new GenerationConfig .Builder ()
98+ .setTopK (10 )
99+ .setTopP (11.0F )
100+ .setTemperature (32.0F )
101+ .setCandidateCount (1 )
102+ .setMaxOutputTokens (0xCAFEBABE )
103+ .setFrequencyPenalty (1.0F )
104+ .setPresencePenalty (2.0F )
105+ .setStopSequences (List .of ("foo" , "bar" ))
106+ .setResponseMimeType ("image/jxl" )
107+ .setResponseModalities (List .of (ResponseModality .TEXT , ResponseModality .TEXT ))
108+ .setResponseSchema (getSchema ())
109+ .build ();
110+ }
111+
112+ private Schema getSchema () {
113+ return Schema .obj (
114+ Map .of (
115+ "foo" , Schema .numInt (),
116+ "bar" , Schema .numInt ("Some integer" ),
117+ "baz" , Schema .numInt ("Some integer" , false ),
118+ "qux" , Schema .numDouble (),
119+ "quux" , Schema .numFloat ("Some floating point number" ),
120+ "xyzzy" , Schema .array (Schema .numInt (), "A list of integers" ),
121+ "fee" , Schema .numLong (),
122+ "ber" ,
123+ Schema .obj (
124+ Map .of (
125+ "bez" , Schema .array (Schema .numDouble ("Nullable double" , true )),
126+ "qez" , Schema .enumeration (List .of ("A" , "B" , "C" ), "One of 3 letters" ),
127+ "qeez" , Schema .str ("A funny string" )))));
97128 }
98129
99130 private LiveGenerationConfig getLiveConfig () {
@@ -113,13 +144,14 @@ private LiveGenerationConfig getLiveConfig() {
113144 private void testFutures (GenerativeModelFutures futures ) throws Exception {
114145 Content content =
115146 new Content .Builder ()
147+ .setParts (new ArrayList <>())
116148 .addText ("Fake prompt" )
117149 .addFileData ("fakeuri" , "image/png" )
118150 .addInlineData (new byte [] {}, "text/json" )
119151 .addImage (Bitmap .createBitmap (0 , 0 , Bitmap .Config .HARDWARE ))
120152 .addPart (new FunctionCallPart ("fakeFunction" , Map .of ("fakeArg" , JsonNull .INSTANCE )))
153+ .setRole ("user" )
121154 .build ();
122- // TODO b/406558430 Content.Builder.setParts and Content.Builder.setRole return void
123155 Executor executor = FirebaseExecutors .directExecutor ();
124156 ListenableFuture <CountTokensResponse > countResponse = futures .countTokens (content );
125157 validateCountTokensResponse (countResponse .get ());
0 commit comments