-
Notifications
You must be signed in to change notification settings - Fork 884
Add ReasoningOptions to ChatOptions #7252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ab97011
Initial plan
Copilot ba4e283
Add ReasoningOptions to ChatOptions with OpenAI implementation
Copilot 676ac5d
Address code review feedback: add Clone method and document ExtraHigh…
Copilot e7f7ce8
Address PR feedback: remove experimental attributes, make Clone inter…
Copilot f459c9c
Address PR feedback: update docs, remove enum values, add tests
Copilot 88c12a3
Rename ReasoningOutput.Detailed to ReasoningOutput.Full
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ReasoningEffort.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Shared.DiagnosticIds; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Specifies the level of reasoning effort that should be applied when generating chat responses. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This value controls how much computational effort the model should put into reasoning. | ||
| /// Higher values may result in more thoughtful responses but with increased latency and token usage. | ||
| /// The specific interpretation and support for each level may vary between providers. | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
| /// </remarks> | ||
| [Experimental(DiagnosticIds.Experiments.AIReasoning, UrlFormat = DiagnosticIds.UrlFormat)] | ||
| public enum ReasoningEffort | ||
| { | ||
| /// <summary> | ||
| /// No reasoning effort. Disables reasoning for providers that support it. | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| None = 0, | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
|
|
||
| /// <summary> | ||
| /// Low reasoning effort. Minimal reasoning for faster responses. | ||
| /// </summary> | ||
| Low = 1, | ||
|
|
||
| /// <summary> | ||
| /// Medium reasoning effort. Balanced reasoning for most use cases. | ||
| /// </summary> | ||
| Medium = 2, | ||
|
|
||
| /// <summary> | ||
| /// High reasoning effort. Extensive reasoning for complex tasks. | ||
| /// </summary> | ||
| High = 3, | ||
|
|
||
| /// <summary> | ||
| /// Extra high reasoning effort. Maximum reasoning for the most demanding tasks. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Not all providers support this level of reasoning effort. Some providers may map this to | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
| /// their highest available level (such as <see cref="High"/>) if they don't have an equivalent. | ||
| /// </remarks> | ||
| ExtraHigh = 4, | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ReasoningOptions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Shared.DiagnosticIds; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Represents options for configuring reasoning behavior in chat requests. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Reasoning options allow control over how much computational effort the model | ||
| /// should put into reasoning about the response, and how that reasoning should | ||
| /// be exposed to the caller. | ||
| /// </para> | ||
| /// <para> | ||
| /// Not all providers support all reasoning options. Implementations should | ||
| /// make a best-effort attempt to map the requested options to the provider's | ||
| /// capabilities. If a provider doesn't support reasoning, these options may be ignored. | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
| /// </para> | ||
| /// </remarks> | ||
| [Experimental(DiagnosticIds.Experiments.AIReasoning, UrlFormat = DiagnosticIds.UrlFormat)] | ||
| public sealed class ReasoningOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the level of reasoning effort to apply. | ||
| /// </summary> | ||
| /// <value> | ||
| /// The reasoning effort level, or <see langword="null"/> to use the provider's default. | ||
| /// </value> | ||
| public ReasoningEffort? Effort { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets how reasoning content should be included in the response. | ||
| /// </summary> | ||
| /// <value> | ||
| /// The reasoning output mode, or <see langword="null"/> to use the provider's default. | ||
| /// </value> | ||
| public ReasoningOutput? Output { get; set; } | ||
|
|
||
| /// <summary>Creates a shallow clone of this <see cref="ReasoningOptions"/> instance.</summary> | ||
| /// <returns>A shallow clone of this instance.</returns> | ||
| public ReasoningOptions Clone() => new() | ||
|
stephentoub marked this conversation as resolved.
Outdated
|
||
| { | ||
| Effort = Effort, | ||
| Output = Output, | ||
| }; | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ReasoningOutput.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Shared.DiagnosticIds; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Specifies how reasoning content should be included in the response. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Some providers support including reasoning or thinking traces in the response. | ||
| /// This setting controls whether and how that reasoning content is exposed. | ||
| /// </remarks> | ||
| [Experimental(DiagnosticIds.Experiments.AIReasoning, UrlFormat = DiagnosticIds.UrlFormat)] | ||
| public enum ReasoningOutput | ||
| { | ||
| /// <summary> | ||
| /// No reasoning output. Do not include reasoning content in the response. | ||
| /// </summary> | ||
| None = 0, | ||
|
|
||
| /// <summary> | ||
| /// Summary reasoning output. Include a summary of the reasoning process. | ||
| /// </summary> | ||
| Summary = 1, | ||
|
|
||
| /// <summary> | ||
| /// Detailed reasoning output. Include detailed reasoning content in the response. | ||
| /// </summary> | ||
| Detailed = 2, | ||
| } |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.