
spring ai introduction
介绍 Spring AI 的演示资料和代码示例。
Repository Info
About This Server
介绍 Spring AI 的演示资料和代码示例。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
Spring AI introduction
概要
Spring AIを紹介する発表資料とコード例です。
コード例
動作環境
- Java 21
- Node.js v22
- MCPの例で使用(発表資料のビルドでも使用)
- Maven 3
- Docker / Docker Compose
- 筆者はOrbStackを使用
- OpenAI API
- 使用しているモデルは次の通り
- テキスト生成:
gpt-4o-mini - 埋め込み:
text-embedding-3-small
- テキスト生成:
- 使用しているモデルは次の通り
事前準備
OpenAI APIのAPIキーを払い出してspring.ai.openai.api-keyプロパティへ設定します。
アプリケーションの起動
mvn spring-boot:run
動作確認
-
シンプルなテキスト生成
curl http://localhost:8080/hello -d query="100文字程度でSpring Bootを説明して。" -
Server-Sent Events版
curl http://localhost:8080/hello/stream -d query="100文字程度でSpring Bootを説明して。" -
システムプロンプトを指定したテキスト生成
curl http://localhost:8080/hello/with_system_prompt -d query="100文字程度でSpring Bootを説明して。" -
テキストと画像のマルチモーダル
curl http://localhost:8080/multimodal -d query="説明して。" -d image="https://avatars.githubusercontent.com/u/209262?v=4" -
構造化された出力
curl http://localhost:8080/structure -d query="ゼルダの伝説ブレスオブザワイルドの主人公とヒロイン、それから代表的なサブキャラクターを3人教えてください。" -s | jq -
関数呼び出し
curl http://localhost:8080/function -d query="うらがみさんのGitHubアカウントは?" -
会話
curl http://localhost:8080/chat/1 -d query="100文字程度でSpring Bootを説明して。"curl http://localhost:8080/chat/1 -d query="Hello Worldして。"curl http://localhost:8080/chat/1 -d query="データベースも使いたい。" -
RAG
curl http://localhost:8080/rag -d query="うらがみさんはどこ住み?"curl http://localhost:8080/rag -d query="うらがみさんの職業は?" -
MCPでPostgreSQLを操作
curl http://localhost:8080/mcppg/2 -d query="PostgreSQLへ接続してどんなテーブルがあるか教えて。"curl http://localhost:8080/mcppg/2 -d query="shopping_historyってどんなテーブル?"curl http://localhost:8080/mcppg/2 -d query="一番高い購入品は?"curl http://localhost:8080/mcppg/2 -d query="他のリコリス・リコイルに関する購入品を教えて。"
発表資料のビルド
まずMermaidのCLIでクラス図をビルドします。
ls src/docs/*.mmd | while read a; do npx -y @mermaid-js/mermaid-cli -i ${a} -o docs/$(basename ${a%.*}).svg; done
それからMarpのCLIで発表資料をビルドします。
npx @marp-team/marp-cli@latest --html --output docs/index.html --theme src/docs/theme.css src/docs/slide.md
このGitHubリポジトリではpushするとdocs/index.htmlへ書き出されてGitHub Pagesでホスティングされます。
- https://backpaper0.github.io/spring-ai-introduction/
なお発表資料のビルドに関して、執筆中はウォッチモードが便利です。
npx @marp-team/marp-cli@latest --html --output docs/index.html --theme src/docs/theme.css src/docs/slide.md --watch
ライセンス
発表資料(docs/配下にあるファイル)はCC BY 4.0、ソースコード(発表資料以外のファイル)はMITを適用します。
Quick Start
Clone the repository
git clone https://github.com/backpaper0/spring-ai-introductionInstall dependencies
cd spring-ai-introduction
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.