114 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
Microsoft.Extensions.AI.Abstractions (2)
Microsoft.Extensions.AI.Abstractions.Tests (59)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (52)
31new(ChatRole.Assistant, "Hello") { ResponseId = "someResponse", MessageId = "12345", CreatedAt = new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model123" },
32new(new("human"), ", ") { 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 })] },
77new(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
78new(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
79new(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should win
80new(null, " AI") { MessageId = "msg1", AuthorName = "AI Assistant" }, // Later AuthorName should win
83new(ChatRole.User, "How") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" },
84new(null, " are") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) },
85new(null, " you?") { MessageId = "msg2", AuthorName = "Human User" }, // Later AuthorName should win
88new(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) },
89new(null, " thank you!") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should win
92new(null, " How can I help?"),
166updates.Add(new(null, text));
187updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
214new(null, "A"),
215new(null, "B"),
216new(null, "C"),
217new() { Contents = [new TextReasoningContent("D")] },
218new() { Contents = [new TextReasoningContent("E")] },
219new() { Contents = [new TextReasoningContent("F")] },
220new(null, "G"),
221new(null, "H"),
222new() { Contents = [new TextReasoningContent("I")] },
223new() { Contents = [new TextReasoningContent("J")] },
224new(null, "K"),
225new() { Contents = [new TextReasoningContent("L")] },
226new(null, "M"),
227new(null, "N"),
228new() { Contents = [new TextReasoningContent("O")] },
229new() { Contents = [new TextReasoningContent("P")] },
252new(null, "A"),
253new(null, "B"),
254new(null, "C"),
255new() { Contents = [new TextContent("D") { Annotations = [new()] }] },
256new() { Contents = [new TextContent("E") { Annotations = [new()] }] },
257new() { Contents = [new TextContent("F") { Annotations = [new()] }] },
258new() { Contents = [new TextContent("G") { Annotations = [] }] },
259new() { Contents = [new TextContent("H") { Annotations = [] }] },
260new() { Contents = [new TextContent("I") { Annotations = [new()] }] },
261new() { Contents = [new TextContent("J") { Annotations = [new()] }] },
262new(null, "K"),
263new() { Contents = [new TextContent("L") { Annotations = [new()] }] },
264new(null, "M"),
265new(null, "N"),
266new() { Contents = [new TextContent("O") { Annotations = [new()] }] },
267new() { Contents = [new TextContent("P") { Annotations = [new()] }] },
292new(null, "Hello, "),
293new(null, "world!"),
294new() { 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)
572var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello")
590var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!")
619var responseUpdate = new ChatResponseUpdate
658var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent])
693var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2])
721var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant,
769var responseUpdate = new ChatResponseUpdate(inputRole, "Test message");
795var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test")
816new ChatResponseUpdate(ChatRole.Assistant, "Hello, ")
823new ChatResponseUpdate(ChatRole.Assistant, "world!")
Microsoft.Extensions.AI.Tests (32)
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)
229 references to ChatResponseUpdate
Microsoft.Extensions.AI (43)
ChatCompletion\AnonymousDelegatingChatClient.cs (7)
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))
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))
300/// <summary>Processes the <see cref="ChatResponseUpdate"/>, incorporating its contents into <paramref name="response"/>.</summary>
303private static void ProcessUpdate(ChatResponseUpdate update, ChatResponse response)
Microsoft.Extensions.AI.Abstractions.Tests (30)
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 (21)
Microsoft.Extensions.AI.OpenAI.Tests (20)
Microsoft.Extensions.AI.Tests (34)
Microsoft.ML.GenAI.Core (1)
Microsoft.ML.GenAI.LLaMA (1)
Microsoft.ML.GenAI.Phi (1)
Microsoft.ML.GenAI.Samples (2)