.NET: Fix stop sequence array serialization#6701
Open
VectorPeak wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes .NET OpenAI ChatCompletions “stop” serialization so that multiple stop sequences are emitted as a JSON string array (matching the expected wire format) and adds a unit test to guard the behavior.
Changes:
- Update
StopSequencesConverter.Writeto serializeSequencesusing the source-generatedIList<string>metadata instead of an unrelated type info. - Add a serialization unit test asserting
"stop"is written as a JSON array when multiple stop sequences are provided.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs | Adds a regression test validating "stop" is serialized as a string array for multiple stop sequences. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs | Fixes the converter’s serialization path to use the correct source-generated type info for IList<string>. |
Thanks Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR fixes Chat Completions request serialization for multiple stop sequences by using the JSON metadata that matches the value being written.
Chat Completions requests support
stopas either a single string or an array of strings.StopSequencesConverteralready deserializes array values with string-list metadata, but the corresponding write path used message-content-part metadata when serializingStopSequences.Sequences.The current write path was built with metadata for message content parts:
That metadata describes message content values, not the
IList<string>stored inStopSequences.Sequences. For requests that include multiple stop sequences, the converter should emit a JSON string array such as:Using the string-list metadata keeps the serializer consistent with the existing read path and with the expected Chat Completions request shape, while leaving single stop sequences and null stop values unchanged.
Description & Review Guide
What are the major changes?
StopSequences.Sequenceswith the existing string-list JSON type information:What is the impact of these changes?
CreateChatCompletion.Stop->StopSequencesConverter.Write()->StopSequences.Sequences-> the JSONstopfield.What do you want reviewers to focus on?
StopSequencesConvertershould use the same string-list metadata for reading and writing stop sequence arrays.Related Issue
No linked issue. This is a small deterministic bug fix found while reviewing the Chat Completions request serialization path. I searched open issues and PRs for matching
StopSequences/ stop sequence serialization reports and did not find an existing one.Contribution Checklist
dotnetis not available in this environment.dotnetis not available in this environment.breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) - a workflow keeps the label and title prefix in sync automatically.