135 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
634new()
Microsoft.Extensions.AI.Abstractions (2)
Microsoft.Extensions.AI.Abstractions.Tests (73)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (66)
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(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
134new(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
135new(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should win
136new(null, " AI") { MessageId = "msg1", AuthorName = "AI Assistant" }, // Later AuthorName should win
139new(ChatRole.User, "How") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" },
140new(null, " are") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) },
141new(null, " you?") { MessageId = "msg2", AuthorName = "Human User" }, // Later AuthorName should win
144new(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) },
145new(null, " thank you!") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should win
148new(null, " How can I help?"),
222updates.Add(new(null, text));
243updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
270new(null, "A"),
271new(null, "B"),
272new(null, "C"),
273new() { Contents = [new TextReasoningContent("D")] },
274new() { Contents = [new TextReasoningContent("E")] },
275new() { Contents = [new TextReasoningContent("F")] },
276new(null, "G"),
277new(null, "H"),
278new() { Contents = [new TextReasoningContent("I")] },
279new() { Contents = [new TextReasoningContent("J")] },
280new(null, "K"),
281new() { Contents = [new TextReasoningContent("L")] },
282new(null, "M"),
283new(null, "N"),
284new() { Contents = [new TextReasoningContent("O")] },
285new() { Contents = [new TextReasoningContent("P")] },
308new(null, "A"),
309new(null, "B"),
310new(null, "C"),
311new() { Contents = [new TextContent("D") { Annotations = [new()] }] },
312new() { Contents = [new TextContent("E") { Annotations = [new()] }] },
313new() { Contents = [new TextContent("F") { Annotations = [new()] }] },
314new() { Contents = [new TextContent("G") { Annotations = [] }] },
315new() { Contents = [new TextContent("H") { Annotations = [] }] },
316new() { Contents = [new TextContent("I") { Annotations = [new()] }] },
317new() { Contents = [new TextContent("J") { Annotations = [new()] }] },
318new(null, "K"),
319new() { Contents = [new TextContent("L") { Annotations = [new()] }] },
320new(null, "M"),
321new(null, "N"),
322new() { Contents = [new TextContent("O") { Annotations = [new()] }] },
323new() { Contents = [new TextContent("P") { Annotations = [new()] }] },
348new(null, "Hello, "),
349new(null, "world!"),
350new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] },
Microsoft.Extensions.AI.AzureAIInference (2)
Microsoft.Extensions.AI.Evaluation.Safety (1)
Microsoft.Extensions.AI.OpenAI (6)
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIConversionTests.cs (10)
643var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello")
661var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!")
690var responseUpdate = new ChatResponseUpdate
729var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent])
764var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2])
792var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant,
840var responseUpdate = new ChatResponseUpdate(inputRole, "Test message");
866var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test")
887new ChatResponseUpdate(ChatRole.Assistant, "Hello, ")
894new ChatResponseUpdate(ChatRole.Assistant, "world!")
Microsoft.Extensions.AI.Tests (39)
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)
241 references to ChatResponseUpdate
Microsoft.Extensions.AI (47)
ChatCompletion\AnonymousDelegatingChatClient.cs (10)
31private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? _getStreamingResponseFunc;
80Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc)
129public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
136var updates = Channel.CreateBounded<ChatResponseUpdate>(1);
146await foreach (var update in InnerClient.GetStreamingResponseAsync(messages, options, cancellationToken))
167static async IAsyncEnumerable<ChatResponseUpdate> ReadAllAsync(
168ChannelReader<ChatResponseUpdate> channel, [EnumeratorCancellation] CancellationToken cancellationToken)
172while (channel.TryRead(out var update))
189static async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsyncViaGetResponseAsync(Task<ChatResponse> task)
192foreach (var update in response.ToChatResponseUpdates())
Microsoft.Extensions.AI.Abstractions (42)
ChatCompletion\ChatResponseExtensions.cs (23)
20/// Provides extension methods for working with <see cref="ChatResponse"/> and <see cref="ChatResponseUpdate"/> instances.
49/// <param name="updates">The <see cref="ChatResponseUpdate"/> instances to convert to messages and add to the list.</param>
54/// method may use <see cref="ChatResponseUpdate.MessageId"/> to determine message boundaries, as well as coalesce
58public static void AddMessages(this IList<ChatMessage> list, IEnumerable<ChatResponseUpdate> updates)
63if (updates is ICollection<ChatResponseUpdate> { Count: 0 })
73/// <param name="update">The <see cref="ChatResponseUpdate"/> instance to convert to a message and add to the list.</param>
78/// If the <see cref="ChatResponseUpdate"/> has no content, or all its content gets excluded by <paramref name="filter"/>, then
81public static void AddMessages(this IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool>? filter = null)
101/// <param name="updates">The <see cref="ChatResponseUpdate"/> instances to convert to messages and add to the list.</param>
108/// method may use <see cref="ChatResponseUpdate.MessageId"/> to determine message boundaries, as well as coalesce
113this IList<ChatMessage> list, IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken = default)
121IList<ChatMessage> list, IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken) =>
125/// <summary>Combines <see cref="ChatResponseUpdate"/> instances into a single <see cref="ChatResponse"/>.</summary>
131/// <see cref="ChatMessage"/> instances. This includes using <see cref="ChatResponseUpdate.MessageId"/> to determine
136this IEnumerable<ChatResponseUpdate> updates)
142foreach (var update in updates)
152/// <summary>Combines <see cref="ChatResponseUpdate"/> instances into a single <see cref="ChatResponse"/>.</summary>
159/// <see cref="ChatMessage"/> instances. This includes using <see cref="ChatResponseUpdate.MessageId"/> to determine
164this IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken = default)
171IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken)
175await foreach (var update in updates.WithCancellation(cancellationToken).ConfigureAwait(false))
306/// <summary>Processes the <see cref="ChatResponseUpdate"/>, incorporating its contents into <paramref name="response"/>.</summary>
309private static void ProcessUpdate(ChatResponseUpdate update, ChatResponse response)
Microsoft.Extensions.AI.Abstractions.Tests (31)
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 (16)
Microsoft.Extensions.AI.OpenAI (22)
Microsoft.Extensions.AI.OpenAI.Tests (22)
Microsoft.Extensions.AI.Tests (38)
Microsoft.ML.GenAI.Core (1)
Microsoft.ML.GenAI.LLaMA (1)
Microsoft.ML.GenAI.Phi (1)
Microsoft.ML.GenAI.Samples (2)