semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Bug: Exception occurs at the end of foreach when executing GetStreamingChatMessageContentsAsync

Open aeras3637 opened this issue 2 years ago • 3 comments

Describe the bug Exception occurs at the end of foreach when executing GetStreamingChatMessageContentsAsync.

To Reproduce

        static async Task Main(string[] args)
        {
            string endPoint = @"https://oai.openai.azure.com/";
            string key = "xxxxx";

            var openAIClient = new AzureOpenAIClient(new Uri(endPoint), new AzureKeyCredential(key));
            var builder = Kernel.CreateBuilder();
            builder.AddAzureOpenAIChatCompletion("gpt-4o", openAIClient);
            var kernel = builder.Build();
            ChatHistory history = [];
            history.AddUserMessage("What day is it today?");

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

            while (true)
            {
                var result = chatCompletionService.GetStreamingChatMessageContentsAsync(history, kernel: kernel);

                await foreach (var content in result)
                {
                    Console.Write(content.Content);
                }
            }
        }

image

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=OpenAI
  スタック トレース:
   場所 OpenAI.Chat.StreamingChatCompletionUpdate.get_Role()
   場所 Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIStreamingChatMessageContent..ctor(StreamingChatCompletionUpdate chatUpdate, Int32 choiceIndex, String modelId, IReadOnlyDictionary`2 metadata)
   場所 Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.<GetStreamingChatMessageContentsAsync>d__16.MoveNext()
   場所 Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.<GetStreamingChatMessageContentsAsync>d__16.MoveNext()
   場所 Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.<GetStreamingChatMessageContentsAsync>d__16.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
   場所 aoai_01.Program.<Main>d__0.MoveNext() (D:\aoai-01\Program.cs):行 58

  この例外は、最初にこの呼び出し履歴 
    [外部コード]
    aoai_01.Program.Main(string[]) (Program.cs 内) でスローされました

Expected behavior The program executes normally without exception.

Platform

  • OS: Windows
  • IDE: Visual Studio
  • Language: C#
  • Source: PackageReference Include="Azure.AI.OpenAI" Version="2.0.0-beta.2" PackageReference Include="Azure.Identity" Version="1.11.0-beta.1" PackageReference Include="Microsoft.SemanticKernel" Version="1.18.0-rc" PackageReference Include="Microsoft.SemanticKernel.Planners.Handlebars" Version="1.18.0-preview" PackageReference Include="Microsoft.SemanticKernel.Plugins.Core" Version="1.18.0-alpha" PackageReference Include="Microsoft.SemanticKernel.Plugins.Web" Version="1.18.0-alpha"

aeras3637 avatar Aug 20 '24 01:08 aeras3637

@aeras3637 Thanks for reporting the Issue with details and reproduction code.

Using your reproduction code (adjustments for credential protection) we could not replicate the error on our environment, suggest checking the HTTP response to ensure if the server side is returning successfully.

Suggest attempting to use the Non-streaming endpoints for testing.

Image

Currently we tested against an Azure OpenAI deployment with the same model gpt-4o.

Image

rogerbarreto avatar Aug 20 '24 14:08 rogerbarreto

Suggest attempting to use the Non-streaming endpoints for testing.

Streaming mode was checked because Custom Content Filter was set. No exception occurred when Streaming mode was set to Default in the content filter settings. When Streaming mode is set to Asynchronous Filter, the exception occurs. Could you please confirm this?

aeras3637 avatar Aug 21 '24 00:08 aeras3637

I also encountered the same error with Asynchronous Filter enabled.

hanhsia avatar Aug 28 '24 16:08 hanhsia