**Last Update**: 14.01.2024
***
> [!INFO]
> Note that, the Spring AI project is still in beta, not all features are finished and documented. Please follow the progress with the issues on the [GitHub repository](https://github.com/spring-projects-experimental/spring-ai).
### What is Spring AI
- The Spring AI project aims to streamline the development of applications that incorporate artificial intelligence functionality without unnecessary complexity.
### What is Spring AI goal?
- The idea behind the project was to provide developers with an abstract interface, the foundation for enabling [[Generative AI | generative AI]] APIs into *Spring Boot* applications as an isolated component.
### Spring AI abstract interface
- The _[AiClient](https://markpollack.github.io/spring-ai-0.7.1/api/aiclient.html),_ which has two basic implementations **—** [OpenAI](https://platform.openai.com/docs/overview) and [Azure OpenAI](https://azure.microsoft.com/en-us/products/ai-services/openai-service).
- The `generate` method with a `String` parameter simplifies initial use, avoiding the complexities of the more sophisticated `Prompt` and `AiResponse` classes.
- The [Prompt](https://markpollack.github.io/spring-ai-0.7.1/api/aiclient.html#_prompt) class encapsulates a list of `Message` objects, along with utility methods.
- The [Message](llack.github.io/spring-ai-0.7.1/api/aiclient.html#_message) interface encapsulates a textual message, a collection of attributes as a `Map`, and a categorization known as `MessageType`.
- It has various implementations that correspond to the categories of messages that an AI model can process.
- The `UserMessage` implementation acts as a standard category, typically representing user-generated inquiries or instructions
- The [AiResponse](https://markpollack.github.io/spring-ai-0.7.1/api/aiclient.html#_airesponse) class holds the AI Model’s output, with each `Generation` instance containing one of potentially multiple outputs from a single prompt.
- It also carries a map of key-value pairs, providing metadata about the AI Model’s response.
- The [Generation](https://markpollack.github.io/spring-ai-0.7.1/api/aiclient.html#_generation) class contains a `String` that represents the output text and a map that provides metadata about this response.
```java
@RestController
public class SimpleAiController {
private final AiClient aiClient;
@Autowired
public SimpleAiController(AiClient aiClient) {
this.aiClient = aiClient;
}
@GetMapping("/ai/generate")
public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
return Map.of("generation", aiClient.generate(message));
}
}
```
***
**References**:
- [Introduction to Spring AI](https://www.baeldung.com/spring-ai?__s=qdepkinxo8evqxc8kpbz)
- [Spring AI Reference](https://docs.spring.io/spring-ai/reference/)