Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor text-only Gemini prompt #9322

Merged
merged 4 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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