135 instantiations of ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
634new()
Microsoft.Extensions.AI.Abstractions (2)
ChatCompletion\ChatResponse.cs (2)
113extra = new ChatResponseUpdate 131updates[i] = new ChatResponseUpdate
Microsoft.Extensions.AI.Abstractions.Tests (73)
ChatCompletion\ChatClientExtensionsTests.cs (1)
146return YieldAsync([new ChatResponseUpdate(ChatRole.Assistant, "world")]);
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 })] },
ChatCompletion\ChatResponseUpdateTests.cs (4)
16ChatResponseUpdate update = new(); 33ChatResponseUpdate update = new(); 87ChatResponseUpdate update = new() 115ChatResponseUpdate original = new()
ChatCompletion\DelegatingChatClientTests.cs (2)
61new(ChatRole.User, "Message 1"), 62new(ChatRole.User, "Message 2")
Microsoft.Extensions.AI.AzureAIInference (2)
AzureAIInferenceChatClient.cs (2)
166ChatResponseUpdate responseUpdate = new() 228var responseUpdate = new ChatResponseUpdate
Microsoft.Extensions.AI.Evaluation.Safety (1)
ContentSafetyChatClient.cs (1)
105yield return new ChatResponseUpdate(ChatRole.Assistant, annotationResult)
Microsoft.Extensions.AI.OpenAI (6)
OpenAIAssistantsChatClient.cs (3)
174ChatResponseUpdate ruUpdate = new() 210ChatResponseUpdate textUpdate = new(mcu.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant, mcu.Text) 259yield return new()
OpenAIChatClient.cs (2)
321ChatResponseUpdate responseUpdate = new() 388ChatResponseUpdate responseUpdate = new()
OpenAIResponsesChatClient.cs (1)
226new(lastRole, content is not null ? [content] : null)
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 (39)
ChatCompletion\ConfigureOptionsChatClientTests.cs (1)
38var expectedUpdates = Enumerable.Range(0, 3).Select(i => new ChatResponseUpdate()).ToArray();
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")]);
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (7)
643yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId }; 646new ChatResponseUpdate( 716yield return new ChatResponseUpdate(ChatRole.Assistant, [new TextContent("Text 1")]) { MessageId = messageId }; 718yield return new ChatResponseUpdate(ChatRole.Assistant, [new TextContent("Text 2")]) { MessageId = messageId }; 720yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId }; 722yield return new ChatResponseUpdate( 729yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func3")]) { MessageId = messageId };
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
742new() { Contents = [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["text"] = "Input 1" })] }, 743new() { Contents = [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["text"] = "Input 2" })] } 748updates = [new() { Contents = [new TextContent("OK bye")] }];
ChatCompletion\LoggingChatClientTests.cs (2)
108yield return new(ChatRole.Assistant, "blue "); 109yield return new(ChatRole.Assistant, "whale");
ChatCompletion\OpenTelemetryChatClientTests.cs (3)
69yield return new ChatResponseUpdate(ChatRole.Assistant, text) 75yield return new ChatResponseUpdate 80yield return new ChatResponseUpdate
ChatCompletion\ReducingChatClientTests.cs (2)
50var expectedUpdates = new[] { new ChatResponseUpdate(ChatRole.Assistant, "It's"), new ChatResponseUpdate(null, " sunny!") };
ChatCompletion\UseDelegateChatClientTests.cs (5)
51return YieldUpdates(new ChatResponseUpdate(null, "world")); 133return YieldUpdates(new ChatResponseUpdate(null, "hello")); 154yield return new(null, " world"); 193return YieldUpdates(new ChatResponseUpdate(null, "streaming hello")); 225yield return new(null, " world (streaming)");
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
73yield return new(ChatRole.Assistant, output)
238 references to ChatResponseUpdate
Microsoft.Extensions.AI (44)
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())
ChatCompletion\CachingChatClient.cs (12)
77public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 87private async IAsyncEnumerable<ChatResponseUpdate> GetCachedStreamingResponseAsync( 100foreach (var chunk in chatResponse.ToChatResponseUpdates()) 108List<ChatResponseUpdate> capturedItems = []; 109await foreach (var chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 126foreach (var chunk in existingChunks) 135List<ChatResponseUpdate> capturedItems = []; 136await foreach (var chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 166/// Returns a previously cached list of <see cref="ChatResponseUpdate"/> values, if available. 173protected abstract Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken); 188/// Stores a list of <see cref="ChatResponseUpdate"/> values in the underlying cache. 197protected abstract Task WriteCacheStreamingAsync(string key, IReadOnlyList<ChatResponseUpdate> value, CancellationToken cancellationToken);
ChatCompletion\ChatClientBuilder.cs (1)
144Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc)
ChatCompletion\ConfigureOptionsChatClient.cs (2)
42public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 45await foreach (var update in base.GetStreamingResponseAsync(messages, Configure(options), cancellationToken))
ChatCompletion\DistributedCachingChatClient.cs (6)
26/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>, 91protected override async Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken) 98return (IReadOnlyList<ChatResponseUpdate>?)JsonSerializer.Deserialize(existingJson, _jsonSerializerOptions.GetTypeInfo(typeof(IReadOnlyList<ChatResponseUpdate>))); 116protected override async Task WriteCacheStreamingAsync(string key, IReadOnlyList<ChatResponseUpdate> value, CancellationToken cancellationToken) 122var newJson = JsonSerializer.SerializeToUtf8Bytes(value, _jsonSerializerOptions.GetTypeInfo(typeof(IReadOnlyList<ChatResponseUpdate>)));
ChatCompletion\DistributedCachingChatClientBuilderExtensions.cs (1)
29/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>,
ChatCompletion\FunctionInvokingChatClient.cs (6)
418public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 438List<ChatResponseUpdate> updates = []; // updates from the current response 504await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 508Throw.InvalidOperationException($"The inner {nameof(IChatClient)} streamed a null {nameof(ChatResponseUpdate)}."); 572var updateToYield = updates[lastYieldedUpdateIndex]; 633private static ChatResponseUpdate ConvertToolResultMessageToUpdate(ChatMessage message, string? conversationId, string? messageId) =>
ChatCompletion\LoggingChatClient.cs (3)
100public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 115IAsyncEnumerator<ChatResponseUpdate> e; 133ChatResponseUpdate? update = null;
ChatCompletion\OpenTelemetryChatClient.cs (4)
161public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 173IAsyncEnumerable<ChatResponseUpdate> updates; 185List<ChatResponseUpdate> trackedUpdates = []; 191ChatResponseUpdate update;
ChatCompletion\ReducingChatClient.cs (2)
40public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 45await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken).ConfigureAwait(false))
Microsoft.Extensions.AI.Abstractions (42)
ChatCompletion\ChatClientExtensions.cs (2)
131public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 151public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatCompletion\ChatResponse.cs (5)
106/// <summary>Creates an array of <see cref="ChatResponseUpdate" /> instances that represent this <see cref="ChatResponse" />.</summary> 107/// <returns>An array of <see cref="ChatResponseUpdate" /> instances that may be used to represent this <see cref="ChatResponse" />.</returns> 108public ChatResponseUpdate[] ToChatResponseUpdates() 110ChatResponseUpdate? extra = null; 125var updates = new ChatResponseUpdate[messageCount + (extra is not null ? 1 : 0)];
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)
ChatCompletion\ChatResponseUpdate.cs (8)
19/// <see cref="ChatResponseUpdate"/> is so named because it represents updates 24/// The relationship between <see cref="ChatResponse"/> and <see cref="ChatResponseUpdate"/> is 43/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 49/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 57/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 93/// If a <see cref="ChatResponseUpdate"/> is created to represent some underlying object from another object 114/// This value is used when <see cref="ChatResponseExtensions.ToChatResponseAsync(IAsyncEnumerable{ChatResponseUpdate}, System.Threading.CancellationToken)"/> 115/// groups <see cref="ChatResponseUpdate"/> instances into <see cref="ChatMessage"/> instances.
ChatCompletion\DelegatingChatClient.cs (1)
48public virtual IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatCompletion\IChatClient.cs (1)
54IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Utilities\AIJsonUtilities.Defaults.cs (2)
83[JsonSerializable(typeof(ChatResponseUpdate))] 84[JsonSerializable(typeof(IReadOnlyList<ChatResponseUpdate>))]
Microsoft.Extensions.AI.Abstractions.Tests (31)
ChatCompletion\ChatClientExtensionsTests.cs (4)
151await foreach (var update in client.GetStreamingResponseAsync("hello", expectedOptions, cts.Token)) 161private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(params ChatResponseUpdate[] updates) 164foreach (var update in updates)
ChatCompletion\ChatResponseTests.cs (7)
139ChatResponseUpdate[] updates = response.ToChatResponseUpdates(); 143ChatResponseUpdate update0 = updates[0]; 152ChatResponseUpdate update1 = updates[1]; 181ChatResponseUpdate[] updates = response.ToChatResponseUpdates(); 185ChatResponseUpdate update0 = updates[0]; 194ChatResponseUpdate update1 = updates[1]; 203ChatResponseUpdate update2 = updates[2];
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (11)
21Assert.Throws<ArgumentNullException>("updates", () => ((List<ChatResponseUpdate>)null!).ToChatResponse()); 29ChatResponseUpdate[] updates = 73ChatResponseUpdate[] updates = 129ChatResponseUpdate[] updates = 207List<ChatResponseUpdate> updates = []; 268ChatResponseUpdate[] updates = 306ChatResponseUpdate[] updates = 346ChatResponseUpdate[] updates = 363private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(IEnumerable<ChatResponseUpdate> updates) 365foreach (ChatResponseUpdate update in updates)
ChatCompletion\ChatResponseUpdateTests.cs (5)
16ChatResponseUpdate update = new(); 33ChatResponseUpdate update = new(); 87ChatResponseUpdate update = new() 115ChatResponseUpdate original = new() 137ChatResponseUpdate? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatResponseUpdate);
ChatCompletion\DelegatingChatClientTests.cs (1)
59ChatResponseUpdate[] expectedResults =
TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
18[JsonSerializable(typeof(ChatResponseUpdate))]
Microsoft.Extensions.AI.AzureAIInference (3)
AzureAIInferenceChatClient.cs (3)
141public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 166ChatResponseUpdate responseUpdate = new() 228var responseUpdate = new ChatResponseUpdate
Microsoft.Extensions.AI.AzureAIInference.Tests (7)
AzureAIInferenceChatClientTests.cs (7)
221List<ChatResponseUpdate> updates = []; 222await foreach (var update in client.GetStreamingResponseAsync(messages, new() 272await foreach (var update in client.GetStreamingResponseAsync("hello", new ChatOptions 453await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 611await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 1335List<ChatResponseUpdate> updates = []; 1336await foreach (var update in client.GetStreamingResponseAsync("How old is Alice?", new()
Microsoft.Extensions.AI.Evaluation.Reporting (6)
ResponseCachingChatClient.cs (3)
64protected override async Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync( 70IReadOnlyList<ChatResponseUpdate>? updates = 122IReadOnlyList<ChatResponseUpdate> value,
SimpleChatClient.cs (3)
58public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 63List<ChatResponseUpdate>? updates = null; 68await foreach (ChatResponseUpdate update in
Microsoft.Extensions.AI.Evaluation.Safety (2)
ContentSafetyChatClient.cs (2)
88public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 114await foreach (var update in
Microsoft.Extensions.AI.Integration.Tests (16)
CallCountingChatClient.cs (1)
26public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatClientIntegrationTests.cs (11)
107await foreach (var chunk in ChatClient.GetStreamingResponseAsync(chatHistory)) 142List<ChatResponseUpdate> chunks = []; 143await foreach (var chunk in response) 272await foreach (var chunk in response) 683await foreach (var update in chatClient.GetStreamingResponseAsync([message])) 692await foreach (var update in chatClient.GetStreamingResponseAsync([message])) 703await foreach (var update in chatClient.GetStreamingResponseAsync([message])) 861await foreach (var update in chatClient.GetStreamingResponseAsync("What's the biggest animal?")) 912await foreach (var update in chatClient.GetStreamingResponseAsync( 1283await foreach (var chunk in chatClient.GetStreamingResponseAsync(messages)) 1385public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
PromptBasedFunctionCallingChatClient.cs (2)
137public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 141foreach (var update in response.ToChatResponseUpdates())
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.OpenAI (22)
MicrosoftExtensionsAIChatExtensions.cs (7)
115/// sequence of <see cref="ChatResponseUpdate"/> instances. 119/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 122this IAsyncEnumerable<ChatResponseUpdate> responseUpdates, [EnumeratorCancellation] CancellationToken cancellationToken = default) 126await foreach (var update in responseUpdates.WithCancellation(cancellationToken).ConfigureAwait(false)) 242/// Creates a sequence of Microsoft.Extensions.AI <see cref="ChatResponseUpdate"/> instances from the specified 248/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 250public static IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
MicrosoftExtensionsAIResponsesExtensions.cs (3)
48/// Creates a sequence of Microsoft.Extensions.AI <see cref="ChatResponseUpdate"/> instances from the specified 54/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 56public static IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
OpenAIAssistantsChatClient.cs (3)
79public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 174ChatResponseUpdate ruUpdate = new() 210ChatResponseUpdate textUpdate = new(mcu.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant, mcu.Text)
OpenAIChatClient.cs (4)
73public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 297internal static async IAsyncEnumerable<ChatResponseUpdate> FromOpenAIStreamingChatCompletionAsync( 321ChatResponseUpdate responseUpdate = new() 388ChatResponseUpdate responseUpdate = new()
OpenAIResponsesChatClient.cs (5)
198public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 211internal static async IAsyncEnumerable<ChatResponseUpdate> FromOpenAIStreamingResponseUpdatesAsync( 225ChatResponseUpdate CreateUpdate(AIContent? content = null) => 247var update = CreateUpdate(ToUsageDetails(completedUpdate.Response) is { } usage ? new UsageContent(usage) : null); 281var mcpUpdate = CreateUpdate();
Microsoft.Extensions.AI.OpenAI.Tests (22)
OpenAIChatClientTests.cs (6)
231List<ChatResponseUpdate> updates = []; 232await foreach (var update in client.GetStreamingResponseAsync("hello", new() 493await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 648await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 1289List<ChatResponseUpdate> updates = []; 1290await foreach (var update in client.GetStreamingResponseAsync("How old is Alice?", new()
OpenAIConversionTests.cs (12)
242List<ChatResponseUpdate> updates = []; 243await foreach (var update in CreateUpdates().AsChatResponseUpdatesAsync()) 543var asyncEnumerable = ((IAsyncEnumerable<ChatResponseUpdate>)null!).AsOpenAIStreamingChatCompletionUpdatesAsync(); 550var updates = new List<ChatResponseUpdate>(); 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")
OpenAIResponseClientTests.cs (4)
292List<ChatResponseUpdate> updates = []; 293await foreach (var update in client.GetStreamingResponseAsync("Calculate the sum of the first 5 positive integers.", new() 429List<ChatResponseUpdate> updates = []; 430await foreach (var update in client.GetStreamingResponseAsync("hello", new()
Microsoft.Extensions.AI.Tests (38)
ChatCompletion\ConfigureOptionsChatClientTests.cs (3)
89static async IAsyncEnumerable<ChatResponseUpdate> YieldUpdates(ChatResponseUpdate[] updates) 91foreach (var update in updates)
ChatCompletion\DistributedCachingChatClientTest.cs (13)
247List<ChatResponseUpdate> actualUpdate = 260List<ChatResponseUpdate> expectedCachedResponse = 311List<ChatResponseUpdate> expectedResponse = 344ChatResponseUpdate update = Assert.Single(await ToListAsync(result2)); 366List<ChatResponseUpdate> expectedResponse = 416var item = Assert.Single(items); 434List<ChatResponseUpdate> expectedResponse = 482return ToAsyncEnumerableAsync<ChatResponseUpdate>(Task.CompletedTask, 521return ToAsyncEnumerableAsync<ChatResponseUpdate>( 833private static async Task AssertResponsesEqualAsync(IReadOnlyList<ChatResponseUpdate> expected, IAsyncEnumerable<ChatResponseUpdate> actual) 837foreach (var expectedItem in expected) 841var actualItem = actualEnumerator.Current;
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (4)
635async IAsyncEnumerable<ChatResponseUpdate> YieldInnerClientUpdates( 660await foreach (var update in updates) 708async IAsyncEnumerable<ChatResponseUpdate> YieldInnerClientUpdates( 738await foreach (var update in updates)
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
736List<ChatResponseUpdate> updates; 751foreach (var update in updates)
ChatCompletion\LoggingChatClientTests.cs (2)
105static async IAsyncEnumerable<ChatResponseUpdate> GetUpdatesAsync() 117await foreach (var update in client.GetStreamingResponseAsync(
ChatCompletion\OpenTelemetryChatClientTests.cs (2)
61async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 137await foreach (var update in chatClient.GetStreamingResponseAsync(messages, options))
ChatCompletion\ReducingChatClientTests.cs (2)
72var updates = new List<ChatResponseUpdate>(); 73await foreach (var update in client.GetStreamingResponseAsync(originalMessages))
ChatCompletion\UseDelegateChatClientTests.cs (7)
146static async IAsyncEnumerable<ChatResponseUpdate> Impl( 149await foreach (var update in innerClient.GetStreamingResponseAsync(messages, options, cancellationToken)) 217static async IAsyncEnumerable<ChatResponseUpdate> Impl( 220await foreach (var update in innerClient.GetStreamingResponseAsync(messages, options, cancellationToken)) 239private static async IAsyncEnumerable<ChatResponseUpdate> YieldUpdates(params ChatResponseUpdate[] updates) 241foreach (var update in updates)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
15[JsonSerializable(typeof(IReadOnlyList<ChatResponseUpdate>))]
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
57public virtual async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Microsoft.ML.GenAI.LLaMA (1)
Llama3CausalLMChatClient.cs (1)
46public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Microsoft.ML.GenAI.Phi (1)
Phi3\Phi3CausalLMChatClient.cs (1)
51public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Microsoft.ML.GenAI.Samples (2)
MEAI\Llama3_1.cs (1)
49await foreach (var response in client.GetStreamingResponseAsync([chatMessage]))
MEAI\Phi3.cs (1)
39await foreach (var response in client.GetStreamingResponseAsync([chatMessage]))