Skip to content

Commit 7aad6b1

Browse files
irataxySita04
andauthored
feat: refactor text-only Gemini prompt (GoogleCloudPlatform#9322)
* feat: refactor text-only Gemini prompt * fix line length errors * update testcase --------- Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
1 parent c4586ca commit 7aad6b1

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

vertexai/snippets/src/main/java/vertexai/gemini/TextInput.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,16 @@ public static void main(String[] args) throws IOException {
3030
String projectId = "your-google-cloud-project-id";
3131
String location = "us-central1";
3232
String modelName = "gemini-1.0-pro-002";
33-
// Does the returned sentiment score match the reviewer's movie rating?
3433
String textPrompt =
35-
"Give a score from 1 - 10 to suggest if the following movie review is"
36-
+ " negative or positive (1 is most negative, 10 is most positive, 5 will be"
37-
+ " neutral). Include an explanation.\n"
38-
+ " The movie takes some time to build, but that is part of its beauty. By the"
39-
+ " time you are hooked, this tale of friendship and hope is thrilling and"
40-
+ " affecting, until the very last scene. You will find yourself rooting for"
41-
+ " the hero every step of the way. This is the sharpest, most original"
42-
+ " animated film I have seen in years. I would give it 8 out of 10 stars.";
34+
"What's a good name for a flower shop that specializes in selling bouquets of"
35+
+ " dried flowers?";
4336

4437
String output = textInput(projectId, location, modelName, textPrompt);
4538
System.out.println(output);
4639
}
4740

4841
// Passes the provided text input to the Gemini model and returns the text-only response.
49-
// For the specified textPrompt, the model returns a sentiment score for the given movie review.
42+
// For the specified textPrompt, the model returns a list of possible store names.
5043
public static String textInput(
5144
String projectId, String location, String modelName, String textPrompt) throws IOException {
5245
// Initialize client that will be used to send requests. This client only needs

vertexai/snippets/src/test/java/vertexai/gemini/SnippetsIT.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,10 @@ public void testStreamingQuestions() throws Exception {
199199
@Test
200200
public void testTextInput() throws Exception {
201201
String textPrompt =
202-
"Give a score from 1 - 10 to suggest if the following movie review is"
203-
+ " negative or positive (1 is most negative, 10 is most positive, 5 will be"
204-
+ " neutral). Include an explanation.\n"
205-
+ " The movie takes some time to build, but that is part of its beauty. By the"
206-
+ " time you are hooked, this tale of friendship and hope is thrilling and"
207-
+ " affecting, until the very last scene. You will find yourself rooting for"
208-
+ " the hero every step of the way. This is the sharpest, most original"
209-
+ " animated film I have seen in years. I would give it 8 out of 10 stars.";
202+
"What's a good name for a flower shop that specializes in selling bouquets of"
203+
+ " dried flowers?";
210204
String output = TextInput.textInput(PROJECT_ID, LOCATION, GEMINI_PRO, textPrompt);
211205
assertThat(output).isNotEmpty();
212-
assertThat(output).contains("positive");
213206
}
214207

215208
@Test
@@ -269,7 +262,7 @@ public void testVideoAudioInput() throws IOException {
269262
public void testAllModalityInputs() throws IOException {
270263
String output = MultimodalAllInput.multimodalAllInput(PROJECT_ID, LOCATION, GEMINI_PRO_1_5);
271264

272-
assertThat(output).ignoringCase().contains("00:49");
265+
assertThat(output).ignoringCase().contains("0:49");
273266
assertThat(output).ignoringCase().contains("moment");
274267
}
275268

0 commit comments

Comments
 (0)