publicstaticvoidmain(String[] args)throws IOException { // TODO(developer): Replace these variables before running the sample. StringprojectId="your-google-cloud-project-id"; Stringlocation="asia-east2"; StringmodelName="gemini-1.5-flash";
chatDiscussion(projectId, location, modelName); }
// Ask interrelated questions in a row using a ChatSession object. publicstaticvoidchatDiscussion(String projectId, String location, String modelName) throws IOException { // 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 (VertexAIvertexAI=newVertexAI(projectId, location)) { GenerateContentResponse response;
GenerativeModelmodel=newGenerativeModel(modelName, vertexAI); // Create a chat session to be used for interactive conversation. ChatSessionchatSession=newChatSession(model);
response = chatSession.sendMessage("What are all the colors in a rainbow?"); System.out.println(ResponseHandler.getText(response));
response = chatSession.sendMessage("Why does it appear when it rains?"); System.out.println(ResponseHandler.getText(response)); System.out.println("Chat Ended."); } } }