-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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: Support polymorphic serialization of ChatMessageContent class and its derivatives #8901
Merged
SergeyMenshykh
merged 5 commits into
microsoft:main
from
SergeyMenshykh:polymorphic-serialization-for-chat-message-content
Sep 19, 2024
Merged
.Net: Support polymorphic serialization of ChatMessageContent class and its derivatives #8901
SergeyMenshykh
merged 5 commits into
microsoft:main
from
SergeyMenshykh:polymorphic-serialization-for-chat-message-content
Sep 19, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… unknown derivatives
markwallace-microsoft
added
.NET
Issue or Pull requests regarding .NET code
kernel
Issues or pull requests impacting the core kernel
kernel.core
labels
Sep 18, 2024
SergeyMenshykh
temporarily deployed
to
integration
September 18, 2024 21:27 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
September 18, 2024 21:36 — with
GitHub Actions
Inactive
alliscode
approved these changes
Sep 18, 2024
markwallace-microsoft
approved these changes
Sep 19, 2024
RogerBarreto
approved these changes
Sep 19, 2024
dotnet/src/SemanticKernel.Abstractions/Contents/KernelContent.cs
Outdated
Show resolved
Hide resolved
…ttps://github.com/SergeyMenshykh/semantic-kernel into polymorphic-serialization-for-chat-message-content
SergeyMenshykh
had a problem deploying
to
integration
September 19, 2024 08:36 — with
GitHub Actions
Error
SergeyMenshykh
temporarily deployed
to
integration
September 19, 2024 08:38 — with
GitHub Actions
Inactive
RogerBarreto
approved these changes
Sep 19, 2024
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Sep 19, 2024
SergeyMenshykh
deleted the
polymorphic-serialization-for-chat-message-content
branch
September 19, 2024 13:22
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kernel.core
kernel
Issues or pull requests impacting the core kernel
.NET
Issue or Pull requests regarding .NET code
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation, Context and Description
Today, when serializing chat history, the
ChatMessageContent
type or its derivatives, likeOpenAIChatMessageContent
, are serialized as theChatMessageContent
type because the type is used as the chat history element type and the JSON serializer uses this type's public contract for serialization.However, when attempting serialization of instances of either the
ChatMessageContent
orOpenAIChatMessageContent
type that are declared asKernelContent
orobject
type, the serialization fails with theSystem.NotSupportedException: Runtime type '{OpenAI}ChatMessageContent' is not supported by polymorphic type 'Microsoft.SemanticKernel.KernelContent'
exception. The reason for this exception is that neither of these types is registered for polymorphic serialization.This PR registers
ChatMessageContent
type for polymorphic serialization to allow serialization of the type instances declared as ofKernelContent
orobject
types:Additionally, it enables serialization of unknow in advance and external derivatives of
ChatMessageContent
type likeOpenAIChatMessageContent
. These types are serialized using contract of nearest ancestor which isChatMessageContent
by default. To change this behavior and register the unknown type for polymorphic serialization use the contract model - Configure polymorphism with the contract modelCloses: #7478
Contribution Checklist