in ai-patterns/langchain4j-function-calling/src/main/java/services/gemini/Langchain4JFunctionCallingApplication.java [135:165]
private void functionCallGeminiWithREST(String userMessage) {
long start = System.currentTimeMillis();
VertexAI vertexAi = new VertexAI.Builder().setProjectId(project).setLocation(location).setTransport(Transport.REST).build();
GenerativeModel generativeModel = new GenerativeModel(chatModel, vertexAi);
GenerationConfig generationConfig = GenerationConfig.newBuilder().setTemperature(0.2f).setMaxOutputTokens(1000).build();
// ChatLanguageModel model = new VertexAiGeminiChatModel(generativeModel, generationConfig, 1);
ChatLanguageModel model = VertexAiGeminiChatModel. builder()
.project(project)
.location(location)
.modelName(chatModel)
.temperature(0.2f)
.maxOutputTokens(1000)
.logRequests(true)
.logResponses(true)
.build();
FunctionCallingService service = new FunctionCallingService();
Assistant assistant = AiServices.builder(Assistant.class)
.chatLanguageModel(model)
.chatMemory(MessageWindowChatMemory.withMaxMessages(10))
.tools(service)
.build();
System.out.println("User message: " + userMessage);
System.out.println(assistant.chat(userMessage));
System.out.println("VertexAI Gemini call using REST took " + (System.currentTimeMillis() - start) + " ms");
}