.NET: fix: preserve Responses logprobs field#5860
Conversation
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. |
| Assert.NotNull(request); | ||
| Assert.True(request.Logprobs); | ||
| Assert.Equal(3, request.TopLogprobs); |
| 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
|
Hi, Team. Just follow up for the catch up on the current status of this. |
| /// Whether log probabilities were requested for the output tokens. | ||
| /// </summary> | ||
| [JsonPropertyName("logprobs")] | ||
| public bool? Logprobs { get; init; } |
There was a problem hiding this comment.
Should this also be propagated wherever a Response is synthesized from CreateResponse? The model now round-trips direct JSON, but the hosted response builders copy TopLogprobs without the matching Logprobs flag, so a /responses request with "logprobs": true can still return response metadata that omits the field. That leaves the OpenAI-compatible endpoint behavior this PR is fixing incomplete.
|
Addressed the remaining propagation gap in 5ead97d. Validation on Windows: project restore/build succeeded, |
5ead97d to
f82bad6
Compare
|
Rebased the logprobs propagation fix onto current main. The final six-file behavior diff is unchanged, the hosting project builds with zero warnings/errors, and the earlier focused serialization/integration test results remain applicable. |
f82bad6 to
2172407
Compare
|
Updated and rebased the branch onto current main. This addresses the remaining review threads:
Validation:
|
2172407 to
facab90
Compare
|
Rebased this branch onto current Validation run locally from
Note: I used |
facab90 to
c2e48bd
Compare
|
Rebased this branch onto current Validation run locally from
The PR diff remains scoped to the six .NET OpenAI hosting/logprobs files after the rebase. |
c2e48bd to
766e32e
Compare
|
Rebased this branch onto current Validation run locally from
|
766e32e to
c80b6a3
Compare
c80b6a3 to
8ed968b
Compare
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