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: Json serialization issue when using SK Streaming chat completion in ASP.net Core minimal Api #9941

Closed
HeKeHenryZhang opened this issue Dec 11, 2024 · 3 comments
Assignees
Labels
aot .NET Issue or Pull requests regarding .NET code

Comments

@HeKeHenryZhang
Copy link

I find that JsonSerializerIsReflectionEnabledByDefault is required to be enabled when using Streaming chat completion with ASP.net Core minimal Api. Is it an expected behavior of using SK?
SK is Aot Compatible, why should we still enable JsonSerializerIsReflectionEnabledByDefault explicitly.

Streaming chat completion
To use streaming chat completion, you can use the following code to generate a response from the AI agent.

Copy
ChatHistory history = [];
history.AddUserMessage("Hello, how are you?");

var response = chatCompletionService.GetStreamingChatMessageContentsAsync(
    chatHistory: history,
    kernel: kernel
);

//OpenAI.ModelSerializationExtensions' threw an exception. ---> System.InvalidOperationException: 
//Reflection-based serialization has been disabled for this application. 
//Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property
await foreach (var chunk in response)
{
   yield return chunk.Content ?? string.Empty;
}
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Dec 11, 2024
@github-actions github-actions bot changed the title Json serialization issue when using SK Streaming chat completion in ASP.net Core minimal Api .Net: Json serialization issue when using SK Streaming chat completion in ASP.net Core minimal Api Dec 11, 2024
@markwallace-microsoft markwallace-microsoft moved this to Sprint: Planned in Semantic Kernel Dec 12, 2024
@SergeyMenshykh SergeyMenshykh moved this from Sprint: Planned to Sprint: In Progress in Semantic Kernel Dec 13, 2024
@SergeyMenshykh
Copy link
Member

Hi @HeKeHenryZhang, I presume you don't use the ONNX AI connector, right? At the moment, we have only three Native-AOT packages: Abstractions, Core, and the ONNX AI connector, but we have plans to make more SK packages AOT-friendly.

Tasks to make {Azure} OpenAI AI connectors AOT compatible - #9972

SK AOT-compatible packages - https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Demos/AotCompatibility/README.md

@HeKeHenryZhang
Copy link
Author

Hi @HeKeHenryZhang, I presume you don't use the ONNX AI connector, right? At the moment, we have only three Native-AOT packages: Abstractions, Core, and the ONNX AI connector, but we have plans to make more SK packages AOT-friendly.

Tasks to make {Azure} OpenAI AI connectors AOT compatible - #9972

SK AOT-compatible packages - https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Demos/AotCompatibility/README.md

Thanks @SergeyMenshykh . I'm using Core + AzureOpenAI connector.

@SergeyMenshykh
Copy link
Member

Closing the issue for now. The work will be tracked in the #9972 issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aot .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: In Progress
Development

No branches or pull requests

3 participants