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: Fix serialization of OpenAIChatMessageContent type #5301

Merged
merged 14 commits into from
Mar 5, 2024

Conversation

SergeyMenshykh
Copy link
Member

Motivation and Context

This PR fixes the #5264 issue that prevents auto calling of kernel functions created from prompt.

Description

  1. The PR checks whether the function execution result type is ChatMessageContent or its subtype and returns the ChatMessageContent.Content property value if that's the case. Otherwise, if the check was not provided, there would be an attempt to serialize the class and because the OpenAIChatMessageContent is not and can't be registered for polymorphic serialization on the KernelContent class, the serialization would fail with the exception - "System.NotSupportedException: Runtime type 'Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIChatMessageContent' is not supported by polymorphic type 'Microsoft.SemanticKernel.KernelContent'." Alternatively, instead of the type check above, the function result serializer could be configured with a custom JsonTypeInfoResolver to handle polymorphic serialization of the OpenAIChatMessageContent class. However, in this case, all the public properties - ModelId, Metadata, Content, Items, Encoding, etc. of the OpenAIChatMessageContent class would be unnecessarily serialized.
  2. This PR also introduces the new ToolCallBehavior.FunctionResultSerializerOptions to manage the serialization behavior of function execution results. It can be used to provide a JsonTypeInfoResolver for the polymorphic serialization of a custom subclass of the KernelContent class.

Contribution Checklist

@SergeyMenshykh SergeyMenshykh added the .NET Issue or Pull requests regarding .NET code label Mar 4, 2024
@SergeyMenshykh SergeyMenshykh self-assigned this Mar 4, 2024
@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner March 4, 2024 23:07
@markwallace-microsoft markwallace-microsoft added the kernel Issues or pull requests impacting the core kernel label Mar 4, 2024
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2024
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2024
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2024
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Mar 5, 2024
Merged via the queue into microsoft:main with commit b460e09 Mar 5, 2024
18 checks passed
@SergeyMenshykh SergeyMenshykh deleted the serialization-fix branch March 5, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants