in sessions/fall24/spring-ai-quotes-llm-in-gke/src/main/java/com/example/quotes/domain/QuoteLLMInGKEService.java [30:62]
public Quote findRandomQuote() {
SystemMessage systemMessage = new SystemMessage("""
You are a helpful AI assistant.
You are an AI assistant that helps people find information.
""");
UserMessage userMessage = new UserMessage("""
Answer succinctly;
please provide a quote from a random book, including book, quote and author;
do not repeat quotes from the same book;
return the answer wrapped in triple backquotes ```json```strictly in JSON format
return only 3 values, the book, the quote and the author, strictly in JSON format, wrapped in tripe backquotes ```json``` while eliminating every other text
""");
ChatResponse chatResponse = chatClient.call(new Prompt(List.of(systemMessage, userMessage),
OpenAiChatOptions.builder()
.temperature(0.4)
.build())
);
Generation generation = chatResponse.getResult();
String input = generation.getOutput().getText();
System.out.printf("\nLLM Model in GKE provided response: \n%s\n", input);
// clear extraneous characters from LLM response
Quote sanitizedQuote = Quote.parseQuoteFromJson(input);
// validate against another LLM for veracity
evalService.evaluate(sanitizedQuote.getQuote(), sanitizedQuote.getBook());
return sanitizedQuote;
}