216 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
628new()
Microsoft.Extensions.AI.Abstractions (2)
ChatCompletion\ChatResponse.cs (2)
129extra = new ChatResponseUpdate 147updates[i] = new ChatResponseUpdate
Microsoft.Extensions.AI.Abstractions.Tests (145)
ChatCompletion\ChatClientExtensionsTests.cs (2)
146return YieldAsync([new ChatResponseUpdate(ChatRole.Assistant, "world")]); 233return YieldAsync([new ChatResponseUpdate(ChatRole.Assistant, "world")]);
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (137)
30new(ChatRole.Assistant, "Hello") { ResponseId = "someResponse", MessageId = "12345", CreatedAt = new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model123" }, 31new(ChatRole.Assistant, ", ") { AuthorName = "Someone", AdditionalProperties = new() { ["a"] = "b" } }, 32new(null, "world!") { CreatedAt = new DateTimeOffset(2, 2, 3, 4, 5, 6, TimeSpan.Zero), ConversationId = "123", AdditionalProperties = new() { ["c"] = "d" } }, 34new() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] }, 35new() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] }, 74new(null, "!") { MessageId = "1" }, 75new(ChatRole.Assistant, "a") { MessageId = "1" }, 76new(ChatRole.Assistant, "b") { MessageId = "2" }, 77new(ChatRole.User, "c") { MessageId = "2" }, 78new(ChatRole.User, "d") { MessageId = "2" }, 79new(ChatRole.Assistant, "e") { MessageId = "3" }, 80new(ChatRole.Tool, "f") { MessageId = "4" }, 81new(ChatRole.Tool, "g") { MessageId = "4" }, 82new(ChatRole.Tool, "h") { MessageId = "5" }, 83new(new("human"), "i") { MessageId = "6" }, 84new(new("human"), "j") { MessageId = "7" }, 85new(new("human"), "k") { MessageId = "7" }, 86new(null, "l") { MessageId = "7" }, 87new(null, "m") { MessageId = "8" }, 132new(ChatRole.Assistant, "Hello ") { AuthorName = "Alice" }, 133new(null, "from ") { AuthorName = "Alice" }, 134new(null, "Alice!"), 137new(null, "Hi ") { AuthorName = "Bob" }, 138new(null, "from ") { AuthorName = "Bob" }, 139new(null, "Bob!"), 142new(ChatRole.Assistant, "Greetings ") { AuthorName = "Charlie" }, 143new(null, "from Charlie!") { AuthorName = "Charlie" }, 146new(null, "Alice again!") { AuthorName = "Alice" }, 149new(null, " Still Alice.") { AuthorName = "" }, 150new(null, " And more."), 185new(ChatRole.Assistant, "A") { MessageId = "1", AuthorName = "Alice" }, 186new(null, "B") { MessageId = "1", AuthorName = "Alice" }, 189new(null, "C") { MessageId = "1", AuthorName = "Bob" }, 192new(null, "D") { MessageId = "2", AuthorName = "Bob" }, 193new(null, "E") { MessageId = "2", AuthorName = "Bob" }, 196new(ChatRole.User, "F") { MessageId = "2", AuthorName = "Bob" }, 199new(ChatRole.Tool, "G") { MessageId = "3", AuthorName = "Charlie" }, 200new(null, "H") { MessageId = "3", AuthorName = "Charlie" }, 244new(ChatRole.Assistant, "Hello") { AuthorName = "Assistant" }, 247new(null, " world") { AuthorName = "" }, 250new(null, "!"), 253new(null, " How") { AuthorName = "" }, 254new(null, " are") { AuthorName = "" }, 257new(null, " you?") { AuthorName = null }, 279new(ChatRole.Assistant, "Hello") { MessageId = "1" }, 280new(null, " there") { MessageId = "1" }, 283new(null, " I'm Bob") { MessageId = "1", AuthorName = "Bob" }, 284new(null, " speaking") { MessageId = "1", AuthorName = "Bob" }, 287new(null, "Now Alice") { MessageId = "1", AuthorName = "Alice" }, 314new(ChatRole.Assistant, "Hello"), 315new(null, " there"), 318new(null, " from") { MessageId = "msg1" }, 319new(null, " AI") { MessageId = "msg1" }, 322new(null, "Next message") { MessageId = "msg2" }, 349new(ChatRole.Assistant, "Hello") { MessageId = "msg1" }, 350new(null, " world") { MessageId = "msg1" }, 353new(null, "!") { MessageId = "" }, 356new(null, " How"), 359new(null, " are") { MessageId = "" }, 360new(null, " you?"), 382new(null, "Hello") { MessageId = "1" }, 383new(null, " there") { MessageId = "1" }, 386new(ChatRole.Assistant, " from") { MessageId = "1" }, 387new(null, " AI") { MessageId = "1" }, 390new(ChatRole.User, "User message") { MessageId = "1" }, 417new(new ChatRole("agent1"), "Hello") { MessageId = "1" }, 418new(null, " from") { MessageId = "1" }, 419new(new ChatRole("agent1"), " agent1") { MessageId = "1" }, 422new(new ChatRole("agent2"), "Hi") { MessageId = "1" }, 423new(null, " from") { MessageId = "1" }, 424new(new ChatRole("agent2"), " agent2") { MessageId = "1" }, 427new(ChatRole.Assistant, "Assistant here") { MessageId = "1" }, 455new(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" }, 456new(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" }, 457new(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should win 458new(null, " AI") { MessageId = "msg1", AuthorName = "Assistant" }, // Keep same AuthorName to avoid creating new message 461new(null, "More text") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 2, 0, TimeSpan.Zero), AuthorName = "Assistant" }, 464new(ChatRole.User, "How") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" }, 465new(null, " are") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) }, 466new(null, " you?") { MessageId = "msg3", AuthorName = "User" }, // Keep same AuthorName 469new(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) }, 470new(null, " thank you!") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should win 473new(null, " How can I help?"), 555updates.Add(new(null, text)); 576updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] }); 603new(null, "A"), 604new(null, "B"), 605new(null, "C"), 606new() { Contents = [new TextReasoningContent("D")] }, 607new() { Contents = [new TextReasoningContent("E")] }, 608new() { Contents = [new TextReasoningContent("F")] }, 609new(null, "G"), 610new(null, "H"), 611new() { Contents = [new TextReasoningContent("I")] }, 612new() { Contents = [new TextReasoningContent("J")] }, 613new(null, "K"), 614new() { Contents = [new TextReasoningContent("L")] }, 615new(null, "M"), 616new(null, "N"), 617new() { Contents = [new TextReasoningContent("O")] }, 618new() { Contents = [new TextReasoningContent("P")] }, 641new() { Contents = [new TextReasoningContent("A") { ProtectedData = "1" }] }, 642new() { Contents = [new TextReasoningContent("B") { ProtectedData = "2" }] }, 643new() { Contents = [new TextReasoningContent("C")] }, 644new() { Contents = [new TextReasoningContent("D")] }, 645new() { Contents = [new TextReasoningContent("E") { ProtectedData = "3" }] }, 646new() { Contents = [new TextReasoningContent("F") { ProtectedData = "4" }] }, 647new() { Contents = [new TextReasoningContent("G")] }, 648new() { Contents = [new TextReasoningContent("H")] }, 678new(null, "A"), 679new(null, "B"), 680new(null, "C"), 681new() { Contents = [new TextContent("D") { Annotations = [new()] }] }, 682new() { Contents = [new TextContent("E") { Annotations = [new()] }] }, 683new() { Contents = [new TextContent("F") { Annotations = [new()] }] }, 684new() { Contents = [new TextContent("G") { Annotations = [] }] }, 685new() { Contents = [new TextContent("H") { Annotations = [] }] }, 686new() { Contents = [new TextContent("I") { Annotations = [new()] }] }, 687new() { Contents = [new TextContent("J") { Annotations = [new()] }] }, 688new(null, "K"), 689new() { Contents = [new TextContent("L") { Annotations = [new()] }] }, 690new(null, "M"), 691new(null, "N"), 692new() { Contents = [new TextContent("O") { Annotations = [new()] }] }, 693new() { Contents = [new TextContent("P") { Annotations = [new()] }] }, 718new(null, "Hello, "), 719new(null, "world!"), 720new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] }, 747new(ChatRole.Tool, "a") { MessageId = "4", CreatedAt = early }, 750new(null, "b") { CreatedAt = unixEpoch }, 753new(null, "c") { CreatedAt = middle }, 756new(null, "d") { CreatedAt = early }, 759new(null, "e") { CreatedAt = late }, 762new(null, "f") { CreatedAt = unixEpoch }, 765new(null, "g") { CreatedAt = null }, 811new(ChatRole.Assistant, "a") { CreatedAt = first }, 812new(null, "b") { CreatedAt = second },
ChatCompletion\ChatResponseUpdateTests.cs (4)
16ChatResponseUpdate update = new(); 33ChatResponseUpdate update = new(); 87ChatResponseUpdate update = new() 115ChatResponseUpdate original = new()
ChatCompletion\DelegatingChatClientTests.cs (2)
61new(ChatRole.User, "Message 1"), 62new(ChatRole.User, "Message 2")
Microsoft.Extensions.AI.AzureAIInference (2)
AzureAIInferenceChatClient.cs (2)
165ChatResponseUpdate responseUpdate = new() 220var responseUpdate = new ChatResponseUpdate
Microsoft.Extensions.AI.Evaluation.Safety (1)
ContentSafetyChatClient.cs (1)
100yield return new ChatResponseUpdate(ChatRole.Assistant, annotationResult)
Microsoft.Extensions.AI.OpenAI (8)
OpenAIAssistantsChatClient.cs (5)
164ChatResponseUpdate ruUpdate = new() 209yield return new ChatResponseUpdate(ChatRole.Assistant, [hcitcc]) 240yield return new ChatResponseUpdate(ChatRole.Assistant, [hcitrc]) 252ChatResponseUpdate textUpdate = new(mcu.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant, mcu.Text) 301yield return new()
OpenAIChatClient.cs (2)
349ChatResponseUpdate responseUpdate = new() 416ChatResponseUpdate responseUpdate = new()
OpenAIResponsesChatClient.cs (1)
299new(lastRole, content is not null ? [content] : null)
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIConversionTests.cs (10)
960var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello") 978var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!") 1007var responseUpdate = new ChatResponseUpdate 1046var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent]) 1081var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2]) 1109var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, 1157var responseUpdate = new ChatResponseUpdate(inputRole, "Test message"); 1183var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test") 1204new ChatResponseUpdate(ChatRole.Assistant, "Hello, ") 1211new ChatResponseUpdate(ChatRole.Assistant, "world!")
Microsoft.Extensions.AI.Tests (46)
ChatCompletion\ConfigureOptionsChatClientTests.cs (1)
38var expectedUpdates = Enumerable.Range(0, 3).Select(i => new ChatResponseUpdate()).ToArray();
ChatCompletion\DistributedCachingChatClientTest.cs (16)
249new() 262new() 267new() 313new(ChatRole.Assistant, "This"), 314new(ChatRole.Assistant, " becomes one chunk"), 315new() { Role = ChatRole.Assistant, Contents = [new FunctionCallContent("callId1", "separator")] }, 316new(ChatRole.Assistant, "... and this"), 317new(ChatRole.Assistant, " becomes another"), 318new(ChatRole.Assistant, " one."), 368new() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] }, 369new() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] }, 370new() 381new() 436new(ChatRole.Assistant, "Chunk 1"), 484() => new(ChatRole.Assistant, "Chunk 1"), 523[() => new(ChatRole.Assistant, "A good result")]);
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (7)
706yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId }; 709new ChatResponseUpdate( 779yield return new ChatResponseUpdate(ChatRole.Assistant, [new TextContent("Text 1")]) { MessageId = messageId }; 781yield return new ChatResponseUpdate(ChatRole.Assistant, [new TextContent("Text 2")]) { MessageId = messageId }; 783yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId }; 785yield return new ChatResponseUpdate( 792yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func3")]) { MessageId = messageId };
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
760new() { Contents = [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["text"] = "Input 1" })] }, 761new() { Contents = [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["text"] = "Input 2" })] } 766updates = [new() { Contents = [new TextContent("OK bye")] }];
ChatCompletion\LoggingChatClientTests.cs (2)
108yield return new(ChatRole.Assistant, "blue "); 109yield return new(ChatRole.Assistant, "whale");
ChatCompletion\OpenTelemetryChatClientTests.cs (10)
69yield return new ChatResponseUpdate(ChatRole.Assistant, text) 75yield return new ChatResponseUpdate 80yield return new ChatResponseUpdate 371yield return new(ChatRole.Assistant, "Assistant response text"); 372yield return new() { Contents = [new TextReasoningContent("This is reasoning")] }; 373yield return new() { Contents = [new FunctionCallContent("call-123", "GetWeather", new Dictionary<string, object?> { ["location"] = "Seattle" })] }; 374yield return new() { Contents = [new FunctionResultContent("call-123", "72°F and sunny")] }; 375yield return new() { Contents = [new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png")] }; 376yield return new() { Contents = [new UriContent(new Uri("https://example.com/image.jpg"), "image/jpeg")] }; 377yield return new() { Contents = [new HostedFileContent("file-abc123")] };
ChatCompletion\ReducingChatClientTests.cs (2)
50var expectedUpdates = new[] { new ChatResponseUpdate(ChatRole.Assistant, "It's"), new ChatResponseUpdate(null, " sunny!") };
ChatCompletion\UseDelegateChatClientTests.cs (5)
51return YieldUpdates(new ChatResponseUpdate(null, "world")); 133return YieldUpdates(new ChatResponseUpdate(null, "hello")); 154yield return new(null, " world"); 193return YieldUpdates(new ChatResponseUpdate(null, "streaming hello")); 225yield return new(null, " world (streaming)");
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
73yield return new(ChatRole.Assistant, output)
303 references to ChatResponseUpdate
Aspire.Dashboard (2)
Model\Assistant\AIHelpers.cs (2)
467await foreach (var update in response.WithCancellation(responseCts.Token).ConfigureAwait(false)) 498public static IList<ChatMessage> GetMessages(ChatResponseUpdate update, Func<AIContent, bool>? filter = null)
Microsoft.Extensions.AI (50)
ChatCompletion\AnonymousDelegatingChatClient.cs (10)
29private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? _getStreamingResponseFunc; 78Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc) 127public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 134var updates = Channel.CreateBounded<ChatResponseUpdate>(1); 144await foreach (var update in InnerClient.GetStreamingResponseAsync(messages, options, cancellationToken)) 165static async IAsyncEnumerable<ChatResponseUpdate> ReadAllAsync( 166ChannelReader<ChatResponseUpdate> channel, [EnumeratorCancellation] CancellationToken cancellationToken) 170while (channel.TryRead(out var update)) 187static async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsyncViaGetResponseAsync(Task<ChatResponse> task) 190foreach (var update in response.ToChatResponseUpdates())
ChatCompletion\CachingChatClient.cs (12)
74public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 84private async IAsyncEnumerable<ChatResponseUpdate> GetCachedStreamingResponseAsync( 97foreach (var chunk in chatResponse.ToChatResponseUpdates()) 105List<ChatResponseUpdate> capturedItems = []; 106await foreach (var chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 123foreach (var chunk in existingChunks) 132List<ChatResponseUpdate> capturedItems = []; 133await foreach (var chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 163/// Returns a previously cached list of <see cref="ChatResponseUpdate"/> values, if available. 170protected abstract Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken); 185/// Stores a list of <see cref="ChatResponseUpdate"/> values in the underlying cache. 194protected abstract Task WriteCacheStreamingAsync(string key, IReadOnlyList<ChatResponseUpdate> value, CancellationToken cancellationToken);
ChatCompletion\ChatClientBuilder.cs (1)
144Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc)
ChatCompletion\ConfigureOptionsChatClient.cs (2)
42public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 45await foreach (var update in base.GetStreamingResponseAsync(messages, Configure(options), cancellationToken))
ChatCompletion\DistributedCachingChatClient.cs (6)
24/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>, 86protected override async Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken) 93return (IReadOnlyList<ChatResponseUpdate>?)JsonSerializer.Deserialize(existingJson, JsonSerializerOptions.GetTypeInfo(typeof(IReadOnlyList<ChatResponseUpdate>))); 111protected override async Task WriteCacheStreamingAsync(string key, IReadOnlyList<ChatResponseUpdate> value, CancellationToken cancellationToken) 117var newJson = JsonSerializer.SerializeToUtf8Bytes(value, JsonSerializerOptions.GetTypeInfo(typeof(IReadOnlyList<ChatResponseUpdate>)));
ChatCompletion\DistributedCachingChatClientBuilderExtensions.cs (1)
29/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>,
ChatCompletion\FunctionInvokingChatClient.cs (7)
404public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 424List<ChatResponseUpdate> updates = []; // updates from the current response 490await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 494Throw.InvalidOperationException($"The inner {nameof(IChatClient)} streamed a null {nameof(ChatResponseUpdate)}."); 558var updateToYield = updates[lastYieldedUpdateIndex]; 580var updateToYield = updates[lastYieldedUpdateIndex]; 627private static ChatResponseUpdate ConvertToolResultMessageToUpdate(ChatMessage message, string? conversationId, string? messageId) =>
ChatCompletion\LoggingChatClient.cs (3)
100public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 115IAsyncEnumerator<ChatResponseUpdate> e; 133ChatResponseUpdate? update = null;
ChatCompletion\OpenTelemetryChatClient.cs (4)
163public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 175IAsyncEnumerable<ChatResponseUpdate> updates; 187List<ChatResponseUpdate> trackedUpdates = []; 193ChatResponseUpdate update;
ChatCompletion\ReducingChatClient.cs (2)
40public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 45await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken).ConfigureAwait(false))
ToolReduction\ToolReducingChatClient.cs (2)
48public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 53await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken).ConfigureAwait(false))
Microsoft.Extensions.AI.Abstractions (43)
ChatCompletion\ChatClientExtensions.cs (2)
131public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 151public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatCompletion\ChatOptions.cs (1)
192/// can be resumed if interrupted. This means that a continuation token obtained from the <see cref="ChatResponseUpdate.ContinuationToken"/>
ChatCompletion\ChatResponse.cs (5)
122/// <summary>Creates an array of <see cref="ChatResponseUpdate" /> instances that represent this <see cref="ChatResponse" />.</summary> 123/// <returns>An array of <see cref="ChatResponseUpdate" /> instances that can be used to represent this <see cref="ChatResponse" />.</returns> 124public ChatResponseUpdate[] ToChatResponseUpdates() 126ChatResponseUpdate? extra = null; 141var updates = new ChatResponseUpdate[messageCount + (extra is not null ? 1 : 0)];
ChatCompletion\ChatResponseExtensions.cs (23)
21/// Provides extension methods for working with <see cref="ChatResponse"/> and <see cref="ChatResponseUpdate"/> instances. 50/// <param name="updates">The <see cref="ChatResponseUpdate"/> instances to convert to messages and add to the list.</param> 55/// method may use <see cref="ChatResponseUpdate.MessageId"/> to determine message boundaries, as well as coalesce 59public static void AddMessages(this IList<ChatMessage> list, IEnumerable<ChatResponseUpdate> updates) 64if (updates is ICollection<ChatResponseUpdate> { Count: 0 }) 74/// <param name="update">The <see cref="ChatResponseUpdate"/> instance to convert to a message and add to the list.</param> 79/// If the <see cref="ChatResponseUpdate"/> has no content, or all its content gets excluded by <paramref name="filter"/>, then 82public static void AddMessages(this IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool>? filter = null) 102/// <param name="updates">The <see cref="ChatResponseUpdate"/> instances to convert to messages and add to the list.</param> 109/// method may use <see cref="ChatResponseUpdate.MessageId"/> to determine message boundaries, as well as coalesce 114this IList<ChatMessage> list, IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken = default) 122IList<ChatMessage> list, IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken) => 126/// <summary>Combines <see cref="ChatResponseUpdate"/> instances into a single <see cref="ChatResponse"/>.</summary> 132/// <see cref="ChatMessage"/> instances. This includes using <see cref="ChatResponseUpdate.MessageId"/> to determine 137this IEnumerable<ChatResponseUpdate> updates) 143foreach (var update in updates) 153/// <summary>Combines <see cref="ChatResponseUpdate"/> instances into a single <see cref="ChatResponse"/>.</summary> 160/// <see cref="ChatMessage"/> instances. This includes using <see cref="ChatResponseUpdate.MessageId"/> to determine 165this IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken = default) 172IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken) 176await foreach (var update in updates.WithCancellation(cancellationToken).ConfigureAwait(false)) 433/// <summary>Processes the <see cref="ChatResponseUpdate"/>, incorporating its contents into <paramref name="response"/>.</summary> 436private static void ProcessUpdate(ChatResponseUpdate update, ChatResponse response)
ChatCompletion\ChatResponseUpdate.cs (8)
17/// <see cref="ChatResponseUpdate"/> is so named because it represents updates 22/// The relationship between <see cref="ChatResponse"/> and <see cref="ChatResponseUpdate"/> is 38/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 44/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 52/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 88/// If a <see cref="ChatResponseUpdate"/> is created to represent some underlying object from another object 109/// This value is used when <see cref="ChatResponseExtensions.ToChatResponseAsync(IAsyncEnumerable{ChatResponseUpdate}, System.Threading.CancellationToken)"/> 110/// groups <see cref="ChatResponseUpdate"/> instances into <see cref="ChatMessage"/> instances.
ChatCompletion\DelegatingChatClient.cs (1)
48public virtual IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatCompletion\IChatClient.cs (1)
54IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Utilities\AIJsonUtilities.Defaults.cs (2)
116[JsonSerializable(typeof(ChatResponseUpdate))] 117[JsonSerializable(typeof(IReadOnlyList<ChatResponseUpdate>))]
Microsoft.Extensions.AI.Abstractions.Tests (43)
ChatCompletion\ChatClientExtensionsTests.cs (5)
151await foreach (var update in client.GetStreamingResponseAsync("hello", expectedOptions, cts.Token)) 238await foreach (var update in client.GetStreamingResponseAsync([], expectedChatOptions, cts.Token)) 247private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(params ChatResponseUpdate[] updates) 250foreach (var update in updates)
ChatCompletion\ChatResponseTests.cs (7)
139ChatResponseUpdate[] updates = response.ToChatResponseUpdates(); 143ChatResponseUpdate update0 = updates[0]; 152ChatResponseUpdate update1 = updates[1]; 181ChatResponseUpdate[] updates = response.ToChatResponseUpdates(); 185ChatResponseUpdate update0 = updates[0]; 194ChatResponseUpdate update1 = updates[1]; 203ChatResponseUpdate update2 = updates[2];
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (22)
20Assert.Throws<ArgumentNullException>("updates", () => ((List<ChatResponseUpdate>)null!).ToChatResponse()); 28ChatResponseUpdate[] updates = 72ChatResponseUpdate[] updates = 128ChatResponseUpdate[] updates = 181ChatResponseUpdate[] updates = 240ChatResponseUpdate[] updates = 275ChatResponseUpdate[] updates = 310ChatResponseUpdate[] updates = 345ChatResponseUpdate[] updates = 378ChatResponseUpdate[] updates = 413ChatResponseUpdate[] updates = 451ChatResponseUpdate[] updates = 540List<ChatResponseUpdate> updates = []; 601ChatResponseUpdate[] updates = 639ChatResponseUpdate[] updates = 676ChatResponseUpdate[] updates = 716ChatResponseUpdate[] updates = 743ChatResponseUpdate[] updates = 809ChatResponseUpdate[] updates = 825private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(IEnumerable<ChatResponseUpdate> updates) 827foreach (ChatResponseUpdate update in updates)
ChatCompletion\ChatResponseUpdateTests.cs (5)
16ChatResponseUpdate update = new(); 33ChatResponseUpdate update = new(); 87ChatResponseUpdate update = new() 115ChatResponseUpdate original = new() 137ChatResponseUpdate? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatResponseUpdate);
ChatCompletion\DelegatingChatClientTests.cs (1)
59ChatResponseUpdate[] expectedResults =
TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
18[JsonSerializable(typeof(ChatResponseUpdate))]
Microsoft.Extensions.AI.AzureAIInference (3)
AzureAIInferenceChatClient.cs (3)
140public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 165ChatResponseUpdate responseUpdate = new() 220var responseUpdate = new ChatResponseUpdate
Microsoft.Extensions.AI.AzureAIInference.Tests (7)
AzureAIInferenceChatClientTests.cs (7)
221List<ChatResponseUpdate> updates = []; 222await foreach (var update in client.GetStreamingResponseAsync(messages, new() 272await foreach (var update in client.GetStreamingResponseAsync("hello", new ChatOptions 453await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 611await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 1335List<ChatResponseUpdate> updates = []; 1336await foreach (var update in client.GetStreamingResponseAsync("How old is Alice?", new()
Microsoft.Extensions.AI.Evaluation.Reporting (6)
ResponseCachingChatClient.cs (3)
64protected override async Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync( 70IReadOnlyList<ChatResponseUpdate>? updates = 122IReadOnlyList<ChatResponseUpdate> value,
SimpleChatClient.cs (3)
58public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 63List<ChatResponseUpdate>? updates = null; 68await foreach (ChatResponseUpdate update in
Microsoft.Extensions.AI.Evaluation.Safety (2)
ContentSafetyChatClient.cs (2)
83public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 109await foreach (var update in
Microsoft.Extensions.AI.Integration.Tests (20)
CallCountingChatClient.cs (1)
26public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatClientIntegrationTests.cs (11)
116await foreach (var chunk in ChatClient.GetStreamingResponseAsync(chatHistory)) 151List<ChatResponseUpdate> chunks = []; 152await foreach (var chunk in response) 281await foreach (var chunk in response) 692await foreach (var update in chatClient.GetStreamingResponseAsync([message])) 701await foreach (var update in chatClient.GetStreamingResponseAsync([message])) 712await foreach (var update in chatClient.GetStreamingResponseAsync([message])) 870await foreach (var update in chatClient.GetStreamingResponseAsync("What's the biggest animal?")) 921await foreach (var update in chatClient.GetStreamingResponseAsync( 1292await foreach (var chunk in chatClient.GetStreamingResponseAsync(messages)) 1394public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
PromptBasedFunctionCallingChatClient.cs (2)
137public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 141foreach (var update in response.ToChatResponseUpdates())
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ToolReductionTests.cs (4)
404return EmptyAsyncEnumerable<ChatResponseUpdate>(); 410await foreach (var _ in client.GetStreamingResponseAsync( 647public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 652public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) =>
Microsoft.Extensions.AI.OpenAI (23)
MicrosoftExtensionsAIChatExtensions.cs (7)
124/// sequence of <see cref="ChatResponseUpdate"/> instances. 128/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 131this IAsyncEnumerable<ChatResponseUpdate> responseUpdates, [EnumeratorCancellation] CancellationToken cancellationToken = default) 135await foreach (var update in responseUpdates.WithCancellation(cancellationToken).ConfigureAwait(false)) 256/// Creates a sequence of Microsoft.Extensions.AI <see cref="ChatResponseUpdate"/> instances from the specified 262/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 264public static IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
MicrosoftExtensionsAIResponsesExtensions.cs (3)
68/// Creates a sequence of Microsoft.Extensions.AI <see cref="ChatResponseUpdate"/> instances from the specified 74/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 76public static IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
OpenAIAssistantsChatClient.cs (3)
73public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 164ChatResponseUpdate ruUpdate = new() 252ChatResponseUpdate textUpdate = new(mcu.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant, mcu.Text)
OpenAIChatClient.cs (4)
98public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 325internal static async IAsyncEnumerable<ChatResponseUpdate> FromOpenAIStreamingChatCompletionAsync( 349ChatResponseUpdate responseUpdate = new() 416ChatResponseUpdate responseUpdate = new()
OpenAIResponsesChatClient.cs (6)
252public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 278internal static async IAsyncEnumerable<ChatResponseUpdate> FromOpenAIStreamingResponseUpdatesAsync( 298ChatResponseUpdate CreateUpdate(AIContent? content = null) => 363var update = CreateUpdate(ToUsageDetails(completedUpdate.Response) is { } usage ? new UsageContent(usage) : null); 397var mcpUpdate = CreateUpdate(); 418var codeUpdate = CreateUpdate();
Microsoft.Extensions.AI.OpenAI.Tests (57)
OpenAIChatClientTests.cs (8)
232List<ChatResponseUpdate> updates = []; 233await foreach (var update in client.GetStreamingResponseAsync("hello", new() 494await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 649await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 1322List<ChatResponseUpdate> updates = []; 1323await foreach (var update in client.GetStreamingResponseAsync("How old is Alice?", new() 1723List<ChatResponseUpdate> updates = []; 1724await foreach (var update in client.GetStreamingResponseAsync("hello", new()
OpenAIConversionTests.cs (12)
630List<ChatResponseUpdate> updates = []; 631await foreach (var update in CreateUpdates().AsChatResponseUpdatesAsync()) 931var asyncEnumerable = ((IAsyncEnumerable<ChatResponseUpdate>)null!).AsOpenAIStreamingChatCompletionUpdatesAsync(); 938var updates = new List<ChatResponseUpdate>(); 960var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello") 978var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!") 1007var responseUpdate = new ChatResponseUpdate 1046var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent]) 1081var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2]) 1109var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, 1157var responseUpdate = new ChatResponseUpdate(inputRole, "Test message"); 1183var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test")
OpenAIResponseClientIntegrationTests.cs (4)
297await foreach (var update in ChatClient.GetStreamingResponseAsync("What is the capital of France?", chatOptions)) 320await foreach (var update in ChatClient.GetStreamingResponseAsync("What is the capital of France?", chatOptions)) 336await foreach (var update in ChatClient.GetStreamingResponseAsync([], chatOptions)) 361await foreach (var update in chatClient.GetStreamingResponseAsync("What time is it?", chatOptions))
OpenAIResponseClientTests.cs (33)
295List<ChatResponseUpdate> updates = []; 296await foreach (var update in client.GetStreamingResponseAsync("Calculate the sum of the first 5 positive integers.", new() 432List<ChatResponseUpdate> updates = []; 433await foreach (var update in client.GetStreamingResponseAsync("hello", new() 2075List<ChatResponseUpdate> updates = []; 2076await foreach (var update in client.GetStreamingResponseAsync("hello", new() 2168List<ChatResponseUpdate> updates = []; 2169await foreach (var update in client.GetStreamingResponseAsync([], chatOptions)) 2235await foreach (var update in client.GetStreamingResponseAsync("Please book a hotel for me", chatOptions)) 3033List<ChatResponseUpdate> updates = []; 3034await foreach (var update in client.GetStreamingResponseAsync("hello", new() 3114List<ChatResponseUpdate> updates = []; 3115await foreach (var update in client.GetStreamingResponseAsync("hello", new() 3195List<ChatResponseUpdate> updates = []; 3196await foreach (var update in client.GetStreamingResponseAsync("hello", new() 3273List<ChatResponseUpdate> updates = []; 3274await foreach (var update in client.GetStreamingResponseAsync("hello", new() 3475List<ChatResponseUpdate> updates = []; 3476await foreach (var update in client.GetStreamingResponseAsync("hello", new() 4353List<ChatResponseUpdate> updates = []; 4354await foreach (var update in client.GetStreamingResponseAsync("test")) 4388List<ChatResponseUpdate> updates = []; 4389await foreach (var update in client.GetStreamingResponseAsync("test")) 4423List<ChatResponseUpdate> updates = []; 4424await foreach (var update in client.GetStreamingResponseAsync("test")) 4461List<ChatResponseUpdate> updates = []; 4462await foreach (var update in client.GetStreamingResponseAsync("test")) 4499List<ChatResponseUpdate> updates = []; 4500await foreach (var update in client.GetStreamingResponseAsync("test")) 4505var refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal")); 4557List<ChatResponseUpdate> updates = []; 4558await foreach (var update in client.GetStreamingResponseAsync("test")) 4563var annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0));
Microsoft.Extensions.AI.Tests (40)
ChatCompletion\ConfigureOptionsChatClientTests.cs (3)
89static async IAsyncEnumerable<ChatResponseUpdate> YieldUpdates(ChatResponseUpdate[] updates) 91foreach (var update in updates)
ChatCompletion\DistributedCachingChatClientTest.cs (13)
247List<ChatResponseUpdate> actualUpdate = 260List<ChatResponseUpdate> expectedCachedResponse = 311List<ChatResponseUpdate> expectedResponse = 344ChatResponseUpdate update = Assert.Single(await ToListAsync(result2)); 366List<ChatResponseUpdate> expectedResponse = 416var item = Assert.Single(items); 434List<ChatResponseUpdate> expectedResponse = 482return ToAsyncEnumerableAsync<ChatResponseUpdate>(Task.CompletedTask, 521return ToAsyncEnumerableAsync<ChatResponseUpdate>( 833private static async Task AssertResponsesEqualAsync(IReadOnlyList<ChatResponseUpdate> expected, IAsyncEnumerable<ChatResponseUpdate> actual) 837foreach (var expectedItem in expected) 841var actualItem = actualEnumerator.Current;
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (4)
698async IAsyncEnumerable<ChatResponseUpdate> YieldInnerClientUpdates( 723await foreach (var update in updates) 771async IAsyncEnumerable<ChatResponseUpdate> YieldInnerClientUpdates( 801await foreach (var update in updates)
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
754List<ChatResponseUpdate> updates; 769foreach (var update in updates)
ChatCompletion\LoggingChatClientTests.cs (2)
105static async IAsyncEnumerable<ChatResponseUpdate> GetUpdatesAsync() 117await foreach (var update in client.GetStreamingResponseAsync(
ChatCompletion\OpenTelemetryChatClientTests.cs (4)
61async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 146await foreach (var update in chatClient.GetStreamingResponseAsync(messages, options)) 367async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 405await foreach (var update in chatClient.GetStreamingResponseAsync(messages))
ChatCompletion\ReducingChatClientTests.cs (2)
72var updates = new List<ChatResponseUpdate>(); 73await foreach (var update in client.GetStreamingResponseAsync(originalMessages))
ChatCompletion\UseDelegateChatClientTests.cs (7)
146static async IAsyncEnumerable<ChatResponseUpdate> Impl( 149await foreach (var update in innerClient.GetStreamingResponseAsync(messages, options, cancellationToken)) 217static async IAsyncEnumerable<ChatResponseUpdate> Impl( 220await foreach (var update in innerClient.GetStreamingResponseAsync(messages, options, cancellationToken)) 239private static async IAsyncEnumerable<ChatResponseUpdate> YieldUpdates(params ChatResponseUpdate[] updates) 241foreach (var update in updates)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
15[JsonSerializable(typeof(IReadOnlyList<ChatResponseUpdate>))]
Microsoft.Extensions.DataIngestion.Tests (2)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
57public virtual async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Microsoft.ML.GenAI.LLaMA (1)
Llama3CausalLMChatClient.cs (1)
46public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Microsoft.ML.GenAI.Phi (1)
Phi3\Phi3CausalLMChatClient.cs (1)
51public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Microsoft.ML.GenAI.Samples (2)
MEAI\Llama3_1.cs (1)
49await foreach (var response in client.GetStreamingResponseAsync([chatMessage]))
MEAI\Phi3.cs (1)
39await foreach (var response in client.GetStreamingResponseAsync([chatMessage]))