-
Notifications
You must be signed in to change notification settings - Fork 849
add support for background responses #6854
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
stephentoub
merged 61 commits into
dotnet:main
from
SergeyMenshykh:background-responses
Oct 11, 2025
Merged
Changes from 58 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
678a22a
add support for background responses
SergeyMenshykh f2afc33
merge with lates main
SergeyMenshykh 61c4434
Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesCh…
SergeyMenshykh f41d7b2
clone chat options
SergeyMenshykh 09db9fc
use readonlymemory instead of array of bytes
SergeyMenshykh a5b4967
Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesCo…
SergeyMenshykh 25e610e
throw exception if no response id provided in continuation token
SergeyMenshykh 611d704
disable S104 rule and throw argument exception via the throw utility.
SergeyMenshykh fba243b
Merge branch 'background-responses' of https://github.com/SergeyMensh…
SergeyMenshykh 51a4e6c
fix failed unit test
SergeyMenshykh b1e1a9e
addressing PR review comments
SergeyMenshykh a384e94
mark new properties as experimantal and json ignore to prevent warnin…
SergeyMenshykh 30b4c0a
make resumption token and its converter experimental
SergeyMenshykh d68b4a4
Merge branch 'main' into background-responses
SergeyMenshykh 21b04db
remove copy constructor of background response options
SergeyMenshykh 991789e
Merge branch 'background-responses' of https://github.com/SergeyMensh…
SergeyMenshykh 78eef28
rename resumption token
SergeyMenshykh 090667e
rename leftovers
SergeyMenshykh 100f6da
fix unit tests
SergeyMenshykh 77832ea
Merge branch 'main' into background-responses
SergeyMenshykh b87472a
Merge branch 'main' into background-responses
SergeyMenshykh 8cdd78f
Merge branch 'main' into background-responses
SergeyMenshykh 0d6af71
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh da996e8
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh 5d3b6d3
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh 57ca6fd
add a warning if different options are provided, and remove the unnec…
SergeyMenshykh 8c931a4
Merge branch 'background-responses' of https://github.com/SergeyMensh…
SergeyMenshykh 8829e8d
register ResponseContinuationToken for source generation
SergeyMenshykh c2fcc5a
merge with latest main
SergeyMenshykh f0543fd
Merge branch 'main' into background-responses
SergeyMenshykh 3f4188d
Merge branch 'main' into background-responses
stephentoub 6f7ee98
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/CHANGELOG.md
SergeyMenshykh 7ee1fd9
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh c62e773
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh cb09c49
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh 1694854
address pr review comments
SergeyMenshykh 89b71c7
Merge branch 'background-responses' of https://github.com/SergeyMensh…
SergeyMenshykh 72cd300
update remarks
SergeyMenshykh 192c530
rollback changes that are irrelevant to this PR
SergeyMenshykh b7b0095
added lost null checks
SergeyMenshykh 8f876fa
Merge branch 'main' into background-responses
SergeyMenshykh 8b4016f
type continuation token as object in public api surface
SergeyMenshykh 40ef7c6
Merge branch 'background-responses' of https://github.com/SergeyMensh…
SergeyMenshykh d294f7c
Merge branch 'main' into background-responses
SergeyMenshykh 67e1b94
drop extension methods for chat clients
SergeyMenshykh 5c8bbf7
Merge branch 'background-responses' of https://github.com/SergeyMensh…
SergeyMenshykh 5bb75ef
merge with the latest main
SergeyMenshykh e1a17a2
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh 9cf2113
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh be30ab3
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh 6e6a1eb
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatComplet…
SergeyMenshykh e75d140
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/CHANGELOG.md
SergeyMenshykh 7ba3e07
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ResponseCon…
SergeyMenshykh ed262aa
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ResponseCon…
SergeyMenshykh 5c0f200
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/ResponseCon…
SergeyMenshykh 03571e8
Update src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesCh…
SergeyMenshykh ef5012b
address pr review comments
SergeyMenshykh f3eb4a4
Merge branch 'main' into background-responses
SergeyMenshykh e5b1dfe
Apply suggestions from code review
stephentoub 06d06fa
Merge branch 'main' into background-responses
SergeyMenshykh 2371ede
Merge branch 'main' into background-responses
SergeyMenshykh 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
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
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
68 changes: 68 additions & 0 deletions
68
src/Libraries/Microsoft.Extensions.AI.Abstractions/ResponseContinuationToken.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,68 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Represents a token used to resume, continue, or rehydrate an operation across multiple scenarios/calls, | ||
| /// such as resuming a streamed response from a specific point or retrieving the result of a background operation. | ||
| /// Subclasses of this class encapsulate all necessary information within the token to facilitate these actions. | ||
| /// </summary> | ||
| [JsonConverter(typeof(Converter))] | ||
| [Experimental("MEAI001")] | ||
| public class ResponseContinuationToken | ||
stephentoub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary>Bytes representing this token.</summary> | ||
| private readonly ReadOnlyMemory<byte> _bytes; | ||
|
|
||
| /// <summary>Initializes a new instance of the <see cref="ResponseContinuationToken"/> class.</summary> | ||
| protected ResponseContinuationToken() | ||
| { | ||
| } | ||
|
|
||
| /// <summary>Initializes a new instance of the <see cref="ResponseContinuationToken"/> class.</summary> | ||
| /// <param name="bytes">Bytes to create the token from.</param> | ||
| protected ResponseContinuationToken(ReadOnlyMemory<byte> bytes) | ||
| { | ||
| _bytes = bytes; | ||
| } | ||
|
|
||
| /// <summary>Create a new instance of <see cref="ResponseContinuationToken"/> from the provided <paramref name="bytes"/>. | ||
| /// </summary> | ||
| /// <param name="bytes">Bytes representing the <see cref="ResponseContinuationToken"/>.</param> | ||
| /// <returns>A <see cref="ResponseContinuationToken"/> equivalent to the one from which | ||
| /// the original<see cref="ResponseContinuationToken"/> bytes were obtained.</returns> | ||
| public static ResponseContinuationToken FromBytes(ReadOnlyMemory<byte> bytes) => new(bytes); | ||
|
|
||
| /// <summary>Gets the bytes representing this <see cref="ResponseContinuationToken"/>.</summary> | ||
| /// <returns>Bytes representing the <see cref="ResponseContinuationToken"/>.</returns>"/> | ||
| public virtual ReadOnlyMemory<byte> ToBytes() => _bytes; | ||
|
|
||
| /// <summary>Provides a <see cref="JsonConverter{ResponseContinuationToken}"/> for serializing <see cref="ResponseContinuationToken"/> instances.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| [Experimental("MEAI001")] | ||
| public sealed class Converter : JsonConverter<ResponseContinuationToken> | ||
| { | ||
| /// <inheritdoc/> | ||
| public override ResponseContinuationToken Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| return ResponseContinuationToken.FromBytes(reader.GetBytesFromBase64()); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void Write(Utf8JsonWriter writer, ResponseContinuationToken value, JsonSerializerOptions options) | ||
| { | ||
| _ = Throw.IfNull(writer); | ||
| _ = Throw.IfNull(value); | ||
|
|
||
| writer.WriteBase64StringValue(value.ToBytes().Span); | ||
| } | ||
| } | ||
| } | ||
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.
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.