216 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
628new()
Microsoft.Extensions.AI.Abstractions (2)
Microsoft.Extensions.AI.Abstractions.Tests (145)
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 },
Microsoft.Extensions.AI.AzureAIInference (2)
Microsoft.Extensions.AI.Evaluation.Safety (1)
Microsoft.Extensions.AI.OpenAI (8)
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\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")]);
Microsoft.ML.GenAI.Core (1)
303 references to ChatResponseUpdate
Aspire.Dashboard (2)
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())
Microsoft.Extensions.AI.Abstractions (43)
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)
Microsoft.Extensions.AI.Abstractions.Tests (43)
Microsoft.Extensions.AI.AzureAIInference (3)
Microsoft.Extensions.AI.AzureAIInference.Tests (7)
Microsoft.Extensions.AI.Evaluation.Reporting (6)
Microsoft.Extensions.AI.Evaluation.Safety (2)
Microsoft.Extensions.AI.Integration.Tests (20)
Microsoft.Extensions.AI.OpenAI (23)
Microsoft.Extensions.AI.OpenAI.Tests (57)
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)
Microsoft.Extensions.DataIngestion.Tests (2)
Microsoft.ML.GenAI.Core (1)
Microsoft.ML.GenAI.LLaMA (1)
Microsoft.ML.GenAI.Phi (1)
Microsoft.ML.GenAI.Samples (2)