57
57
import com .google .firebase .ai .type .PublicPreviewAPI ;
58
58
import com .google .firebase .ai .type .ResponseModality ;
59
59
import com .google .firebase .ai .type .SafetyRating ;
60
+ import com .google .firebase .ai .type .Schema ;
60
61
import com .google .firebase .ai .type .SpeechConfig ;
61
62
import com .google .firebase .ai .type .TextPart ;
62
63
import com .google .firebase .ai .type .UsageMetadata ;
63
64
import com .google .firebase .ai .type .Voices ;
64
65
import com .google .firebase .concurrent .FirebaseExecutors ;
66
+ import java .util .ArrayList ;
65
67
import java .util .Calendar ;
66
68
import java .util .List ;
67
69
import java .util .Map ;
@@ -92,8 +94,37 @@ public void initializeJava() throws Exception {
92
94
}
93
95
94
96
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" )))));
97
128
}
98
129
99
130
private LiveGenerationConfig getLiveConfig () {
@@ -113,13 +144,14 @@ private LiveGenerationConfig getLiveConfig() {
113
144
private void testFutures (GenerativeModelFutures futures ) throws Exception {
114
145
Content content =
115
146
new Content .Builder ()
147
+ .setParts (new ArrayList <>())
116
148
.addText ("Fake prompt" )
117
149
.addFileData ("fakeuri" , "image/png" )
118
150
.addInlineData (new byte [] {}, "text/json" )
119
151
.addImage (Bitmap .createBitmap (0 , 0 , Bitmap .Config .HARDWARE ))
120
152
.addPart (new FunctionCallPart ("fakeFunction" , Map .of ("fakeArg" , JsonNull .INSTANCE )))
153
+ .setRole ("user" )
121
154
.build ();
122
- // TODO b/406558430 Content.Builder.setParts and Content.Builder.setRole return void
123
155
Executor executor = FirebaseExecutors .directExecutor ();
124
156
ListenableFuture <CountTokensResponse > countResponse = futures .countTokens (content );
125
157
validateCountTokensResponse (countResponse .get ());
0 commit comments