Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Bug: 在调用GetStreamingChatMessageContentsAsync方法时如果传入了executionSettings的参数时流式输出就会失效 #10292

Open
landonzeng opened this issue Jan 24, 2025 · 0 comments
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code triage

Comments

@landonzeng
Copy link

Describe the bug
当我执行以下代码时:

 var endpoint = new Uri("http://localhost:11434/v1/");
 var modelId = "qwen2.5:14b";

var httpClient = new HttpClient();
var builder = Kernel.CreateBuilder()
    .AddOpenAIChatCompletion(modelId: modelId!, apiKey: null, endpoint: endpoint, httpClient: httpClient);
var kernel = builder.Build();

var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();

var openAIPromptExecutionSettings = new OpenAIPromptExecutionSettings()
{
    ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};
KernelArguments kernelArgs = new(openAIPromptExecutionSettings);
var history = new ChatHistory();
string? userInput;
do
{
    Console.Write("User > ");
    userInput = Console.ReadLine();
    history.AddUserMessage(userInput!);

    var result = chatCompletionService.GetStreamingChatMessageContentsAsync(history, executionSettings: openAIPromptExecutionSettings, kernel: kernel);
    string fullMessage = "";

    Console.Write("Assistant > ");
    await foreach (var content in result)
    {
        Console.Write(content.Content);
        fullMessage += content.Content;
    }
    Console.WriteLine();

    history.AddAssistantMessage(fullMessage);
} while (userInput is not null);

如果chatCompletionService.GetStreamingChatMessageContentsAsync方法传入了executionSettings的参数时流式输出就会失效,如果不传入的话,流式输出是正确的,例如:

chatCompletionService.GetStreamingChatMessageContentsAsync(history,  kernel: kernel);

修改成这样,那么控制台将以流式输出AI回答的内容

Expected behavior
GetStreamingChatMessageContentsAsync能正确按流式输出内容

Platform

  • Language: C#
  • Source: 1.34.0
  • AI model: qwen2.5:14b
  • IDE: Visual Studio
  • OS: Windows
@landonzeng landonzeng added the bug Something isn't working label Jan 24, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Jan 24, 2025
@github-actions github-actions bot changed the title Bug: 在调用GetStreamingChatMessageContentsAsync方法时如果传入了executionSettings的参数时流式输出就会失效 .Net: Bug: 在调用GetStreamingChatMessageContentsAsync方法时如果传入了executionSettings的参数时流式输出就会失效 Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code triage
Projects
None yet
Development

No branches or pull requests

2 participants