liveBook · Manning

Chapter 11: Applying generative AI patterns

What you will learn in chapter 11 of Spring AI in Action

This introduction explains that Spring AI’s ChatClient can do more than answer questions, with the task shaped largely by the prompt.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains that Spring AI’s ChatClient can do more than answer questions, with the task shaped largely by the prompt.

Key terms: ChatClient, Q&A tasks, prompt

11.1 Summarizing content

Shows how Board Game Buddy turns uploaded board game rules into quick-start summaries with Spring AI, and explains practical model constraints for summarizing long documents.

Key terms: ChatClient, system prompt message, user message, summarizeRules(), Answer, MultipartFile, rulesDocument, TikaDocumentReader, BoardGameService, context window

11.2 Translating messages

This section explains why static translation mappings do not suit unpredictable LLM responses and introduces asking an LLM to translate text instead.

Key terms: internationalization, mappings, nondeterministic response, LLMs, translating text, summarization

11.2.1 Building a simple translator

Shows how to build a Spring Boot translation API that uses a prompt template and ChatClient to translate text between languages.

Key terms: prompt template, translator, source language, target language, placeholder parameters, Translation record, @RestController, HTTP POST, ChatClient, TranslatorController

11.2.2 Translating game rule answers

Shows how Board Game Buddy can answer game-rule questions in a requested language in one model request instead of translating the answer in a second request.

Key terms: target language, additional API request, latency, token usage, translation mappings, Question record, default language, English, askQuestion(), targetLanguage

11.3 Analyzing sentiment

This section shows how to use a prompt and Spring AI’s ChatClient to score the sentiment of user text and return an explanation.

Key terms: sentiment analysis, user sentiment, natural language experiences, sentiment score, prompt template, neutral sentiment, ChatClient, system message, user message, SentimentAnalysis

11.4 Summary

Concepts explained in this chapter

← Chapter 10: Safeguarding generative AI Chapter 12: Employing agents →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.