Skip to content

Commit

Permalink
feat: refactor text-only Gemini prompt (#9322)
Browse files Browse the repository at this point in the history
* feat: refactor text-only Gemini prompt

* fix line length errors

* update testcase

---------

Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
  • Loading branch information
irataxy and Sita04 authored May 11, 2024
1 parent c4586ca commit 7aad6b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
13 changes: 3 additions & 10 deletions vertexai/snippets/src/main/java/vertexai/gemini/TextInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,16 @@ public static void main(String[] args) throws IOException {
String projectId = "your-google-cloud-project-id";
String location = "us-central1";
String modelName = "gemini-1.0-pro-002";
// Does the returned sentiment score match the reviewer's movie rating?
String textPrompt =
"Give a score from 1 - 10 to suggest if the following movie review is"
+ " negative or positive (1 is most negative, 10 is most positive, 5 will be"
+ " neutral). Include an explanation.\n"
+ " The movie takes some time to build, but that is part of its beauty. By the"
+ " time you are hooked, this tale of friendship and hope is thrilling and"
+ " affecting, until the very last scene. You will find yourself rooting for"
+ " the hero every step of the way. This is the sharpest, most original"
+ " animated film I have seen in years. I would give it 8 out of 10 stars.";
"What's a good name for a flower shop that specializes in selling bouquets of"
+ " dried flowers?";

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

// Passes the provided text input to the Gemini model and returns the text-only response.
// For the specified textPrompt, the model returns a sentiment score for the given movie review.
// For the specified textPrompt, the model returns a list of possible store names.
public static String textInput(
String projectId, String location, String modelName, String textPrompt) throws IOException {
// Initialize client that will be used to send requests. This client only needs
Expand Down
13 changes: 3 additions & 10 deletions vertexai/snippets/src/test/java/vertexai/gemini/SnippetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,10 @@ public void testStreamingQuestions() throws Exception {
@Test
public void testTextInput() throws Exception {
String textPrompt =
"Give a score from 1 - 10 to suggest if the following movie review is"
+ " negative or positive (1 is most negative, 10 is most positive, 5 will be"
+ " neutral). Include an explanation.\n"
+ " The movie takes some time to build, but that is part of its beauty. By the"
+ " time you are hooked, this tale of friendship and hope is thrilling and"
+ " affecting, until the very last scene. You will find yourself rooting for"
+ " the hero every step of the way. This is the sharpest, most original"
+ " animated film I have seen in years. I would give it 8 out of 10 stars.";
"What's a good name for a flower shop that specializes in selling bouquets of"
+ " dried flowers?";
String output = TextInput.textInput(PROJECT_ID, LOCATION, GEMINI_PRO, textPrompt);
assertThat(output).isNotEmpty();
assertThat(output).contains("positive");
}

@Test
Expand Down Expand Up @@ -269,7 +262,7 @@ public void testVideoAudioInput() throws IOException {
public void testAllModalityInputs() throws IOException {
String output = MultimodalAllInput.multimodalAllInput(PROJECT_ID, LOCATION, GEMINI_PRO_1_5);

assertThat(output).ignoringCase().contains("00:49");
assertThat(output).ignoringCase().contains("0:49");
assertThat(output).ignoringCase().contains("moment");
}

Expand Down

0 comments on commit 7aad6b1

Please sign in to comment.