|Introducing Spring AI|
|Written by Nikos Vaggalis|
|Monday, 23 October 2023|
At the recent SpringOne conference, the Spring team announced the Spring AI project. With it you can start integrating the OpenAI and Azure OpenAI services with your Java code to unleash the power of AI in your apps and leverage the power of LLMs from within your Spring code.
I say "start" because the project is in Alpha , current version is 0. 7. 0-SNAPSHO, as such susceptible to change in later versions.
The project draws inspiration from notable Python projects such as LangChain and LlamaIndex, but Spring AI is not a direct port of those projects. The project was founded with the belief that the next wave of Generative AI applications will not be for Python developers only, but will be ubiquitous across many programming languages.
In its simplest form, Spring AI allows for embedding generative AI to Spring applications by feeding it simple string prompts and have it do a generation against those prompts. However it can also go beyond simple string prompts. In more advanced scenarios you can also inject an "AI prompt" object;the advantage in that is that you hand an object in and you get an object out enriched with useful metadata.
Sure, you can call the OpenAI APIs by using a simple RestTemplate client, but Spring AI streamlines the process and
To utilize Spring AI, first make sure that you have an Open AI API Key or Azure Open AI service key, and set it
Then in your Maven project, add a reference to the Spring Milestone repository :
as well the according Spring Boot Starter depending on whether you are using Azure Open AI or Open AI.
Then you are good to go. A very simple use case of feeding it a string prompt follows, where you tell it to generate the filmography for a given actor:
There's many more examples and advanced usage in the "Spring AI Workshop" repository.
As said, still in alpha, but looking very promising.
or email your comment to: email@example.com