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
takes care of all plumbing. In other words it "make your @Beans intelligent!". As Spring has it, to make the transition even easier, there's Spring Boot Starters available to help set up essential dependencies and classes, as well as a Spring CLI project which allows you to get started quickly using the command line.

To utilize Spring AI, first make sure that you have an Open AI API Key or Azure Open AI service key, and set it
in your application. properties, pointing spring. ai. openai to that API key.

Then in your Maven project, add a reference to the Spring Milestone repository :

<repositories>
  <repository>
      <id>spring-snapshots</id>
     <name>Spring Snapshots</name>
    <url>https://repo.spring.io/snapshot</url>
     <releases>
         <enabled>false</enabled>
     </releases>
  </repository>
</repositories>

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.

More Information

Spring AI

Spring AI Workshop

Related Articles

Learn With The Spring Academy

Azure Workshop with Quarkus, Spring Boot and Micronaut

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Avi Wigderson Gains Turing Award
16/04/2024

Israeli mathematician and computer scientist, Avi Wigderson, is the recipient of the 2023 ACM A.M Turing Award which carries a $1 million prize with financial support from Google.



Quantum Computing Prize Awarded
05/04/2024

John Preskill, Professor of Theoretical Physics at the California Institute of Technology, is the eighth recipient of the John Stewart Bell Prize for Research on Fundamental Issues in Quantu [ ... ]


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info