232 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
631new()
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatResponseUpdate.cs (1)
69new()
Microsoft.Extensions.AI.Abstractions.Tests (160)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (147)
32new(ChatRole.Assistant, "Hello") { ResponseId = "someResponse", MessageId = "12345", CreatedAt = new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model123" },
33new(ChatRole.Assistant, ", ") { AuthorName = "Someone", AdditionalProperties = new() { ["a"] = "b" } },
34new(null, "world!") { CreatedAt = new DateTimeOffset(2, 2, 3, 4, 5, 6, TimeSpan.Zero), ConversationId = "123", AdditionalProperties = new() { ["c"] = "d" } },
36new() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] },
37new() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] },
76new(null, "!") { MessageId = "1" },
77new(ChatRole.Assistant, "a") { MessageId = "1" },
78new(ChatRole.Assistant, "b") { MessageId = "2" },
79new(ChatRole.User, "c") { MessageId = "2" },
80new(ChatRole.User, "d") { MessageId = "2" },
81new(ChatRole.Assistant, "e") { MessageId = "3" },
82new(ChatRole.Tool, "f") { MessageId = "4" },
83new(ChatRole.Tool, "g") { MessageId = "4" },
84new(ChatRole.Tool, "h") { MessageId = "5" },
85new(new("human"), "i") { MessageId = "6" },
86new(new("human"), "j") { MessageId = "7" },
87new(new("human"), "k") { MessageId = "7" },
88new(null, "l") { MessageId = "7" },
89new(null, "m") { MessageId = "8" },
134new(ChatRole.Assistant, "Hello ") { AuthorName = "Alice" },
135new(null, "from ") { AuthorName = "Alice" },
136new(null, "Alice!"),
139new(null, "Hi ") { AuthorName = "Bob" },
140new(null, "from ") { AuthorName = "Bob" },
141new(null, "Bob!"),
144new(ChatRole.Assistant, "Greetings ") { AuthorName = "Charlie" },
145new(null, "from Charlie!") { AuthorName = "Charlie" },
148new(null, "Alice again!") { AuthorName = "Alice" },
151new(null, " Still Alice.") { AuthorName = "" },
152new(null, " And more."),
187new(ChatRole.Assistant, "A") { MessageId = "1", AuthorName = "Alice" },
188new(null, "B") { MessageId = "1", AuthorName = "Alice" },
191new(null, "C") { MessageId = "1", AuthorName = "Bob" },
194new(null, "D") { MessageId = "2", AuthorName = "Bob" },
195new(null, "E") { MessageId = "2", AuthorName = "Bob" },
198new(ChatRole.User, "F") { MessageId = "2", AuthorName = "Bob" },
201new(ChatRole.Tool, "G") { MessageId = "3", AuthorName = "Charlie" },
202new(null, "H") { MessageId = "3", AuthorName = "Charlie" },
246new(ChatRole.Assistant, "Hello") { AuthorName = "Assistant" },
249new(null, " world") { AuthorName = "" },
252new(null, "!"),
255new(null, " How") { AuthorName = "" },
256new(null, " are") { AuthorName = "" },
259new(null, " you?") { AuthorName = null },
281new(ChatRole.Assistant, "Hello") { MessageId = "1" },
282new(null, " there") { MessageId = "1" },
285new(null, " I'm Bob") { MessageId = "1", AuthorName = "Bob" },
286new(null, " speaking") { MessageId = "1", AuthorName = "Bob" },
289new(null, "Now Alice") { MessageId = "1", AuthorName = "Alice" },
316new(ChatRole.Assistant, "Hello"),
317new(null, " there"),
320new(null, " from") { MessageId = "msg1" },
321new(null, " AI") { MessageId = "msg1" },
324new(null, "Next message") { MessageId = "msg2" },
351new(ChatRole.Assistant, "Hello") { MessageId = "msg1" },
352new(null, " world") { MessageId = "msg1" },
355new(null, "!") { MessageId = "" },
358new(null, " How"),
361new(null, " are") { MessageId = "" },
362new(null, " you?"),
384new(null, "Hello") { MessageId = "1" },
385new(null, " there") { MessageId = "1" },
388new(ChatRole.Assistant, " from") { MessageId = "1" },
389new(null, " AI") { MessageId = "1" },
392new(ChatRole.User, "User message") { MessageId = "1" },
419new(new ChatRole("agent1"), "Hello") { MessageId = "1" },
420new(null, " from") { MessageId = "1" },
421new(new ChatRole("agent1"), " agent1") { MessageId = "1" },
424new(new ChatRole("agent2"), "Hi") { MessageId = "1" },
425new(null, " from") { MessageId = "1" },
426new(new ChatRole("agent2"), " agent2") { MessageId = "1" },
429new(ChatRole.Assistant, "Assistant here") { MessageId = "1" },
457new(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
458new(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
459new(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should win
460new(null, " AI") { MessageId = "msg1", AuthorName = "Assistant" }, // Keep same AuthorName to avoid creating new message
463new(null, "More text") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 2, 0, TimeSpan.Zero), AuthorName = "Assistant" },
466new(ChatRole.User, "How") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" },
467new(null, " are") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) },
468new(null, " you?") { MessageId = "msg3", AuthorName = "User" }, // Keep same AuthorName
471new(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) },
472new(null, " thank you!") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should win
475new(null, " How can I help?"),
557updates.Add(new(null, text));
578updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
605new(null, "A"),
606new(null, "B"),
607new(null, "C"),
608new() { Contents = [new TextReasoningContent("D")] },
609new() { Contents = [new TextReasoningContent("E")] },
610new() { Contents = [new TextReasoningContent("F")] },
611new(null, "G"),
612new(null, "H"),
613new() { Contents = [new TextReasoningContent("I")] },
614new() { Contents = [new TextReasoningContent("J")] },
615new(null, "K"),
616new() { Contents = [new TextReasoningContent("L")] },
617new(null, "M"),
618new(null, "N"),
619new() { Contents = [new TextReasoningContent("O")] },
620new() { Contents = [new TextReasoningContent("P")] },
643new() { Contents = [new TextReasoningContent("A") { ProtectedData = "1" }] },
644new() { Contents = [new TextReasoningContent("B") { ProtectedData = "2" }] },
645new() { Contents = [new TextReasoningContent("C")] },
646new() { Contents = [new TextReasoningContent("D")] },
647new() { Contents = [new TextReasoningContent("E") { ProtectedData = "3" }] },
648new() { Contents = [new TextReasoningContent("F") { ProtectedData = "4" }] },
649new() { Contents = [new TextReasoningContent("G")] },
650new() { Contents = [new TextReasoningContent("H")] },
680new(null, "A"),
681new(null, "B"),
682new(null, "C"),
683new() { Contents = [new TextContent("D") { Annotations = [new()] }] },
684new() { Contents = [new TextContent("E") { Annotations = [new()] }] },
685new() { Contents = [new TextContent("F") { Annotations = [new()] }] },
686new() { Contents = [new TextContent("G") { Annotations = [] }] },
687new() { Contents = [new TextContent("H") { Annotations = [] }] },
688new() { Contents = [new TextContent("I") { Annotations = [new()] }] },
689new() { Contents = [new TextContent("J") { Annotations = [new()] }] },
690new(null, "K"),
691new() { Contents = [new TextContent("L") { Annotations = [new()] }] },
692new(null, "M"),
693new(null, "N"),
694new() { Contents = [new TextContent("O") { Annotations = [new()] }] },
695new() { Contents = [new TextContent("P") { Annotations = [new()] }] },
720new(null, "Hello, "),
721new(null, "world!"),
722new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] },
749new(ChatRole.Tool, "a") { MessageId = "4", CreatedAt = early },
752new(null, "b") { CreatedAt = unixEpoch },
755new(null, "c") { CreatedAt = middle },
758new(null, "d") { CreatedAt = early },
761new(null, "e") { CreatedAt = late },
764new(null, "f") { CreatedAt = unixEpoch },
767new(null, "g") { CreatedAt = null },
813new(ChatRole.Assistant, "a") { CreatedAt = first },
814new(null, "b") { CreatedAt = second },
840new(null, "Let's generate"),
841new(null, " some images"),
844new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image1] }] },
847new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image2] }] },
850new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image3] }] },
853new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image4] }] },
856new(null, "Here are those generated images"),
898new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image1] }] },
901new() { Contents = [new ImageGenerationToolResultContent { ImageId = "", Outputs = [image2] }] },
904new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image3] }] },
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 (48)
ChatCompletion\DistributedCachingChatClientTest.cs (16)
250new()
263new()
268new()
314new(ChatRole.Assistant, "This"),
315new(ChatRole.Assistant, " becomes one chunk"),
316new() { Role = ChatRole.Assistant, Contents = [new FunctionCallContent("callId1", "separator")] },
317new(ChatRole.Assistant, "... and this"),
318new(ChatRole.Assistant, " becomes another"),
319new(ChatRole.Assistant, " one."),
369new() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] },
370new() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] },
371new()
382new()
437new(ChatRole.Assistant, "Chunk 1"),
485() => new(ChatRole.Assistant, "Chunk 1"),
524[() => new(ChatRole.Assistant, "A good result")]);
Microsoft.ML.GenAI.Core (1)
340 references to ChatResponseUpdate
Aspire.Dashboard (2)
Microsoft.Extensions.AI (53)
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 (45)
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))
482/// <summary>Processes the <see cref="ChatResponseUpdate"/>, incorporating its contents into <paramref name="response"/>.</summary>
485private static void ProcessUpdate(ChatResponseUpdate update, ChatResponse response)
Microsoft.Extensions.AI.Abstractions.Tests (55)
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 (81)
OpenAIResponseClientTests.cs (57)
295List<ChatResponseUpdate> updates = [];
296await foreach (var update in client.GetStreamingResponseAsync("Calculate the sum of the first 5 positive integers.", new()
428List<ChatResponseUpdate> updates = [];
429await foreach (var update in client.GetStreamingResponseAsync("Solve this problem step by step.", new()
471var assistantUpdate = updates.First(u => u.Role == ChatRole.Assistant && !string.IsNullOrEmpty(u.Text));
559List<ChatResponseUpdate> updates = [];
560await foreach (var update in client.GetStreamingResponseAsync("hello", new()
798List<ChatResponseUpdate> updates = [];
799await foreach (var update in client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "Search the web for the temperature today in Fremont")], chatOptions))
2434List<ChatResponseUpdate> updates = [];
2435await foreach (var update in client.GetStreamingResponseAsync("hello", new()
2527List<ChatResponseUpdate> updates = [];
2528await foreach (var update in client.GetStreamingResponseAsync([], chatOptions))
2594await foreach (var update in client.GetStreamingResponseAsync("Please book a hotel for me", chatOptions))
3392List<ChatResponseUpdate> updates = [];
3393await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3473List<ChatResponseUpdate> updates = [];
3474await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3554List<ChatResponseUpdate> updates = [];
3555await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3632List<ChatResponseUpdate> updates = [];
3633await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3834List<ChatResponseUpdate> updates = [];
3835await foreach (var update in client.GetStreamingResponseAsync("hello", new()
4716List<ChatResponseUpdate> updates = [];
4717await foreach (var update in client.GetStreamingResponseAsync("test"))
4751List<ChatResponseUpdate> updates = [];
4752await foreach (var update in client.GetStreamingResponseAsync("test"))
4786List<ChatResponseUpdate> updates = [];
4787await foreach (var update in client.GetStreamingResponseAsync("test"))
4824List<ChatResponseUpdate> updates = [];
4825await foreach (var update in client.GetStreamingResponseAsync("test"))
4862List<ChatResponseUpdate> updates = [];
4863await foreach (var update in client.GetStreamingResponseAsync("test"))
4868var refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal"));
4920List<ChatResponseUpdate> updates = [];
4921await foreach (var update in client.GetStreamingResponseAsync("test"))
4926var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent));
4963List<ChatResponseUpdate> updates = [];
4964await foreach (var update in client.GetStreamingResponseAsync("test"))
4969var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent));
5006List<ChatResponseUpdate> updates = [];
5007await foreach (var update in client.GetStreamingResponseAsync("test"))
5012var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent));
5049List<ChatResponseUpdate> updates = [];
5050await foreach (var update in client.GetStreamingResponseAsync("test"))
5055var annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0));
5292List<ChatResponseUpdate> updates = [];
5302await foreach (var update in client.GetStreamingResponseAsync("Generate an image of a dog", new ChatOptions
5313var createdUpdate = updates.First(u => u.CreatedAt.HasValue);
5318var toolCallUpdate = updates.FirstOrDefault(u =>
5325var partialImageUpdate = updates.FirstOrDefault(u =>
5331var completionUpdate = updates.FirstOrDefault(u =>
5410List<ChatResponseUpdate> updates = [];
5421await foreach (var update in client.GetStreamingResponseAsync("Generate an image of a sunset", new ChatOptions
5441var partialUpdate = partialImageUpdates.FirstOrDefault(u =>
5478var toolCallUpdate = updates.FirstOrDefault(u =>
Microsoft.Extensions.AI.Tests (46)
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)