Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net - Remove empty properties for content serialization. (#5644)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> A lot of extra bytes for empty and duplicated content when serializing `ChatHistory`. ``` [ { "Role": { "Label": "user" }, "Content": "Discuss the potential long-term consequences for the Earth\u0027s ecosystem as well.", "Items": [ { "$type": "TextContent", "Text": "Discuss the potential long-term consequences for the Earth\u0027s ecosystem as well.", "ModelId": null, "Metadata": null, "MimeType": null }, { "$type": "ImageContent", "Uri": "https://fake-random-test-host:123", "Data": null, "ModelId": null, "Metadata": null, "MimeType": null }, { "$type": "BinaryContent", "Content": "WzEsMiwzXQ==", "ModelId": null, "Metadata": null, "MimeType": null }, { "$type": "AudioContent", "Data": "WzEsMiwzXQ==", "ModelId": null, "Metadata": null, "MimeType": null } ], "ModelId": null, "Metadata": null, "MimeType": null } ] ``` ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Fixed - no data loss with current version (also added json output to test for visibility): ``` [ { "Role": { "Label": "user" }, "Items": [ { "$type": "TextContent", "Text": "Discuss the potential long-term consequences for the Earth\u0027s ecosystem as well." }, { "$type": "ImageContent", "Uri": "https://fake-random-test-host:123" }, { "$type": "BinaryContent", "Content": "WzEsMiwzXQ==" }, { "$type": "AudioContent", "Data": "WzEsMiwzXQ==" } ] } ] ``` > NOTE: There exists a small window of time in the evolution of `ChatHistory` where it only contained a simple `Content` property and no `Items` property. In the outside chance this version of `ChatHistory` have been serialized and now attempted to be deserialized, the data stored in `Content` will not be present in the deserialized object instance. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
- Loading branch information