in sessions/fall24/books-genai-vertex-springai/src/main/java/services/ai/VertexAIClient.java [120:144]
public String promptModelWithFunctionCalls(Message systemMessage,
Message userMessage,
String functionName,
String model) {
long start = System.currentTimeMillis();
ChatClient client = ChatClient.create(chatClient);
ChatResponse chatResponse = client.prompt()
.advisors(new LoggingAdvisor(),
new GuardrailsAdvisor())
.messages(List.of(systemMessage, userMessage))
.functions(functionName)
.options(VertexAiGeminiChatOptions.builder()
.withTemperature(0.4)
.withModel(model)
.build())
.call()
.chatResponse();
logger.info("Elapsed time ({}, with SpringAI): {} ms", model, (System.currentTimeMillis() - start));
String output = chatResponse.getResult().getOutput().getContent();
logger.info("Chat Model output with Function Call: {}", output);
return output;
}