Bug: The function call plugin name printed is empty

未关闭
#13,516 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

  • #1 来自 @Whning0513 —— 已关闭,未合并
  • #13585 来自 @weiguangli-io —— 已关闭,未合并
  • #13672 来自 @aayushbaluni —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
csharp, ollama
领域
ai

调研方向

从 kernel.Plugins.AddFromObject(plugin1, pluginName: "time") 和 Microsoft.SemanticKernel.FunctionCallContent.GetFunctionCalls(response) 开始,复现所提供的 Ollama chat-completion 示例。当生成的 function call 暴露已注册的 plugin 名称 "time",并且 FunctionName 和 invocation 继续正常工作时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug triage

The function call plugin name printed is empty

Image

using Microsoft.SemanticKernel;

using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.Ollama;
using System.ComponentModel;
using System.Text;

#pragma warning disable SKEXP0110
public class TimePlugin
{
    [KernelFunction, Description("读取指定路径文件的内容,跨平台兼容~目录")]
    public string ReadFile(
        string filePath)
    {
        var ret = File.ReadAllText(filePath, Encoding.UTF8);
        return ret;

    }
    [KernelFunction, Description("This method is used to query the current system time and return it in the format yyyy-MM-dd HH:mm:ss")]
    public string QueryDateTime()
    {
        return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    }

    [KernelFunction, Description("The purpose of this method is to write the text content to the local computer's target path")]
    public void SaveFile(string filePath, string fileContent)
    {
        System.IO.File.WriteAllText(filePath, fileContent);
    }
}

class Program3
{
    public static async Task Main()
    {
        Console.OutputEncoding = System.Text.Encoding.UTF8;
        var builder = Kernel.CreateBuilder();
        var modelId = "qwen3:4b-instruct-2507-q4_K_M";
        var endpoint = new Uri("http://localhost:11434");

        builder.Services.AddOllamaChatCompletion(modelId, endpoint);

        var kernel = builder.Build();
        //KernelPlugin plugin = kernel.ImportPluginFromType<TimePlugin>();
        var plugin1 = new TimePlugin();
        kernel.Plugins.AddFromObject(plugin1, pluginName:"time");
        var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();

        string prompt = "读取一下d:\\test123.txt的内容";
        var executionSettings = new OllamaPromptExecutionSettings
        {
            FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false)
        };

        var t0 = DateTime.Now;
        var response = await chatCompletionService.GetChatMessageContentAsync(prompt, kernel: kernel, executionSettings: executionSettings);
        var functionCalls = Microsoft.SemanticKernel.FunctionCallContent.GetFunctionCalls(response).ToArray();
        foreach (var functionCall in functionCalls)
        {
            Console.WriteLine($" {functionCall.PluginName}, {functionCall.FunctionName}");//error  have no PluginName
            var functionResult = await functionCall.InvokeAsync(kernel);
            Console.WriteLine($"{functionResult.Result}");
       
        }
        Console.WriteLine($"工具调用数 {functionCalls.Length}");
        Console.Write(response.Content);
    }
}


主要语言
C#
星标
28.8k
派生
4.9k
平均合并
2 天 17 小时
30 天内合并 PR
48

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/semantic-kernel 的其他 Issue

查看 microsoft/semantic-kernel 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。