@@ -50,10 +50,11 @@ public class SnippetsIT {
50
50
private static final String GEMINI_PRO_1_5 = "gemini-1.5-pro-preview-0409" ;
51
51
private static final int MAX_ATTEMPT_COUNT = 3 ;
52
52
private static final int INITIAL_BACKOFF_MILLIS = 120000 ; // 2 minutes
53
+
53
54
@ Rule
54
- public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule (
55
- MAX_ATTEMPT_COUNT ,
56
- INITIAL_BACKOFF_MILLIS );
55
+ public final MultipleAttemptsRule multipleAttemptsRule =
56
+ new MultipleAttemptsRule ( MAX_ATTEMPT_COUNT , INITIAL_BACKOFF_MILLIS );
57
+
57
58
private final PrintStream printStream = System .out ;
58
59
private ByteArrayOutputStream bout ;
59
60
@@ -145,10 +146,11 @@ public void testMultimodalMultiImage() throws IOException {
145
146
146
147
@ Test
147
148
public void testMultimodalQuery () throws Exception {
148
- String imageUri = "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark1.png" ;
149
+ String imageUri =
150
+ "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark1.png" ;
149
151
String dataImageBase64 = Base64 .getEncoder ().encodeToString (readImageFile (imageUri ));
150
- String output = MultimodalQuery . multimodalQuery ( PROJECT_ID , LOCATION , GEMINI_PRO_VISION ,
151
- dataImageBase64 );
152
+ String output =
153
+ MultimodalQuery . multimodalQuery ( PROJECT_ID , LOCATION , GEMINI_PRO_VISION , dataImageBase64 );
152
154
assertThat (output ).isNotEmpty ();
153
155
}
154
156
@@ -180,26 +182,42 @@ public void testQuickstart() throws IOException {
180
182
181
183
@ Test
182
184
public void testSingleTurnMultimodal () throws IOException {
183
- String imageUri = "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark1.png" ;
185
+ String imageUri =
186
+ "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark1.png" ;
184
187
String dataImageBase64 = Base64 .getEncoder ().encodeToString (readImageFile (imageUri ));
185
- SingleTurnMultimodal .generateContent (PROJECT_ID , LOCATION , GEMINI_PRO_VISION ,
186
- "What is this image" , dataImageBase64 );
188
+ SingleTurnMultimodal .generateContent (
189
+ PROJECT_ID , LOCATION , GEMINI_PRO_VISION , "What is this image" , dataImageBase64 );
187
190
assertThat (bout .toString ()).contains ("Colosseum" );
188
191
}
189
192
190
193
@ Test
191
194
public void testStreamingQuestions () throws Exception {
192
- StreamingQuestionAnswer .streamingQuestion (PROJECT_ID , LOCATION ,
193
- GEMINI_PRO_VISION );
195
+ StreamingQuestionAnswer .streamingQuestion (PROJECT_ID , LOCATION , GEMINI_PRO_VISION );
194
196
assertThat (bout .toString ()).contains ("Rayleigh scattering" );
195
197
}
196
198
199
+ @ Test
200
+ public void testTextInput () throws Exception {
201
+ String textPrompt =
202
+ "Give a score from 1 - 10 to suggest if the following movie review is negative or positive"
203
+ + " (1 is most negative, 10 is most positive, 5 will be neutral). Include an"
204
+ + " explanation.\n "
205
+ + "This era was not just the dawn of sound in cartoons, but of a cartoon character"
206
+ + " which would go down in history as the world's most famous mouse. Yes, Mickey makes"
207
+ + " his debut here, in this cheery tale of life on board a steamboat. The animation is"
208
+ + " good for it's time, and the plot - though a little simple - is quite jolly. A true"
209
+ + " classic, and if you ever manage to get it on video, you won't regret it." ;
210
+ String output = TextInput .textInput (PROJECT_ID , LOCATION , GEMINI_PRO , textPrompt );
211
+ assertThat (output ).isNotEmpty ();
212
+ assertThat (output ).contains ("positive" );
213
+ }
214
+
197
215
@ Test
198
216
public void testSafetySettings () throws Exception {
199
217
String textPrompt = "Hello World!" ;
200
218
201
- String output = WithSafetySettings . safetyCheck ( PROJECT_ID , LOCATION , GEMINI_PRO_VISION ,
202
- textPrompt );
219
+ String output =
220
+ WithSafetySettings . safetyCheck ( PROJECT_ID , LOCATION , GEMINI_PRO_VISION , textPrompt );
203
221
assertThat (output ).isNotEmpty ();
204
222
assertThat (output ).contains ("reasons?" );
205
223
}
@@ -208,17 +226,17 @@ public void testSafetySettings() throws Exception {
208
226
public void testTokenCount () throws Exception {
209
227
String textPrompt = "Why is the sky blue?" ;
210
228
211
- int tokenCount = GetTokenCount . getTokenCount ( PROJECT_ID , LOCATION , GEMINI_PRO_VISION ,
212
- textPrompt );
229
+ int tokenCount =
230
+ GetTokenCount . getTokenCount ( PROJECT_ID , LOCATION , GEMINI_PRO_VISION , textPrompt );
213
231
assertThat (tokenCount ).isEqualTo (6 );
214
232
}
215
233
216
234
@ Test
217
235
public void testFunctionCalling () throws Exception {
218
236
String textPrompt = "What's the weather in Paris?" ;
219
237
220
- String answer = FunctionCalling . whatsTheWeatherLike ( PROJECT_ID , LOCATION , GEMINI_PRO ,
221
- textPrompt );
238
+ String answer =
239
+ FunctionCalling . whatsTheWeatherLike ( PROJECT_ID , LOCATION , GEMINI_PRO , textPrompt );
222
240
assertThat (answer ).ignoringCase ().contains ("Paris" );
223
241
assertThat (answer ).ignoringCase ().contains ("sunny" );
224
242
}
0 commit comments