Skip to content
项目

danvega/spring-ai-workshop

在 GitHub 查看

关于

Spring AI Workshop

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
-1
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Spring AI Workshop

Hands-on demos for building AI applications with Spring Boot and Spring AI. Each package under dev.danvega.workshop shows one feature: chat, prompts, structured output, memory, advisors, tools, RAG, guardrails, multimodal, evals, and model routing. Every demo is a small REST endpoint you can hit from a browser, curl, or the included workshop.http file.

Tested with Java 26, Spring Boot 4.1.2, and Spring AI 2.1.0-M1. Chat goes through OpenAI's Responses API with gpt-6-astra as the default model, configured in application.yml.

What you need

  • JDK 26
  • An OpenAI API key
  • A TypeSafe API key for the model router demo
export OPENAI_API_KEY='your-openai-key'
export TYPESAFE_API_KEY='your-typesafe-key'

The router demo uses the Jev Spring Boot starter, a local snapshot. Install it once:

cd ../jev-spring-boot-starter && ./mvnw install

Run it

./mvnw spring-boot:run

The app starts on http://localhost:8080.

Try it

Open workshop.http in IntelliJ or VS Code and run requests from there, or start with:

curl "localhost:8080/?message=Tell me a dad joke about dogs"
curl "localhost:8080/vacation/structured"
curl "localhost:8080/router?message=What is the capital of Ohio"

The demos

Package Shows Endpoints
chat ChatClient basics, .content() vs .chatResponse() /, /jokes-by-topic, /jokes-with-response
chatmodel ChatModel API, usage metadata, and n=3 generations on a self-built Completions model /chat-model/fact, /chat-model/taglines
prompt Prompt templates loaded from resources /posts/new
output Structured output into Java records, plus two Spring AI 2 options: provider structured output and schema validation with retries /vacation/structured, /vacation/unstructured, POST /output/ticket/provider, POST /output/ticket/validated
talks Lab 2: a prompt template, a system message, and structured output together in one endpoint. Lab 3: a talk coach with chat memory, SimpleLoggerAdvisor, and a word count @Tool POST /talks/review, POST /talks/coach
options Configuring model options (README) /options
memory Chat memory: short-term (the last messages of one conversation) and long-term (Markdown notes the model writes with AutoMemoryTools) (README) /memory, /memory/short-term/{id}, /memory/long-term/{userId}
advisor The built-in SimpleLoggerAdvisor, then custom advisors, one per superpower: observe (token counting), transform (PII masking), short-circuit (on-topic guard) /advisor/logging, /advisor, /pii-masking, /support
async Streaming responses /stream
multimodal Image to text, image generation, text to speech /image-to-text, /generate-image, /speak
byod Bring your own data by stuffing the prompt /models, /models/stuff-the-prompt
rag Retrieval augmented generation over data/models.json /rag/models
guards Guardrails through system prompts: input validation and fact checking /input-validation, /fact-checking
tools Tool calling: date and time, task actions, weather (README) /tools, /tasks, /weather/alerts
router Jev picks the cheapest capable model per prompt (README) /router
evals Testing AI output with evaluators (README) test sources
observability Metrics for AI calls (README) actuator

There is also a minimal SimpleChatController in the root package: /chat returns .content() and /chat-response returns the full .chatResponse() with metadata. The agents and multiplellms packages hold notes in their READMEs.

Testing

./mvnw test

The eval tests call the live OpenAI API, so they need OPENAI_API_KEY and can flake on rare occasions.

Good to know

  • This is demo code for a workshop, not production code.
  • Configuration lives in application.yml. The default chat model is set there, and spring.ai.openai.chat.api: responses switches Spring AI to the Responses API.
  • Spring AI 2.1.0-M1 is a milestone. Per-request options use OpenAiResponsesChatOptions; the old OpenAiChatOptions is silently ignored by the Responses model. The pom pins jsonschema-module-jackson to 5.0.0 to fix a mixed-version resolution in the milestone.
  • Reasoning models like gpt-6-astra reject temperature and support reasoning-effort values low through max.
  • Slides for the talk are in the slides folder.

探索相关项目

加载中…