How to convert Kernel with Plugins to IChatClient with AIFunction / Tools ? #10815
-
I'm trying to extract an IChatClient from a Kernel that has Plugins. I've gotten this far: serviceCollection
.AddKernel()
.AddOpenAIChatCompletion(apiKey: chatConfig!.OpenAiApiKey, modelId: "gpt-4o-mini")
.Plugins
.AddFromType<UtilitiesPlugin>()
.AddFromType<TreasuryPlugin>();
serviceCollection.AddChatClient(serviceProvider =>
{
Kernel kernel = serviceProvider.GetRequiredService<Kernel>();
IChatCompletionService completionService = kernel.GetRequiredService<IChatCompletionService>();
IChatClient client = completionService.AsChatClient();
ChatClientBuilder builder = new ChatClientBuilder(client)
.UseFunctionInvocation()
.ConfigureOptions(options =>
{
IEnumerable<AIFunction> aiFunctions =
kernel.Plugins.SelectMany(kp => kp.AsAIFunctions());
options.Tools = [..aiFunctions];
options.ToolMode = ChatToolMode.Auto;
});
return builder.Build();
});
public sealed class UtilitiesPlugin
{
[KernelFunction("get_current_utc_time")]
public string GetCurrentUtcTime()
{
return DateTime.UtcNow.ToString("R");
}
} When sending a message I get this error:
I guess it's from this dash Any suggestions? Is plugin use from IChatClient not supported? |
Beta Was this translation helpful? Give feedback.
Answered by
stephentoub
Mar 5, 2025
Replies: 1 comment 3 replies
-
It should definitely work. Looks like a bug to be fixed asap. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
cdock1029
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should definitely work. Looks like a bug to be fixed asap.