Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Semantic Kernel を使って ChatGPT Plugins をアプリに組み込んでみよう
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kazuki
June 01, 2023
Technology
970
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Semantic Kernel を使って ChatGPT Plugins をアプリに組み込んでみよう
以下のイベントの発表資料です。
https://dotnet-communities.connpass.com/event/277869/
Kazuki
June 01, 2023
More Decks by Kazuki
See All by Kazuki
GitHub Copilot CLI の 個人的な好きなところ
okazuki
1
700
.NET ユーザーにやさしい GitHub Copilot の使い方
okazuki
0
640
Durable Task Extension for Microsoft Agent Framework はいいぞ
okazuki
2
450
正式リリースされた Semantic Kernel の Agent Framework 全部紹介!
okazuki
1
3.3k
.NET のUnified AI Building Blocks 入門...!
okazuki
0
380
Semantic Kernel の Agent 機能試してみた!
okazuki
1
1.1k
.NET Aspire を始めよう
okazuki
0
570
空のプロジェクトから始める Blazor
okazuki
1
760
.NET Aspire を使おう!
okazuki
0
450
Other Decks in Technology
See All in Technology
[RSJ26] NarrativeFlow: Flow-Based Vision-Language-Action Model Using Robot Velocity Fields
keio_smilab
PRO
0
130
Self Healing Rollouts: Automating Production Fixes with Agentic AI
kdubois
0
130
Claude Codeで開発以外の業務も爆速化しよう!
minorun365
PRO
12
9.5k
多摩川(.dev)ランニング入門 / Tamagawa.dev#3
fujiwara3
3
260
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
少人数データチームのDevin活用実践事例
runandy16
2
330
[RSJ26] Flow as Flow: Modeling Robot Velocity Fields as Probability Velocity Fields
keio_smilab
PRO
0
180
AIで開発は速くなったのに、なぜ現場は楽にならないのか 〜あなたの組織のボトルネックを突き止めるワークショップ〜
jacopen
1
200
人気商品が「ちゃんと買える」をつくる ー ECの負荷改善
ykagano
1
190
サーバー常駐型の 簡易障害調査AI エージェントを作ってみた話
masayoshi
1
520
PM領域でのAI Agentの活用
lycorptech_jp
PRO
0
230
Claude Codeの体系的な理解と知識のフック
oikon48
10
6.6k
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
260
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
Why Our Code Smells
bkeepers
PRO
340
58k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
500
Evolving SEO for Evolving Search Engines
ryanjones
0
280
Designing for Performance
lara
611
70k
The SEO Collaboration Effect
kristinabergwall1
1
550
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
We Are The Robots
honzajavorek
0
330
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
510
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
220
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Transcript
Semantic Kernel を使って ChatGPT plugins を 自分のアプリに組み込む方法 日本マイクロソフト シニア クラウドソリューション
アーキテクト エンジニアリング 大田 一希
自己紹介 日本マイクロソフト クラウド ソリューション アーキテクト エンジニアリング 大田 一希 (Kazuki Ota)
好きな技術:C# (20 年以上ほぼ一筋)、Azure PaaS 系サービス 苦手な言語:変数に型のない言語全般 SNS や Blog: Twitter: @okazuki (https://twitter.com/okazuki) GitHub: @runceel (https://github.com/runceel) Zenn: https://zenn.dev/okazuki Qiita: https://qiita.com/okazuki Hatena: https://blog.okazuki.jp 趣味:プログラミング、ゲーム(スマブラ: 2495時間, モンハン 1785時間、ティアキン 80時間) 好きな食べ物:🍖🍣 出身地:広島
もくじ Semantic Kernel の全体像をざっくり Semantic Kernel で ChatGPT
Plugins を呼ぶ方法 まとめ
Semantic Kernel の全体像をざっくり
Semantic Kernel とは • 全体概要については以下の動画の 2:19:00 あたりから始まる、ちょまどさん の「Azure OpenAI Service
と OpenAI (本家) + Semantic Kernel (LLM 用 SDK) 入門セッション (C#)」見てください。 • JAZUG: Global Azure 2023 [Room C+D] https://www.youtube.com/watch?v=LQhihic-PCg
Semantic Kernel とは LLM を使うアプリを作る際に必要な機能の詰め合わせ ◼ コア機能 (a.k.a 分類に困った機能) •
プロンプト生成のためのテンプレート エンジン • 変数の埋め込み、関数の呼び出し結果の埋め込みが可能 • プラグイン機能 (少し前まで Skill という名前でした) • 組み込みのプラグイン (MSGraph、Bing、OpenAPI、etc...) • 自作のプロンプトや C# の関数で作るプラグイン • 関数のオーケストレーション機能 ◼ Connectors • 外部サービスとの接続機能 ◼ Memories • データの永続化・検索機能 ◼ Planner • やりたいことを達成するための関数を自動で選んでくれる機能
Semantic Kernel 全体像 Kernel KernelBuilder Plugin 関数 関数 関数 関数
Plugin 関数 関数 関数 関数 自作Plugin 関数 関数 関数 関数 Memories Azure Cognitive Search、Sqlite、 Qdrant、PostgreSQL、Pinecone、 CosmosDB、etc 外部サービス 組み込みPlugin テキスト、ドキュメント、MS Graph API、 OpenAPI、ChatGPT Plugins、etc Connector 生成 データ保存先 使うものを登録 AI サービス テキスト、チャット、画像 Embedding Azure OpenAI Service OpenAI Others... Plugins 使用するAIサービス 使う 使う セットアップが終わった Kernel に対して 以下のようなことが出来る • 実行したい関数を選んで実行 • 実行したい複数の関数をつなげて実行 • AI サービスを直接呼び出す • Memory にデータを登録 • Memory からデータを取得
Semantic Kernel 全体像 Kernel KernelBuilder Plugin 関数 関数 関数 関数
Plugin 関数 関数 関数 関数 自作Plugin 関数 関数 関数 関数 Memory Azure Cognitive Search、Sqlite、 Qdrant、PostgreSQL、Pinecone、 CosmosDB、etc Planner Plan 外部サービス 組み込みPlugin テキスト、ドキュメント、MS Graph API、 OpenAPI、ChatGPT Plugins、etc Connector 生成 データ保存先 使うものを登録 Pluginの 関数一覧から 最適なものを AIを使って選択 AI サービス テキスト、チャット、画像 Embedding Azure OpenAI Service OpenAI Others... 作成 Plan 達成に 必要な関数を参照 Plugins 使用するAIサービス 使う 使う
Semantic Kernel 全体像 Kernel KernelBuilder Plugin 関数 関数 関数 関数
Plugin 関数 関数 関数 関数 自作Plugin 関数 関数 関数 関数 Memory Azure Cognitive Search、Sqlite、 Qdrant、PostgreSQL、Pinecone、 CosmosDB、etc Planner Plan 外部サービス 組み込みPlugin テキスト、ドキュメント、MS Graph API、 OpenAPI、ChatGPT Plugins、etc Connector 生成 データ保存先 使うものを登録 Pluginの 関数一覧から 最適なものを AIを使って選択 AI サービス テキスト、チャット、画像 Embedding Azure OpenAI Service OpenAI Others... 作成 Plan 達成に 必要な関数を参照 Plugins 使用するAIサービス 使う 使う 今日やりたいことが 組み込みである!
作ってみました 自作 TODO ChatGPT Plugins を組み込んだアプリのデモ runceel/ChatGPTPlugins-SemanticKernel (github.com)
頑張った点 ChatGPT Plugins を作る 参考: Introduction - OpenAI
API 作った Plugin の説明文を丁寧に記載する 正しい Plugin が選択されるようにプロンプトを組み立てる 正しい回答が返ってくるようにプロンプトを組み立てる
ポイント1: ChatGPT Plugins のマニフェスト Description に使い方をきちんと書かないとダメ openapi: 3.0.1 info: title:
TodoPlugin version: '1.0' servers: - url: https://localhost:7062 paths: /todos: get: tags: - TodoPlugin description: 全てのTODOを返します。 operationId: getTodos responses: '200': description: O { "schema_version": "v1", "name_for_human": "TODO リスト (no auth)", "name_for_model": "TODO list", "description_for_human": "TODOリストの表示と追加が出来ます。", "description_for_model": "TODOリストの管理が出来るプラグインです。TODOの一覧表示と追加が出来ます。", "auth": { "type": "none" }, "api": { "type": "openapi", "url": "https://localhost:7062/swagger/v1/swagger.yaml" }, "logo_url": "http://localhost:5003/logo.png", "contact_email": "
[email protected]
", "legal_info_url": "http://example.com/legal" } name_for_model と description_for_model を見て AI が使うプラグインを選ぶ
ポイント2: OpenAPI の定義 Description に使い方をきちんと書かないとダメ openapi: 3.0.1 info: title: TodoPlugin
version: '1.0' servers: - url: https://localhost:7062 paths: /todos: get: tags: - TodoPlugin description: 全てのTODOを返します。 operationId: getTodos responses: '200': description: O openapi: 3.0.1 info: title: TodoPlugin version: '1.0' servers: - url: https://localhost:7062 paths: /todos: get: tags: - TodoPlugin description: 全てのTODOを返します。 operationId: getTodos responses: '200': description: OK content: application/json: schema: type: array items: $ref: '#/components/schemas/TodoItem' post: tags: - TodoPlugin description: TODOを作成します。 operationId: createTodo requestBody: description: 'TODO Item. { "text": "Todo item title" }' content: application/json: schema: $ref: '#/components/schemas/TodoItem' required: true responses: '200': description: OK components: schemas: TodoItem: required: - Text type: object properties: text: minLength: 1 type: string description: TODO のタイトル additionalProperties: false description: TODO Item Description を見て AI が呼び出すべき 処理と渡すべきパラメーターを決める
Kernel への ChatGPT Plugins の読み込み IKernel の ImportChatGptPluginSkillFromUrlAsync メソッドで Kernel
に登録可能 await kernel.ImportChatGptPluginSkillFromUrlAsync( "Todos", new Uri("https://localhost:7062/.well-known/ai-plugin.json"), new HttpClient()); ai-plugins.json と OpenAPI の定義を読み込んで Semantic Kernel の Plugins として登録
プラグインを使ったチャットを成立させる処理の流れ 1. ユーザーの入力メッセージが何をしたいのか意図を確認する 2. 意図を元に適切なプラグインがあるか ActionPlanner を使って探す 3. 適切なプラグインがある場合は実行をする 4.
プラグインを実行した結果を含めたプロンプトを使って回答を生成
プラグインを使うためのフロー 1. ユーザーの入力メッセージが何をしたいのか意図を確認する プロンプト力が求められる…
プラグインを使うためのフロー 2. 意図を元に適切なプラグインがあるか ActionPlanner を使って探す 3. 適切なプラグインがある場合は実行をする 3 2
プラグインを使うためのフロー 4. プラグインを実行した結果を含めて回答を生成 プロンプト力が求められる… この部分で 2, 3 の処理を呼び出し結果を埋め込んでいる
苦労した点、もっと考えないといけない点 苦労した点 Planner が呼び出すべきプラグインを正しく選定出来るような文章を組むのが大変 Planner が内部で使用しているプロンプトが英語なので英語になりがち Planner
のプロンプトは差し替え可能なので日本語を使ってくれる Planner はプロンプト力があれば作れる もっと考えないといけない点 ChatGPT Plugins を呼ぶ場合はユーザーの明示的な同意が必要なようにするべき 呼ぶ前にユーザーがボタンを押すなどの明示的なアクションが必要 特に更新系の場合はユーザーの明示的なアクションがないと怖くて使えない Semantic Kernel の Copilot Chat というサンプル アプリは確認プロセスを実装しているので参考になる semantic-kernel/samples/apps/copilot-chat-app at main チャット履歴が長くなってくると思った通りに動かなくなりがち… 例: プラグインから取得した情報とチャットの履歴の間で矛盾が起きたら間違う可能性が上がる ユーザー認証はどうする?
まとめ 簡単な ChatGPT Plugins を作って Semantic Kernel で使ってみた
プロンプト力が無いと思った結果を出すのが大変… GPT 4 で試してみたい ある程度やることを絞らないと使い物になるものを作るのは難しそう… AI にユーザーがやりたいことを要約してもらってから処理をするのが良さそう 1 回のチャットのやり取りで N 回 AI に処理してもらう ユーザーが結構待たされることになるので UI での工夫が必要になりそう 「考え中…」の表示やストリーミングに対応して生成結果をパラパラと表示する Semantic Kernel の Copilot Chat サンプルが参考になる semantic-kernel/samples/apps/copilot-chat-app at main
参考: Copilot Chat の画面 a
© Copyright Microsoft Corporation. All rights reserved.