Inspired by LangChain4j and LlamaIndex, Spring AI project aims to streamline the development and integration of AI capabilities into existing or new Spring applications. By utilizing the well-known coding patterns in other modules, such as JdbcTemplate or RestClient, the integration hides all sorts of complexities in dealing with LLMs from all supported vendors such as OpenAI, Microsoft, Amazon, Google, and Hugging Face.
Spring AI provides high-level interfaces (such as ChatModel, ImageModel, VectorStore etc.) and implements these interfaces into different modules whereas each module provides integration points to a certain LLM. We can import these modules as and when required.
For example, to work with OpenAI models, we can import the dependency:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
And use the autoconfigured beans (ChatClient, ChatModel, etc) to interact with LLMs:
@RestController
public class OpenAiChatController {
private final ChatClient chatClient;
@Autowired
public OpenAiChatController(ChatClient chatClient) {
this.chatClient = chatClient;
}
@GetMapping("/joke-service/simple")
public Map<String, String> tellSimpleJoke() {
return Map.of("generation", chatClient.call("Tell me a joke"));
}
}
The following tutorials discuss each sub-topic/feature in detail with examples.
1. Getting Started
- Getting Started with Spring AI
- Spring AI PromptTemplate
- Spring AI Structured Output Converters
- Ollama Local Setup and Spring AI Integration
2. Models
- Spring AI EmbeddingModel
- Spring AI ImageModel (Text-to-Image)
- Spring AI SpeechModel (Text-to-Speech)
- Spring AI AudioTranscriptionModel (Speech-to-text)
Comments