· java,spring,AI,video

In this talk, Craig Walls explains how to use the Spring AI starter to interact with AI (like Open AI) from Spring Boot. Below is a sample of the code to dial with Open AI.

Simplest way:

import org.springframework.ai.chat.ChatClient;

//...

 private final ChatClient chatClient;

 public JokeController(ChatClient chatClient) {
        this.chatClient = chatClient;
}

@GetMapping("/joke")
public JokeResponse tellJoke(@RequestParam("subject") String subject) {
    return chatClient.call("Tell me a joke about "+ subject);
}