liveBook · Manning

Language model

As explained in Spring AI in Action

A large language model is a machine-learning model trained on extensive text data to understand and generate natural-language content.

A large language model (LLM) generates natural-language responses from prompts. Applications can send questions, documents, classifications, sentiment requests, or other instructions through provider APIs. section 1.1

Spring AI provides a consistent client abstraction over different providers and models. Its ChatClient builds a prompt, submits it, and returns generated content without requiring application code to manage the underlying HTTP exchange. section 1.1 section 1.1.2

A basic LLM integration follows this path:

  • Accept a user question through a REST endpoint. section 1.1.2
  • Place the question in a user message within a prompt. section 1.1.2
  • Call the model and wrap its returned text in an application response. section 1.1.2
  • Supply conversation history or tool results when the application needs context beyond one prompt. section 5.0 section 6.4

Question-answering service

A Spring service injects ChatClient.Builder, builds a ChatClient, submits question.question() through user(), calls the LLM, and returns the resulting content as an Answer. section 1.1.2

Listing 1.2 The Spring AI implementation of BoardGameService
package com.example.boardgamebuddy;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.stereotype.Service;

@Service
public class SpringAiBoardGameService implements BoardGameService {

  private final ChatClient chatClient;

  public SpringAiBoardGameService(ChatClient.Builder chatClientBuilder) {  #1
    this.chatClient = chatClientBuilder.build();  #2
  }

  @Override
  public Answer askQuestion(Question question) {
    var answerText = chatClient.prompt()
        .user(question.question())      #3
        .call()
        .content();
    return new Answer(answerText);
  }

}

Inspect the compact Spring service that turns a Java question record into an LLM-generated answer. section 1.1.2

How Spring AI in Action covers it

How deep it goes
Explains prompt submission, client abstraction, statelessness, memory, and tool interactions, but does not descend into model-training internals.
Examples
Demonstrates question answering, sentiment analysis, summarization, moderation, classification, image descriptions, conversation history, and tool results.
What it assumes
Assumes Spring Boot, Java records, dependency injection, REST controllers, provider access, and an API key configured for the selected service.
What you can do after
Apply it via Spring AI by building a REST-backed ChatClient service that submits prompts and returns generated content.
How it connects
Connects LLMs with prompts, Spring AI, REST APIs, conversational memory, advisors, and tools.

Also explained in

Compare how 67 books explain language model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.