0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Semantic KernelでGemini 2.5 Flashを試してみる

Posted at

こんにちは。

テックリードのTerukiです。

Semantic Kernelでは、ずっとGPT4.1しか試していなかったのですがOpenAI以外のモデルもプレビューではあるものの、使わせることはできるので試してみます。

OpenAIのモデルを使ったものは以前書いた記事にあるのでもし良ければこちらも参照ください。

実装

まずはNuGetパッケージを追加します。

Microsoft.SemanticKernel.Connectors.Google

プレビュー版なのでVisual Studioではプレリリースを含めて検索しないと出てきません。
image.png

前回のコードをベースに変更してみます。

var kernelBuilder = Kernel.CreateBuilder()
    .AddGoogleAIGeminiChatCompletion(Configuration["Google:Gemini:ModelId"]!,
        Configuration["Google:Gemini:ApiKey"]!);
    
var kernel = kernelBuilder.Build();

// INotionServiceを解決するためにアプリのIServiceProviderを指定しておく
kernel.Plugins.AddFromType<NotionPlugin>(null, ServiceProvider);

var agent = new ChatCompletionAgent {
    Name = "Agent",
    Instructions = """
        質問への応答や回答を考えて返答してください。
        FAQNotionに保存されています。
        """,
    InstructionsRole = AuthorRole.Assistant,
    Kernel = kernel,
    Arguments = new(new GeminiPromptExecutionSettings {
        FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(),
        ToolCallBehavior = GeminiToolCallBehavior.AutoInvokeKernelFunctions, // これがないとKernelFunctionが呼ばれない
    }),
};

APIキーはこちらから取得できます。

モデルIDは今回は「gemini-2.5-flash-preview-05-20」を指定してみました。

GPTとは違ってToolCallBehaviorを指定しないとKernelFunctionが一切呼ばれなかったのに少しハマりました。


結構簡単に差し替えることができました。

モデルの精度がどうかはまだ確認できていないですが、すごいモデルが登場した時に簡単に乗り換えられるのは非常に良いですね。

もしくはモデルを切り替える機能を搭載しても面白そうです。

社内AIエージェント開発をひそひそと進めていますが、面白そうな機能があれば組み込んでいこうと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?