234 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
628new()
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatResponseUpdate.cs (1)
69new()
Microsoft.Extensions.AI.Abstractions.Tests (160)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (147)
31new(ChatRole.Assistant, "Hello") { ResponseId = "someResponse", MessageId = "12345", CreatedAt = new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model123" },
32new(ChatRole.Assistant, ", ") { AuthorName = "Someone", AdditionalProperties = new() { ["a"] = "b" } },
33new(null, "world!") { CreatedAt = new DateTimeOffset(2, 2, 3, 4, 5, 6, TimeSpan.Zero), ConversationId = "123", AdditionalProperties = new() { ["c"] = "d" } },
35new() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] },
36new() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] },
75new(null, "!") { MessageId = "1" },
76new(ChatRole.Assistant, "a") { MessageId = "1" },
77new(ChatRole.Assistant, "b") { MessageId = "2" },
78new(ChatRole.User, "c") { MessageId = "2" },
79new(ChatRole.User, "d") { MessageId = "2" },
80new(ChatRole.Assistant, "e") { MessageId = "3" },
81new(ChatRole.Tool, "f") { MessageId = "4" },
82new(ChatRole.Tool, "g") { MessageId = "4" },
83new(ChatRole.Tool, "h") { MessageId = "5" },
84new(new("human"), "i") { MessageId = "6" },
85new(new("human"), "j") { MessageId = "7" },
86new(new("human"), "k") { MessageId = "7" },
87new(null, "l") { MessageId = "7" },
88new(null, "m") { MessageId = "8" },
133new(ChatRole.Assistant, "Hello ") { AuthorName = "Alice" },
134new(null, "from ") { AuthorName = "Alice" },
135new(null, "Alice!"),
138new(null, "Hi ") { AuthorName = "Bob" },
139new(null, "from ") { AuthorName = "Bob" },
140new(null, "Bob!"),
143new(ChatRole.Assistant, "Greetings ") { AuthorName = "Charlie" },
144new(null, "from Charlie!") { AuthorName = "Charlie" },
147new(null, "Alice again!") { AuthorName = "Alice" },
150new(null, " Still Alice.") { AuthorName = "" },
151new(null, " And more."),
186new(ChatRole.Assistant, "A") { MessageId = "1", AuthorName = "Alice" },
187new(null, "B") { MessageId = "1", AuthorName = "Alice" },
190new(null, "C") { MessageId = "1", AuthorName = "Bob" },
193new(null, "D") { MessageId = "2", AuthorName = "Bob" },
194new(null, "E") { MessageId = "2", AuthorName = "Bob" },
197new(ChatRole.User, "F") { MessageId = "2", AuthorName = "Bob" },
200new(ChatRole.Tool, "G") { MessageId = "3", AuthorName = "Charlie" },
201new(null, "H") { MessageId = "3", AuthorName = "Charlie" },
245new(ChatRole.Assistant, "Hello") { AuthorName = "Assistant" },
248new(null, " world") { AuthorName = "" },
251new(null, "!"),
254new(null, " How") { AuthorName = "" },
255new(null, " are") { AuthorName = "" },
258new(null, " you?") { AuthorName = null },
280new(ChatRole.Assistant, "Hello") { MessageId = "1" },
281new(null, " there") { MessageId = "1" },
284new(null, " I'm Bob") { MessageId = "1", AuthorName = "Bob" },
285new(null, " speaking") { MessageId = "1", AuthorName = "Bob" },
288new(null, "Now Alice") { MessageId = "1", AuthorName = "Alice" },
315new(ChatRole.Assistant, "Hello"),
316new(null, " there"),
319new(null, " from") { MessageId = "msg1" },
320new(null, " AI") { MessageId = "msg1" },
323new(null, "Next message") { MessageId = "msg2" },
350new(ChatRole.Assistant, "Hello") { MessageId = "msg1" },
351new(null, " world") { MessageId = "msg1" },
354new(null, "!") { MessageId = "" },
357new(null, " How"),
360new(null, " are") { MessageId = "" },
361new(null, " you?"),
383new(null, "Hello") { MessageId = "1" },
384new(null, " there") { MessageId = "1" },
387new(ChatRole.Assistant, " from") { MessageId = "1" },
388new(null, " AI") { MessageId = "1" },
391new(ChatRole.User, "User message") { MessageId = "1" },
418new(new ChatRole("agent1"), "Hello") { MessageId = "1" },
419new(null, " from") { MessageId = "1" },
420new(new ChatRole("agent1"), " agent1") { MessageId = "1" },
423new(new ChatRole("agent2"), "Hi") { MessageId = "1" },
424new(null, " from") { MessageId = "1" },
425new(new ChatRole("agent2"), " agent2") { MessageId = "1" },
428new(ChatRole.Assistant, "Assistant here") { MessageId = "1" },
456new(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
457new(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
458new(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should win
459new(null, " AI") { MessageId = "msg1", AuthorName = "Assistant" }, // Keep same AuthorName to avoid creating new message
462new(null, "More text") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 2, 0, TimeSpan.Zero), AuthorName = "Assistant" },
465new(ChatRole.User, "How") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" },
466new(null, " are") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) },
467new(null, " you?") { MessageId = "msg3", AuthorName = "User" }, // Keep same AuthorName
470new(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) },
471new(null, " thank you!") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should win
474new(null, " How can I help?"),
556updates.Add(new(null, text));
577updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
604new(null, "A"),
605new(null, "B"),
606new(null, "C"),
607new() { Contents = [new TextReasoningContent("D")] },
608new() { Contents = [new TextReasoningContent("E")] },
609new() { Contents = [new TextReasoningContent("F")] },
610new(null, "G"),
611new(null, "H"),
612new() { Contents = [new TextReasoningContent("I")] },
613new() { Contents = [new TextReasoningContent("J")] },
614new(null, "K"),
615new() { Contents = [new TextReasoningContent("L")] },
616new(null, "M"),
617new(null, "N"),
618new() { Contents = [new TextReasoningContent("O")] },
619new() { Contents = [new TextReasoningContent("P")] },
642new() { Contents = [new TextReasoningContent("A") { ProtectedData = "1" }] },
643new() { Contents = [new TextReasoningContent("B") { ProtectedData = "2" }] },
644new() { Contents = [new TextReasoningContent("C")] },
645new() { Contents = [new TextReasoningContent("D")] },
646new() { Contents = [new TextReasoningContent("E") { ProtectedData = "3" }] },
647new() { Contents = [new TextReasoningContent("F") { ProtectedData = "4" }] },
648new() { Contents = [new TextReasoningContent("G")] },
649new() { Contents = [new TextReasoningContent("H")] },
679new(null, "A"),
680new(null, "B"),
681new(null, "C"),
682new() { Contents = [new TextContent("D") { Annotations = [new()] }] },
683new() { Contents = [new TextContent("E") { Annotations = [new()] }] },
684new() { Contents = [new TextContent("F") { Annotations = [new()] }] },
685new() { Contents = [new TextContent("G") { Annotations = [] }] },
686new() { Contents = [new TextContent("H") { Annotations = [] }] },
687new() { Contents = [new TextContent("I") { Annotations = [new()] }] },
688new() { Contents = [new TextContent("J") { Annotations = [new()] }] },
689new(null, "K"),
690new() { Contents = [new TextContent("L") { Annotations = [new()] }] },
691new(null, "M"),
692new(null, "N"),
693new() { Contents = [new TextContent("O") { Annotations = [new()] }] },
694new() { Contents = [new TextContent("P") { Annotations = [new()] }] },
719new(null, "Hello, "),
720new(null, "world!"),
721new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] },
748new(ChatRole.Tool, "a") { MessageId = "4", CreatedAt = early },
751new(null, "b") { CreatedAt = unixEpoch },
754new(null, "c") { CreatedAt = middle },
757new(null, "d") { CreatedAt = early },
760new(null, "e") { CreatedAt = late },
763new(null, "f") { CreatedAt = unixEpoch },
766new(null, "g") { CreatedAt = null },
812new(ChatRole.Assistant, "a") { CreatedAt = first },
813new(null, "b") { CreatedAt = second },
839new(null, "Let's generate"),
840new(null, " some images"),
843new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image1] }] },
846new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image2] }] },
849new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image3] }] },
852new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image4] }] },
855new(null, "Here are those generated images"),
897new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image1] }] },
900new() { Contents = [new ImageGenerationToolResultContent { ImageId = "", Outputs = [image2] }] },
903new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image3] }] },
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 (48)
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)
336 references to ChatResponseUpdate
Aspire.Dashboard (2)
Microsoft.Extensions.AI (50)
ChatCompletion\AnonymousDelegatingChatClient.cs (7)
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))
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.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 (70)
OpenAIResponseClientTests.cs (46)
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()
2202List<ChatResponseUpdate> updates = [];
2203await foreach (var update in client.GetStreamingResponseAsync("hello", new()
2295List<ChatResponseUpdate> updates = [];
2296await foreach (var update in client.GetStreamingResponseAsync([], chatOptions))
2362await foreach (var update in client.GetStreamingResponseAsync("Please book a hotel for me", chatOptions))
3160List<ChatResponseUpdate> updates = [];
3161await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3241List<ChatResponseUpdate> updates = [];
3242await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3322List<ChatResponseUpdate> updates = [];
3323await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3400List<ChatResponseUpdate> updates = [];
3401await foreach (var update in client.GetStreamingResponseAsync("hello", new()
3602List<ChatResponseUpdate> updates = [];
3603await foreach (var update in client.GetStreamingResponseAsync("hello", new()
4484List<ChatResponseUpdate> updates = [];
4485await foreach (var update in client.GetStreamingResponseAsync("test"))
4519List<ChatResponseUpdate> updates = [];
4520await foreach (var update in client.GetStreamingResponseAsync("test"))
4554List<ChatResponseUpdate> updates = [];
4555await foreach (var update in client.GetStreamingResponseAsync("test"))
4592List<ChatResponseUpdate> updates = [];
4593await foreach (var update in client.GetStreamingResponseAsync("test"))
4630List<ChatResponseUpdate> updates = [];
4631await foreach (var update in client.GetStreamingResponseAsync("test"))
4636var refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal"));
4688List<ChatResponseUpdate> updates = [];
4689await foreach (var update in client.GetStreamingResponseAsync("test"))
4694var annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0));
4931List<ChatResponseUpdate> updates = [];
4941await foreach (var update in client.GetStreamingResponseAsync("Generate an image of a dog", new ChatOptions
4952var createdUpdate = updates.First(u => u.CreatedAt.HasValue);
4957var toolCallUpdate = updates.FirstOrDefault(u =>
4964var partialImageUpdate = updates.FirstOrDefault(u =>
4970var completionUpdate = updates.FirstOrDefault(u =>
5049List<ChatResponseUpdate> updates = [];
5060await foreach (var update in client.GetStreamingResponseAsync("Generate an image of a sunset", new ChatOptions
5080var partialUpdate = partialImageUpdates.FirstOrDefault(u =>
5117var 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)