Skip to content

Commit

Permalink
add region tag for QuestionAnswer.java (#9335)
Browse files Browse the repository at this point in the history
* add region tag for QuestionAnswer.java

* fix: remove extraneous region tags; update comments

* fix: ensure that region tag includes the last }

---------

Co-authored-by: Jennifer Davis <sigje@google.com>
  • Loading branch information
LukeSchlangen and iennae committed May 23, 2024
1 parent 49bc3b9 commit dade187
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package vertexai.gemini;

// [START generativeaionvertexai_non_stream_text_basic]
import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
Expand All @@ -33,18 +34,20 @@ public static void main(String[] args) throws Exception {
System.out.println(output);
}

// Ask a simple question to the model.
// Asks a question to the specified Vertex AI Gemini model and returns the generated answer.
public static String simpleQuestion(String projectId, String location, String modelName)
throws Exception {
// Initialize client that will be used to send requests.
// This client only needs to be created once, and can be reused for multiple requests.
try (VertexAI vertexAI = new VertexAI(projectId, location)) {
String output;
GenerativeModel model = new GenerativeModel(modelName, vertexAI);

// Send the question to the model for processing.
GenerateContentResponse response = model.generateContent("Why is the sky blue?");
// Extract the generated text from the model's response.
output = ResponseHandler.getText(response);
return output;
}
}
}
// [END generativeaionvertexai_non_stream_text_basic]

0 comments on commit dade187

Please sign in to comment.