SK还提供了类似函数调用的方式,可以在prompt中实现多种技能的组合,而且并不限制是Semantic Function 还是 Native Function。 {varbuilder = Kernel.CreateBuilder().AddOpenAIChatCompletion(modelId: Config.OpenAiChatModel, Config.OpenAiKey);var
二、使用Semantic Kernel框架和C#.NET 实现Function Calling 在Semantic Kernel框架中,大模型可以通过Function Calling(函数调用)来执行插件(Plugins)中的功能。以下示例,展示如何在 Semantic Kernel 中让大模型调用一个插件函数(Function Call)。 设计一个计算插件,包含一个add_numbers方法,让大模型可以调用它来执行加法...
kernel.CreateFunctionFromMethod(GetWeatherForCity,"GetWeatherForCity","获取指定城市的天气") }); 手动调用 function calling 根据上面的描述 手动处理function calling的关键实际上是ToolCallBehavior.EnableKernelFunctions参数。 OpenAIPromptExecutionSettingssettings=newOpenAIPromptExecutionSettings { Temperature=0, Tool...
// Get kernelKernel kernel = GetKernel();// Enable Automatic Function CallingOpenAIPromptExecutionSettings executionSettings =new() { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions };// Generate and execute a planFunctionResult result =awaitkernel.InvokePromptAsync("Check current UTC time...
如果想在聊天中用到Function Calling怎么做呢? awaitCall2; asyncTaskCall2(){Console.WriteLine("---Call2 开始---");varsettings =newOpenAIPromptExecutionSettings { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions };varchat = kernel.GetRequiredService<IChatCompletionService>;varchatHistory ...
Semantic Kernel:Function Calling,在上一篇的Function中,我们用混合方式来分别调用语义Function和本地Function,但调用顺序是开发者组织的。其实SK是可以自组织的,下面定义了一个本地Function——GetChineseDay,用ImportPluginFromFunctions的方式添加到SK的插件库里
function_choice_behavior: type: auto """; KernelFunction promptFunction = KernelFunctionYaml.FromPromptYaml(promptTemplateConfig); Kernel kernel = builder.Build();awaitkernel.InvokeAsync(promptFunction); Next steps Now that you know about the new function-calling capabilities, you can get more detai...
Semantic Kernel 本质上是在利用函数调用(function calling)功能让 LLM 进行规划(planning)并调用 API...
下面的教程我们将使用Microsoft.SemanticKernel开发,然后依赖ModelContextProtocol官方的包,然后我们需要用到Microsoft.Extensions.Hosting 开始我们的代码开发 扩展SemanticKernel的MCPClient 由于SemnaticKernel默认是不能直接使用MCP的功能,那么我们需要先对它进行扩展 ...
插件是Semantic Kernel的核心组件。通过插件,你可以将现有的API封装成一个集合,供AI调用,从而赋予AI原本无法执行的操作能力。 在背后,Semantic Kernel利用了最新大型语言模型(LLM)中的原生功能——Function Calling,来帮助LLM进行规划并调用API。通过函数调用,LLM可以请求特定函数的执行。Semantic Kernel会将这个请求传递给...