.NET: fix: preserve Responses logprobs field#5860
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes loss of the logprobs field during .NET Responses request/response JSON serialization round-trips by adding the missing model properties and extending serialization tests to cover the behavior.
Changes:
- Add nullable
logprobstoCreateResponseandResponsemodels. - Add unit tests to validate
logprobs+top_logprobsdeserialize/reserialize round trips.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIResponsesSerializationTests.cs | Adds round-trip serialization tests for logprobs and top_logprobs in request/response payloads. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Models/Response.cs | Adds Logprobs JSON-mapped property to preserve response payload field. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Models/CreateResponse.cs | Adds Logprobs JSON-mapped property to preserve request payload field. |
Comment on lines
+212
to
+214
| Assert.NotNull(request); | ||
| Assert.True(request.Logprobs); | ||
| Assert.Equal(3, request.TopLogprobs); |
Comment on lines
+591
to
+593
| Assert.NotNull(response); | ||
| Assert.True(response.Logprobs); | ||
| Assert.Equal(3, response.TopLogprobs); |
| } | ||
|
|
||
| [Fact] | ||
| public void Deserialize_CreateRequestWithLogprobs_RoundTripsFields() |
| } | ||
| """; | ||
|
|
||
| CreateResponse? request = JsonSerializer.Deserialize(Json, OpenAIHostingJsonContext.Default.CreateResponse); |
bbfbec0 to
8a09b0f
Compare
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.
Summary
logprobsfield to the ResponsesCreateResponseandResponsemodelslogprobsalongsidetop_logprobsduring JSON deserialize / reserialize round tripsFixes #5854.
To verify
dotnet test --project tests\Microsoft.Agents.AI.Hosting.OpenAI.UnitTests\Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.csproj -f net10.0 --no-restore --filter-class Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.OpenAIResponsesSerializationTestsdotnet build src\Microsoft.Agents.AI.Hosting.OpenAI\Microsoft.Agents.AI.Hosting.OpenAI.csproj -f net10.0 --no-restore --tl:offdotnet build tests\Microsoft.Agents.AI.Hosting.OpenAI.UnitTests\Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.csproj -f net10.0 --no-restore --tl:offdotnet format src\Microsoft.Agents.AI.Hosting.OpenAI\Microsoft.Agents.AI.Hosting.OpenAI.csproj --verify-no-changes --no-restoredotnet format tests\Microsoft.Agents.AI.Hosting.OpenAI.UnitTests\Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.csproj --verify-no-changes --no-restore