Share
Embed
Semantic Kernelのすすめ
.NET の 2 日間 2024 冬 (1 日目) ~3 コミュニティ合同イベント~
Semantic Kernelのすすめ
https://dotnet-communities.connpass.com/event/294588/
tomokusaba PRO
January 17, 2024
Transcript
22 slides
-
Semantic Kernelのすすめ 株式会社SAKURUG プロダクトDiv 草場 友光 .NET の 2 日間
~3 コミュニティ合同イベント~ -
自己紹介 • 普段は主にシステムをAzureにモダナ イズする仕事をしています。 • コミュニティ活動を通じて知識をアッ プデートしています。 • 2022/08-2024 Microsoft
MVP (Developer Technologies) • tomo_kusaba -
Semantic Kernelとは? • 既存のアプリケーションにLLMエージェントを簡単に追加できる オープンソースのSDK。 • 現在は、OpenAI、Azure OpenAI、Hugging Faceなどのモ デルで使用可能。
• C#、Python、Javaで使用可能。 • AIモデルと組み合わせ質問に答えプロセスを自動化するエージェ ントを構築できる。 -
なぜ、Semantic Kernelを選択するのか? • C#がメインの開発言語であるから • もはや、AIはクラウド・デスクトップ・モバイル・IoT・Web・MRな どすべての領域において不可欠の存在になりつつある。 • また、PlatformもWindows・Linux・Macすべてで動かす必要 がある。
• そのすべての領域での開発が可能なのがC#/.NET • エンタープライズ対応(監視・負荷分散・認証・認可・・・) -
Semantic Kernelの始め方 • まずは、Jupyter Notebooksから! • 次に、Semantic Kernelリポジトリ内にある多数のサンプル コードを参照 •
/dotnet/samples/kernelSyntaxExamples/ -
Jupyter Notebooks • 前提 • .NET7 SDK • Visual Studio
Code • “polyglot” VSCode Extension • OpenAIまたはAzure OpenAI ServiceのAPIキーを取得済み • Semantic Kernelリポジトリ (https://github.com/microsoft/semantic-kernel)を クローン • /dotnet/notebooks/に移動して配下のREADME.mdを参照してウエ から順番に実行 -
.NET Conf Japan2023「.NET + AI」 • https://info.microsoft.com/JA-ModApps-WBNR- FY24-12Dec-19-NET-Conf-2023-Recap-Japan- Latest-Learn-NET-SREVM25677_LP01- Registration---Form-in-Body.html
• https://zenn.dev/microsoft/articles/231219-dot- net-conf?redirected=1 -
プラグイン using Microsoft.SemanticKernel; using System.ComponentModel; namespace ConsoleApp17; public class ColorMode
{ public bool IsOn { get; set; } = false; [KernelFunction, Description("画面モードの状態を取得します。")] public string GetMode() { return IsOn ? "ON" : "OFF"; } [KernelFunction, Description("画面モードを切り替えます。")] public string ToggleMode() { IsOn = !IsOn; if (IsOn) { Console.ForegroundColor = ConsoleColor.DarkBlue; } else { Console.ResetColor(); } return GetMode(); } } • AIにコードを呼び出させたいときは説明文をつ けてその関数の使い方をAIに理解させる必要 があります。(Description) • AIは説明文を読み取り適切な関数を実行します。 (複数該当すれば複数実行することも!) -
呼び出し側 using Microsoft.SemanticKernel.Connectors.OpenAI; using Microsoft.SemanticKernel; using ConsoleApp17; Kernel kernel =
Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion( “デプロイ名”, “エンドポイント”, “APIキー”).Build(); kernel.Plugins.AddFromType<ColorMode>(); OpenAIPromptExecutionSettings? setting = new() { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions, }; while (true) { Console.Write("User > "); string input = Console.ReadLine()!; if (input == "exit") { break; } else { var result = await kernel.InvokePromptAsync(input, new(setting)); Console.WriteLine($"Assistant > {result}"); } } • Semantic KernelのKernelに先ほど作った プラグインと使用するモデルを渡します。 • ToolCallBehavior.AutoInvokeKernelF unctionで関数を説明文に従って自動的に呼 び出します。 使用するモデル 使用するプラグイン 自動的に関数を呼び 出す LLMと会話する -
続きは、.NETラボ2024年1月で • リアル会場:ピクシブ株式会社本社ビル 東京都渋谷区千駄ヶ谷4-23-5 JPR千駄ヶ谷ビル5階 • オンライン:Teams or YoutubeLive •
2024/1/27 13:00 Start お待ちしてます。 -
参考文献 • What is Semantic Kernel? https://learn.microsoft.com/ja-jp/semantic-kernel/overview/ • .NET Conf
2023 Recap Japan ~ 最新の.NETを学ぶ https://info.microsoft.com/JA-ModApps-WBNR-FY24-12Dec-19- NET-Conf-2023-Recap-Japan-Latest-Learn-NET- SREVM25677_LP01-Registration---Form-in-Body.html • .NET Conf Japan 2023「.NET + AI」補足記事 https://zenn.dev/microsoft/articles/231219-dot-net- conf?redirected=1 • semantic-kernel https://github.com/microsoft/semantic-kernel