in ai-patterns/spring-ai-quotes/src/main/java/services/gemini/QuotesTestApplication.java [38:81]
ApplicationRunner applicationRunner(
VertexAiGeminiChatModel geminiChatModel,
AnthropicChatModel anthropicChatModel) {
return args -> {
String book = "The Jungle Book";
// sample prompt
// String prompt = String.format("You are an experienced literary critic. Please write a summary of the book %s", book);
String prompt = String.format("You are an experienced literary critic. Please extract a famous quote from the book %s", book);
// test against Gemini (Flash|Pro) 1.5
long start = System.currentTimeMillis();
System.out.println("VERTEX_AI_GEMINI: " + geminiChatModel
.call(
new Prompt(prompt,
VertexAiGeminiChatOptions.builder()
.withTemperature(0.2).build())
).getResult().getOutput().getContent());
System.out.println("VertexAI Gemini call took " + (System.currentTimeMillis() - start) + " ms");
// test against Anthropic SONNET (3.5)
start = System.currentTimeMillis();
System.out.println("ANTHROPIC_SONNET: " + anthropicChatModel
.call(
new Prompt(prompt,
AnthropicChatOptions.builder()
.withTemperature(0.2).build())
).getResult().getOutput().getContent());
System.out.println("Anthropic SONNET call took " + (System.currentTimeMillis() - start) + " ms");
String baseURL = String.format("https://us-east5-aiplatform.googleapis.com/v1/projects/genai-playground/locations/us-east5/publishers/anthropic/models/claude-3-5-sonnet-20240620");
var anthropicApi = new AnthropicApi(baseURL, getOauth2Token(baseURL));
var chatModel = new AnthropicChatModel(anthropicApi,
AnthropicChatOptions.builder()
.withModel("claude-3-5-sonnet-20240620")
.withTemperature(0.4)
.withMaxTokens(200)
.build());
ChatResponse response = chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
};
}