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


Fermyon's Spin WebAssembly Version 3.0 Released
26/11/2024

The open source developer tool for building, distributing, and running serverless WebAssembly applications reaches version 3.0. What's new?



Zitadel Announces Funding And Future Plans
21/11/2024

Zitadel has announced a major funding round that will be used to expand technical teams and fund further product development. The company is the creator of an open source project for cloud-native iden [ ... ]


More News

espbook

 

Comments




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