Skip to content

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Sep 9, 2025

Moves the implementation used by GetResponseAsync<T> to be exposed as its own helper that can be used directly, for cases where folks want the formatting but don't want to use the generic GetResponseAsync<T>.

Fixes #6179

Microsoft Reviewers: Open in CodeFlow

@stephentoub stephentoub requested a review from a team as a code owner September 9, 2025 20:45
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Sep 9, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR exposes the JSON schema formatting functionality as a public API by adding a new ChatResponseFormat.ForJsonSchema<T> method, making the schema generation logic directly accessible to users who want the formatting capabilities without using the generic GetResponseAsync<T> method.

  • Moves schema creation logic from ChatClientStructuredOutputExtensions to ChatResponseFormat as a new public method
  • Refactors GetResponseAsync<T> to use the new ForJsonSchema<T> method internally
  • Adds comprehensive test coverage for the new API

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseFormat.cs Adds the new ForJsonSchema<T> method and moves shared constants and helper methods
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs Refactors to use the new ForJsonSchema<T> method and removes duplicated code
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseFormatTests.cs Adds comprehensive test coverage for the new API
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestJsonSerializerContext.cs Adds serialization support for test types
src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json Documents the new public API surface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Moves the implementation used by `GetResponseAsync<T>` to be exposed as its own helper that can be used directly, for cases where folks want the formatting but don't want to use the generic `GetResponseAsync<T>`.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@stephentoub stephentoub enabled auto-merge (squash) September 12, 2025 00:56
@stephentoub stephentoub merged commit d299e16 into dotnet:main Sep 12, 2025
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add ChatResponseFormat.ForType

2 participants