2

What is Spring AI, and how to use it: A beginner's guide

 6 months ago
source link: https://www.pluralsight.com/resources/blog/software-development/what-is-spring-ai
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Applications everywhere are investigating how artificial intelligence can enhance their application. In this article, you’ll learn about a new Spring project that affords Java developers a convenient API abstraction for working with large-language models (LLMs) like ChatGPT. By the end, we’ll have a simple program that can answer questions about the Swiftie Bowl based on information retrieved from Wikipedia.

The Origin of Spring AI

Spring AI --- a Spring project, not quite GA as of this writing --- represents a groundbreaking initiative aimed at simplifying the integration of artificial intelligence features into applications across the JVM family of languages. It was introduced officially to the world in the fall of 2023 at SpringOne by Mark Pollack, its creator. In true Spring fashion, the project introduces a common Spring-like pane of glass across the disparate LLM APIs cropping up, among them OpenAI and Azure OpenAI.

While it is in the experimental phase, it’s not considered production-ready; however, it is certainly worth a look so you can get a jump on learning the kinds of problems AI can help you solve.

AI Concepts

Before creating our sample application, let’s go over a few basic terms:

  • Models: AI models are algorithms that mimic human cognitive functions to generate predictions, text, images, or other outputs from large datasets.

  • Prompts: Prompts are language-based inputs that guide AI models to produce specific outputs; often this requires skillful crafting (sometimes called Prompt Engineering) to be effective.

  • Prompt Templates: These templates use text-based engines to create prompts by substituting parts of the request with user-specific values.

  • Embeddings: Embeddings transform text into numerical vectors, allowing AI models to process and understand language.

  • Tokens: Tokens are the basic units of language processed by AI models, with usage directly linked to the cost of AI services.

We’ll refer to each of these concepts while creating the application.

Initializing a Spring AI Application

Spring AI is so new that it isn’t part of the Spring Intializr. While we could use https://start.spring.io to create a skeleton and then manually add the starters afterward, I’m going to use the Spring CLI which already has Spring AI support.

Once you’ve installed the CLI, navigate to a directory where you want the application to be, start the Spring Shell, and run:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK