Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.AI;

Expand Down Expand Up @@ -187,17 +185,7 @@ protected ChatOptions(ChatOptions? other)
/// If the implementation does not support background responses, this property will be ignored.
/// </para>
/// </remarks>
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations, UrlFormat = DiagnosticIds.UrlFormat)]
[JsonIgnore]
public bool? AllowBackgroundResponses
{
get => AllowBackgroundResponsesCore;
set => AllowBackgroundResponsesCore = value;
}

[JsonInclude]
[JsonPropertyName("allowBackgroundResponses")]
internal bool? AllowBackgroundResponsesCore { get; set; }
public bool? AllowBackgroundResponses { get; set; }

/// <summary>Gets or sets the continuation token for resuming and getting the result of the chat response identified by this token.</summary>
/// <remarks>
Expand All @@ -210,17 +198,7 @@ public bool? AllowBackgroundResponses
/// can be polled for completion by obtaining the token from the <see cref="ChatResponse.ContinuationToken"/> property
/// and passing it to this property on subsequent calls to <see cref="IChatClient.GetResponseAsync"/>.
/// </remarks>
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations, UrlFormat = DiagnosticIds.UrlFormat)]
[JsonIgnore]
public ResponseContinuationToken? ContinuationToken
{
get => ContinuationTokenCore;
set => ContinuationTokenCore = value;
}

[JsonInclude]
[JsonPropertyName("continuationToken")]
internal ResponseContinuationToken? ContinuationTokenCore { get; set; }
public ResponseContinuationToken? ContinuationToken { get; set; }
Comment thread
jozkee marked this conversation as resolved.

/// <summary>
/// Gets or sets a callback responsible for creating the raw representation of the chat options from an underlying implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.AI;
Expand Down Expand Up @@ -101,17 +100,9 @@ public IList<ChatMessage> Messages
/// to poll for completion.
/// </para>
/// </remarks>
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations, UrlFormat = DiagnosticIds.UrlFormat)]
[JsonIgnore]
public ResponseContinuationToken? ContinuationToken
{
get => ContinuationTokenCore;
set => ContinuationTokenCore = value;
}

[JsonInclude]
[JsonPropertyName("continuationToken")]
internal ResponseContinuationToken? ContinuationTokenCore { get; set; }
public ResponseContinuationToken? ContinuationToken { get; set; }

/// <summary>Gets or sets the raw representation of the chat response from an underlying implementation.</summary>
/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.AI;

Expand Down Expand Up @@ -171,17 +170,9 @@ public IList<AIContent> Contents
/// to resume streaming from the point of interruption.
/// </para>
/// </remarks>
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations, UrlFormat = DiagnosticIds.UrlFormat)]
[JsonIgnore]
public ResponseContinuationToken? ContinuationToken
{
get => ContinuationTokenCore;
set => ContinuationTokenCore = value;
}

[JsonInclude]
[JsonPropertyName("continuationToken")]
internal ResponseContinuationToken? ContinuationTokenCore { get; set; }
public ResponseContinuationToken? ContinuationToken { get; set; }

/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,15 +1013,15 @@
},
{
"Member": "bool? Microsoft.Extensions.AI.ChatOptions.AllowBackgroundResponses { get; set; }",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "bool? Microsoft.Extensions.AI.ChatOptions.AllowMultipleToolCalls { get; set; }",
"Stage": "Stable"
},
{
"Member": "Microsoft.Extensions.AI.ResponseContinuationToken? Microsoft.Extensions.AI.ChatOptions.ContinuationToken { get; set; }",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "string? Microsoft.Extensions.AI.ChatOptions.ConversationId { get; set; }",
Expand Down Expand Up @@ -1121,7 +1121,7 @@
},
{
"Member": "Microsoft.Extensions.AI.ResponseContinuationToken? Microsoft.Extensions.AI.ChatResponse.ContinuationToken { get; set; }",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "string? Microsoft.Extensions.AI.ChatResponse.ConversationId { get; set; }",
Expand Down Expand Up @@ -1301,7 +1301,7 @@
},
{
"Member": "Microsoft.Extensions.AI.ResponseContinuationToken? Microsoft.Extensions.AI.ChatResponseUpdate.ContinuationToken { get; set; }",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "string? Microsoft.Extensions.AI.ChatResponseUpdate.ConversationId { get; set; }",
Expand Down Expand Up @@ -3820,41 +3820,41 @@
},
{
"Type": "class Microsoft.Extensions.AI.ResponseContinuationToken",
"Stage": "Experimental",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.AI.ResponseContinuationToken.ResponseContinuationToken();",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "Microsoft.Extensions.AI.ResponseContinuationToken.ResponseContinuationToken(System.ReadOnlyMemory<byte> bytes);",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "static Microsoft.Extensions.AI.ResponseContinuationToken Microsoft.Extensions.AI.ResponseContinuationToken.FromBytes(System.ReadOnlyMemory<byte> bytes);",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "virtual System.ReadOnlyMemory<byte> Microsoft.Extensions.AI.ResponseContinuationToken.ToBytes();",
"Stage": "Experimental"
"Stage": "Stable"
}
]
},
{
"Type": "sealed class Microsoft.Extensions.AI.ResponseContinuationToken.Converter",
"Stage": "Experimental",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.AI.ResponseContinuationToken.Converter.Converter();",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "override Microsoft.Extensions.AI.ResponseContinuationToken Microsoft.Extensions.AI.ResponseContinuationToken.Converter.Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "override void Microsoft.Extensions.AI.ResponseContinuationToken.Converter.Write(System.Text.Json.Utf8JsonWriter writer, Microsoft.Extensions.AI.ResponseContinuationToken value, System.Text.Json.JsonSerializerOptions options);",
"Stage": "Experimental"
"Stage": "Stable"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.AI;
Expand All @@ -17,7 +15,6 @@ namespace Microsoft.Extensions.AI;
/// Subclasses of this class encapsulate all necessary information within the token to facilitate these actions.
/// </summary>
[JsonConverter(typeof(Converter))]
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations, UrlFormat = DiagnosticIds.UrlFormat)]
public class ResponseContinuationToken
{
/// <summary>Bytes representing this token.</summary>
Expand Down Expand Up @@ -48,7 +45,6 @@ protected ResponseContinuationToken(ReadOnlyMemory<byte> bytes)

/// <summary>Provides a <see cref="JsonConverter{ResponseContinuationToken}"/> for serializing <see cref="ResponseContinuationToken"/> instances.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations, UrlFormat = DiagnosticIds.UrlFormat)]
public sealed class Converter : JsonConverter<ResponseContinuationToken>
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ private static JsonSerializerOptions CreateDefaultOptions()
[JsonSerializable(typeof(AIContent))]
[JsonSerializable(typeof(IEnumerable<AIContent>))]

[JsonSerializable(typeof(ResponseContinuationToken))]

// IEmbeddingGenerator
[JsonSerializable(typeof(EmbeddingGenerationOptions))]
[JsonSerializable(typeof(EmbeddingGeneratorMetadata))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.AI;
Expand All @@ -15,7 +13,6 @@ namespace Microsoft.Extensions.AI;
/// The token is used for resuming streamed background responses and continuing
/// non-streamed background responses until completion.
/// </remarks>
[Experimental(DiagnosticIds.Experiments.AIResponseContinuations)]
internal sealed class ResponsesClientContinuationToken : ResponseContinuationToken
{
/// <summary>Initializes a new instance of the <see cref="ResponsesClientContinuationToken"/> class.</summary>
Expand Down Expand Up @@ -67,7 +64,7 @@ internal static ResponsesClientContinuationToken FromToken(ResponseContinuationT

if (data.Length == 0)
{
Throw.ArgumentException(nameof(token), "Failed to create OpenAIResponsesResumptionToken from provided token because it does not contain any data.");
Throw.ArgumentException(nameof(token), "Failed to create OpenAI continuation token from provided token because it does not contain any data.");
}

Utf8JsonReader reader = new(data.Span);
Expand Down Expand Up @@ -104,7 +101,7 @@ internal static ResponsesClientContinuationToken FromToken(ResponseContinuationT

if (responseId is null)
{
Throw.ArgumentException(nameof(token), "Failed to create MessagesPageToken from provided pageToken because it does not contain a responseId.");
Throw.ArgumentException(nameof(token), "Failed to create OpenAI continuation token from provided token because it does not contain a responseId.");
}

return new(responseId)
Expand Down
1 change: 0 additions & 1 deletion src/Shared/DiagnosticIds/DiagnosticIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ internal static class Experiments
internal const string AIFunctionApprovals = AIExperiments;

internal const string AIChatReduction = AIExperiments;
internal const string AIResponseContinuations = AIExperiments;
internal const string AIToolSearch = AIExperiments;
internal const string AIRealTime = AIExperiments;
internal const string AIFiles = AIExperiments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public void JsonSerialization_Roundtrips_DefaultOptions()

string json = JsonSerializer.Serialize(original, AIJsonUtilities.DefaultOptions);

Assert.Contains("\"allowBackgroundResponses\": true", json, StringComparison.Ordinal);
Assert.Contains("\"continuationToken\": \"AQID\"", json, StringComparison.Ordinal);

ChatOptions? result = JsonSerializer.Deserialize<ChatOptions>(json, AIJsonUtilities.DefaultOptions);

Assert.NotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,30 @@ public void Bytes_Roundtrip(byte[] testBytes)
Assert.Equal(testBytes, token.ToBytes().ToArray());
}

[Fact]
public void JsonSerialization_Roundtrips()
[Theory]
[InlineData(new byte[0], "\"\"")]
[InlineData(new byte[] { 1, 2, 3, 4, 5 }, "\"AQIDBAU=\"")]
public void JsonSerialization_Roundtrips(byte[] testBytes, string expectedJson)
{
ResponseContinuationToken originalToken = ResponseContinuationToken.FromBytes(new byte[] { 1, 2, 3, 4, 5 });
ResponseContinuationToken originalToken = ResponseContinuationToken.FromBytes(testBytes);

// Act
string json = JsonSerializer.Serialize(originalToken, TestJsonSerializerContext.Default.ResponseContinuationToken);
string json = JsonSerializer.Serialize(originalToken, AIJsonUtilities.DefaultOptions);

ResponseContinuationToken? deserializedToken = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ResponseContinuationToken);
ResponseContinuationToken? deserializedToken = JsonSerializer.Deserialize<ResponseContinuationToken>(json, AIJsonUtilities.DefaultOptions);

// Assert
Assert.Equal(expectedJson, json);
Assert.NotNull(deserializedToken);
Assert.Equal(originalToken.ToBytes().ToArray(), deserializedToken.ToBytes().ToArray());
Assert.NotSame(originalToken, deserializedToken);
}

[Fact]
public void DefaultOptions_ContainsMetadataForResponseContinuationToken()
{
Assert.True(AIJsonUtilities.DefaultOptions.TryGetTypeInfo(typeof(ResponseContinuationToken), out var info));
Assert.NotNull(info);
Assert.Equal(typeof(ResponseContinuationToken), info.Type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolCallContentTests.cs" Link="Contents\ImageGenerationToolCallContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolResultContentTests.cs" Link="Contents\ImageGenerationToolResultContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Tools\HostedImageGenerationToolTests.cs" Link="Tools\HostedImageGenerationToolTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\ResponseContinuationTokenTests.cs" Link="ResponseContinuationTokenTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolCallContentTests.cs" Link="Contents\CodeInterpreterToolCallContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolResultContentTests.cs" Link="Contents\CodeInterpreterToolResultContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolCallContentTests.cs" Link="Contents\ImageGenerationToolCallContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolResultContentTests.cs" Link="Contents\ImageGenerationToolResultContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\WebSearchToolCallContentTests.cs" Link="Contents\WebSearchToolCallContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Contents\WebSearchToolResultContentTests.cs" Link="Contents\WebSearchToolResultContentTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Tools\HostedCodeInterpreterToolTests.cs" Link="Tools\HostedCodeInterpreterToolTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Tools\HostedImageGenerationToolTests.cs" Link="Tools\HostedImageGenerationToolTests.cs" />
<Compile Include="..\Microsoft.Extensions.AI.Abstractions.Tests\Tools\HostedWebSearchToolTests.cs" Link="Tools\HostedWebSearchToolTests.cs" />
</ItemGroup>

Expand Down
Loading