278 instantiations of ChatResponseUpdate
Microsoft.AspNetCore.Components.AI (1)
Engine\UIAgent.cs (1)
113var userUpdate = new ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
708new()
Microsoft.Extensions.AI.Abstractions (4)
ChatCompletion\ChatResponse.cs (2)
127extra = new ChatResponseUpdate 145updates[i] = new ChatResponseUpdate
ChatCompletion\ChatResponseUpdate.cs (1)
69new()
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatResponseUpdate.g.cs (1)
33ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatResponseUpdate(),
Microsoft.Extensions.AI.Abstractions.Tests (186)
ChatCompletion\ChatClientExtensionsTests.cs (2)
146return YieldAsync([new ChatResponseUpdate(ChatRole.Assistant, "world")]); 233return YieldAsync([new ChatResponseUpdate(ChatRole.Assistant, "world")]);
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (171)
31new(ChatRole.Assistant, "Hello") { ResponseId = "someResponse", MessageId = "12345", CreatedAt = new DateTimeOffset(2024, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model123" }, 32new(ChatRole.Assistant, ", ") { AuthorName = "Someone", AdditionalProperties = new() { ["a"] = "b" } }, 33new(null, "world!") { CreatedAt = new DateTimeOffset(2025, 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(ChatRole.Assistant, "First message") { MessageId = "msg1", AdditionalProperties = new() { ["key1"] = "value1" } }, 457new(null, " part 2") { MessageId = "msg1", AdditionalProperties = new() { ["key2"] = "value2" } }, 460new(ChatRole.User, "Second message") { MessageId = "msg2", AdditionalProperties = new() { ["key1"] = "different_value1" } }, 461new(null, " part 2") { MessageId = "msg2", AdditionalProperties = new() { ["key3"] = "value3" } }, 464new(ChatRole.Assistant, "Third message") { MessageId = "msg3" }, 508new(ChatRole.Assistant, "Hello") { MessageId = "msg1", AdditionalProperties = new() { ["messageKey"] = "messageValue" } }, 511new() { AdditionalProperties = new() { ["responseKey"] = "responseValue" } }, 541new(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" }, 542new(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" }, 543new(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should not overwrite first 544new(null, " AI") { MessageId = "msg1", AuthorName = "Assistant" }, // Keep same AuthorName to avoid creating new message 547new(null, "More text") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 2, 0, TimeSpan.Zero), AuthorName = "Assistant" }, 550new(ChatRole.User, "How") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" }, 551new(null, " are") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) }, 552new(null, " you?") { MessageId = "msg3", AuthorName = "User" }, // Keep same AuthorName 555new(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) }, 556new(null, " thank you!") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should not overwrite first 559new(null, " How can I help?"), 641updates.Add(new(null, text)); 662updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] }); 689new(null, "A"), 690new(null, "B"), 691new(null, "C"), 692new() { Contents = [new TextReasoningContent("D")] }, 693new() { Contents = [new TextReasoningContent("E")] }, 694new() { Contents = [new TextReasoningContent("F")] }, 695new(null, "G"), 696new(null, "H"), 697new() { Contents = [new TextReasoningContent("I")] }, 698new() { Contents = [new TextReasoningContent("J")] }, 699new(null, "K"), 700new() { Contents = [new TextReasoningContent("L")] }, 701new(null, "M"), 702new(null, "N"), 703new() { Contents = [new TextReasoningContent("O")] }, 704new() { Contents = [new TextReasoningContent("P")] }, 727new() { Contents = [new TextReasoningContent("A") { ProtectedData = "1" }] }, 728new() { Contents = [new TextReasoningContent("B") { ProtectedData = "2" }] }, 729new() { Contents = [new TextReasoningContent("C")] }, 730new() { Contents = [new TextReasoningContent("D")] }, 731new() { Contents = [new TextReasoningContent("E") { ProtectedData = "3" }] }, 732new() { Contents = [new TextReasoningContent("F") { ProtectedData = "4" }] }, 733new() { Contents = [new TextReasoningContent("G")] }, 734new() { Contents = [new TextReasoningContent("H")] }, 764new(null, "A"), 765new(null, "B"), 766new(null, "C"), 767new() { Contents = [new TextContent("D") { Annotations = [new()] }] }, 768new() { Contents = [new TextContent("E") { Annotations = [new()] }] }, 769new() { Contents = [new TextContent("F") { Annotations = [new()] }] }, 770new() { Contents = [new TextContent("G") { Annotations = [] }] }, 771new() { Contents = [new TextContent("H") { Annotations = [] }] }, 772new() { Contents = [new TextContent("I") { Annotations = [new()] }] }, 773new() { Contents = [new TextContent("J") { Annotations = [new()] }] }, 774new(null, "K"), 775new() { Contents = [new TextContent("L") { Annotations = [new()] }] }, 776new(null, "M"), 777new(null, "N"), 778new() { Contents = [new TextContent("O") { Annotations = [new()] }] }, 779new() { Contents = [new TextContent("P") { Annotations = [new()] }] }, 804new(null, "Hello, "), 805new(null, "world!"), 806new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] }, 834new(ChatRole.Tool, "a") { MessageId = "4", CreatedAt = early }, 837new(null, "b") { CreatedAt = unixEpoch }, 840new(null, "c") { CreatedAt = beforeEpoch }, 843new(null, "d") { CreatedAt = middle }, 846new(null, "e") { CreatedAt = early }, 849new(null, "f") { CreatedAt = late }, 852new(null, "g") { CreatedAt = unixEpoch }, 855new(null, "h") { CreatedAt = null }, 903new(ChatRole.Assistant, "a") { CreatedAt = first }, 904new(null, "b") { CreatedAt = second }, 930new(null, "Let's generate"), 931new(null, " some images"), 934new() { Contents = [new ImageGenerationToolResultContent("img1") { Outputs = [image1] }] }, 937new() { Contents = [new ImageGenerationToolResultContent("img2") { Outputs = [image2] }] }, 940new() { Contents = [new ImageGenerationToolResultContent("img1") { Outputs = [image3] }] }, 943new() { Contents = [new ImageGenerationToolResultContent("img2") { Outputs = [image4] }] }, 946new(null, "Here are those generated images"), 988new() { Contents = [new ImageGenerationToolResultContent("id-1") { Outputs = [image1] }] }, 991new() { Contents = [new ImageGenerationToolResultContent("id-2") { Outputs = [image2] }] }, 994new() { Contents = [new ImageGenerationToolResultContent("id-3") { Outputs = [image3] }] }, 1020new(null, "Searching..."), 1023new() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["first query"] }] }, 1026new(null, " found results"), 1029new() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["second query"], RawRepresentation = rawRepresentation, AdditionalProperties = additionalProps }] }, 1032new() { Contents = [new WebSearchToolCallContent("ws2") { Queries = ["AI safety"] }] }, 1035new() { Contents = [new WebSearchToolCallContent("ws1")] }, 1037new(null, " done"), 1067new() { Contents = [new WebSearchToolCallContent("ws1")] }, 1068new() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["query from second"] }] }, 1086new() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["q1"] }] }, 1087new() { Contents = [new WebSearchToolCallContent("ws2") { Queries = ["q2"] }] }, 1088new() { Contents = [new WebSearchToolCallContent("ws3") { Queries = ["q3"] }] }, 1116new(null, "Searching the web..."), 1120new() { Contents = [inProgress] }, 1123new() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["dotnet extensions"] }] }, 1127new() { Contents = [new FunctionCallContent("fc1", "SearchTool", new Dictionary<string, object?> { ["q"] = "test" })] },
ChatCompletion\ChatResponseUpdateTests.cs (10)
16ChatResponseUpdate update = new(); 33ChatResponseUpdate update = new(); 87ChatResponseUpdate update = new() 115ChatResponseUpdate original = new() 178ChatResponseUpdate original = new() 250var original = new ChatResponseUpdate 291var original = new ChatResponseUpdate 319var original = new ChatResponseUpdate(); 343var original = new ChatResponseUpdate 378var original = new ChatResponseUpdate
ChatCompletion\DelegatingChatClientTests.cs (2)
61new(ChatRole.User, "Message 1"), 62new(ChatRole.User, "Message 2")
Generated\361d1da7f942c932\TestJsonSerializerContext.ChatResponseUpdate.g.cs (1)
31ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatResponseUpdate(),
Microsoft.Extensions.AI.Evaluation.Safety (1)
ContentSafetyChatClient.cs (1)
100yield return new ChatResponseUpdate(ChatRole.Assistant, annotationResult)
Microsoft.Extensions.AI.OpenAI (8)
OpenAIAssistantsChatClient.cs (5)
167ChatResponseUpdate ruUpdate = new() 211yield return new ChatResponseUpdate(ChatRole.Assistant, [hcitcc]) 241yield return new ChatResponseUpdate(ChatRole.Assistant, [hcitrc]) 253ChatResponseUpdate textUpdate = new(mcu.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant, mcu.Text) 302yield return new()
OpenAIChatClient.cs (2)
376ChatResponseUpdate responseUpdate = new() 450ChatResponseUpdate responseUpdate = new()
OpenAIResponsesChatClient.cs (1)
386new(lastRole, content is not null ? [content] : null)
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIConversionTests.cs (10)
1694var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello") 1712var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!") 1741var responseUpdate = new ChatResponseUpdate 1780var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent]) 1815var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2]) 1843var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, 1891var responseUpdate = new ChatResponseUpdate(inputRole, "Test message"); 1917var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test") 1938new ChatResponseUpdate(ChatRole.Assistant, "Hello, ") 1945new ChatResponseUpdate(ChatRole.Assistant, "world!")
Microsoft.Extensions.AI.Tests (66)
ChatCompletion\ConfigureOptionsChatClientTests.cs (1)
38var expectedUpdates = Enumerable.Range(0, 3).Select(i => new ChatResponseUpdate()).ToArray();
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")]);
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (7)
1482yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId }; 1485new ChatResponseUpdate( 1558yield return new ChatResponseUpdate(ChatRole.Assistant, [new TextContent("Text 1")]) { MessageId = messageId }; 1560yield return new ChatResponseUpdate(ChatRole.Assistant, [new TextContent("Text 2")]) { MessageId = messageId }; 1562yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId }; 1564yield return new ChatResponseUpdate( 1571yield return new ChatResponseUpdate(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func3")]) { MessageId = messageId };
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
1192new() { Contents = [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["text"] = "Input 1" })] }, 1193new() { Contents = [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["text"] = "Input 2" })] } 1198updates = [new() { Contents = [new TextContent("OK bye")] }];
ChatCompletion\ImageGeneratingChatClientTests.cs (3)
229yield return new(ChatRole.Assistant, "test"); 359yield return new ChatResponseUpdate(ChatRole.Assistant, 488yield return new ChatResponseUpdate(ChatRole.Assistant, contents);
ChatCompletion\LoggingChatClientTests.cs (2)
108yield return new(ChatRole.Assistant, "blue "); 109yield return new(ChatRole.Assistant, "whale");
ChatCompletion\OpenTelemetryChatClientTests.cs (22)
74yield return new ChatResponseUpdate(ChatRole.Assistant, text) 80yield return new ChatResponseUpdate 85yield return new ChatResponseUpdate 422yield return new(ChatRole.Assistant, "Assistant response text"); 423yield return new() { Contents = [new TextReasoningContent("This is reasoning")] }; 424yield return new() { Contents = [new FunctionCallContent("call-123", "GetWeather", new Dictionary<string, object?> { ["location"] = "Seattle" })] }; 425yield return new() { Contents = [new FunctionResultContent("call-123", "72°F and sunny")] }; 426yield return new() { Contents = [new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png")] }; 427yield return new() { Contents = [new UriContent(new Uri("https://example.com/image.jpg"), "image/jpeg")] }; 428yield return new() { Contents = [new HostedFileContent("file-abc123")] }; 676yield return new(ChatRole.Assistant, "Processing with tools..."); 677yield return new() { Contents = [new CodeInterpreterToolCallContent("ci-call-1") { Inputs = [new TextContent("print('hello')")] }] }; 678yield return new() { Contents = [new CodeInterpreterToolResultContent("ci-call-1") { Outputs = [new TextContent("hello")] }] }; 679yield return new() { Contents = [new ImageGenerationToolCallContent("img-123")] }; 680yield return new() 690yield return new() { Contents = [new McpServerToolCallContent("mcp-call-1", "myTool", "myServer") { Arguments = new Dictionary<string, object?> { ["param1"] = "value1" } }] }; 691yield return new() { Contents = [new McpServerToolResultContent("mcp-call-1") { Outputs = [new TextContent("Tool result")] }] }; 917yield return new ChatResponseUpdate(ChatRole.Assistant, "First") { ResponseId = "id1", ModelId = "responsemodel" }; 919yield return new ChatResponseUpdate(ChatRole.Assistant, "Second") { ResponseId = "id1" }; 921yield return new ChatResponseUpdate(ChatRole.Assistant, "Third") { ResponseId = "id1" }; 1104yield return new ChatResponseUpdate(ChatRole.Assistant, "chunk1"); 1106yield return new ChatResponseUpdate(ChatRole.Assistant, "chunk2");
ChatCompletion\ReducingChatClientTests.cs (2)
51var 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)");
ChatRouting\FailoverChatClientTests.cs (4)
1018[new ChatResponseUpdate(ChatRole.Assistant, "first")], 1166yield return new ChatResponseUpdate(ChatRole.Assistant, text); 1175yield return new ChatResponseUpdate(ChatRole.Assistant, "never"); 1187yield return new ChatResponseUpdate(ChatRole.Assistant, "never");
Generated\361d1da7f942c932\TestJsonSerializerContext.ChatResponseUpdate.g.cs (1)
31ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatResponseUpdate(),
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
73yield return new(ChatRole.Assistant, output)
632 references to ChatResponseUpdate
Aspire.Dashboard (2)
Model\Assistant\AIHelpers.cs (2)
320await foreach (var update in response.WithCancellation(responseCts.Token).ConfigureAwait(false)) 351public static IList<ChatMessage> GetMessages(ChatResponseUpdate update, Func<AIContent, bool>? filter = null)
Microsoft.AspNetCore.Components.AI (6)
Engine\UIAgent.cs (3)
113var userUpdate = new ChatResponseUpdate 129var assistantUpdates = new List<ChatResponseUpdate>(); 132await foreach (var update in _chatClient.GetStreamingResponseAsync(
Pipeline\BlockMappingContext.cs (2)
18internal BlockMappingContext(ChatResponseUpdate update) 27public ChatResponseUpdate Update { get; }
Pipeline\BlockMappingPipeline.cs (1)
37ChatResponseUpdate update,
Microsoft.Extensions.AI (54)
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())
ChatCompletion\CachingChatClient.cs (12)
74public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 84private async IAsyncEnumerable<ChatResponseUpdate> GetCachedStreamingResponseAsync( 97foreach (var chunk in chatResponse.ToChatResponseUpdates()) 105List<ChatResponseUpdate> capturedItems = []; 106await foreach (var chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 123foreach (var chunk in existingChunks) 132List<ChatResponseUpdate> capturedItems = []; 133await foreach (var chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 163/// Returns a previously cached list of <see cref="ChatResponseUpdate"/> values, if available. 170protected abstract Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken); 185/// Stores a list of <see cref="ChatResponseUpdate"/> values in the underlying cache. 194protected 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)
24/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>, 86protected override async Task<IReadOnlyList<ChatResponseUpdate>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken) 93return (IReadOnlyList<ChatResponseUpdate>?)JsonSerializer.Deserialize(existingJson, JsonSerializerOptions.GetTypeInfo(typeof(IReadOnlyList<ChatResponseUpdate>))); 111protected override async Task WriteCacheStreamingAsync(string key, IReadOnlyList<ChatResponseUpdate> value, CancellationToken cancellationToken) 117var 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 (8)
437public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 457List<ChatResponseUpdate> updates = []; // updates from the current response 542await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken)) 546Throw.InvalidOperationException($"The inner {nameof(IChatClient)} streamed a null {nameof(ChatResponseUpdate)}."); 623var updateToYield = updates[lastYieldedUpdateIndex]; 654var updateToYield = updates[lastYieldedUpdateIndex]; 707private static ChatResponseUpdate ConvertToolResultMessageToUpdate(ChatMessage message, string? conversationId, string? messageId) => 968private static void MarkServerHandledFunctionCalls(List<ChatResponseUpdate> updates, List<FunctionCallContent>? functionCallContents)
ChatCompletion\ImageGeneratingChatClient.cs (3)
95public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 106await foreach (var update in base.GetStreamingResponseAsync(processedMessages, processedOptions, cancellationToken)) 114var modifiedUpdate = update.Clone();
ChatCompletion\LoggingChatClient.cs (3)
100public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 115IAsyncEnumerator<ChatResponseUpdate> e; 133ChatResponseUpdate? update = null;
ChatCompletion\OpenTelemetryChatClient.cs (4)
166public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 179IAsyncEnumerable<ChatResponseUpdate> updates; 191List<ChatResponseUpdate> trackedUpdates = []; 207ChatResponseUpdate update;
ChatCompletion\ReducingChatClient.cs (2)
41public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 46await foreach (var update in base.GetStreamingResponseAsync(messages, options, cancellationToken).ConfigureAwait(false))
ChatRouting\FailoverChatClient.cs (5)
165public sealed override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 183IAsyncEnumerator<ChatResponseUpdate>? enumerator = null; 241out ChatResponseUpdate current, 342IAsyncEnumerator<ChatResponseUpdate> enumerator, 343out ChatResponseUpdate current,
Microsoft.Extensions.AI.Abstractions (119)
ChatCompletion\ChatClientExtensions.cs (2)
131public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 151public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatCompletion\ChatOptions.cs (1)
195/// can be resumed if interrupted. This means that a continuation token obtained from the <see cref="ChatResponseUpdate.ContinuationToken"/>
ChatCompletion\ChatResponse.cs (5)
120/// <summary>Creates an array of <see cref="ChatResponseUpdate" /> instances that represent this <see cref="ChatResponse" />.</summary> 121/// <returns>An array of <see cref="ChatResponseUpdate" /> instances that can be used to represent this <see cref="ChatResponse" />.</returns> 122public ChatResponseUpdate[] ToChatResponseUpdates() 124ChatResponseUpdate? extra = null; 139var updates = new ChatResponseUpdate[messageCount + (extra is not null ? 1 : 0)];
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)) 535/// <summary>Processes the <see cref="ChatResponseUpdate"/>, incorporating its contents into <paramref name="response"/>.</summary> 538private static void ProcessUpdate(ChatResponseUpdate update, ChatResponse response)
ChatCompletion\ChatResponseUpdate.cs (10)
17/// <see cref="ChatResponseUpdate"/> is so named because it represents updates 22/// The relationship between <see cref="ChatResponse"/> and <see cref="ChatResponseUpdate"/> is 23/// codified in the <see cref="ChatResponseExtensions.ToChatResponseAsync(IAsyncEnumerable{ChatResponseUpdate}, System.Threading.CancellationToken)"/> and 38/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 44/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 52/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary> 68public ChatResponseUpdate Clone() => 111/// If a <see cref="ChatResponseUpdate"/> is created to represent some underlying object from another object 132/// This value is used when <see cref="ChatResponseExtensions.ToChatResponseAsync(IAsyncEnumerable{ChatResponseUpdate}, System.Threading.CancellationToken)"/> 133/// 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(
ChatRouting\RoutingChatClient.cs (2)
80public virtual async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 90await foreach (ChatResponseUpdate update in
Generated\361d1da7f942c932\JsonContext.IReadOnlyListChatResponseUpdate.g.cs (12)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>>? _IReadOnlyListChatResponseUpdate; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> IReadOnlyListChatResponseUpdate 24get => _IReadOnlyListChatResponseUpdate ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> Create_IReadOnlyListChatResponseUpdate(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIEnumerableInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>, global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, info); 47private void IReadOnlyListChatResponseUpdateSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>? value) 57foreach (global::Microsoft.Extensions.AI.ChatResponseUpdate element in value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatResponseUpdate.g.cs (58)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>? _ChatResponseUpdate; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> ChatResponseUpdate 24get => _ChatResponseUpdate ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> Create_ChatResponseUpdate(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatResponseUpdate> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 60Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AuthorName, 61Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AuthorName = value!, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 78DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 80Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Role, 81Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Role = value!, 88AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole?), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 119DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 121Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Contents, 122Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Contents = value!, 129AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 140DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 150AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 160DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 162Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AdditionalProperties, 163Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AdditionalProperties = value!, 170AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null), 180DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 182Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ResponseId, 183Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ResponseId = value!, 190AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ResponseId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 200DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 202Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).MessageId, 203Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).MessageId = value!, 210AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 220DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 222Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ConversationId, 223Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ConversationId = value!, 230AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ConversationId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 240DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 242Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).CreatedAt, 243Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).CreatedAt = value!, 250AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 260DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 262Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).FinishReason, 263Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).FinishReason = value!, 270AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("FinishReason", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatFinishReason?), global::System.Array.Empty<global::System.Type>(), null), 280DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 282Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ModelId, 283Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ModelId = value!, 290AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ModelId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 300DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 302Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ContinuationToken, 303Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ContinuationToken = value!, 310AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ContinuationToken", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ResponseContinuationToken), global::System.Array.Empty<global::System.Type>(), null),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (2)
124if (type == typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate)) 424if (type == typeof(global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>))
Utilities\AIJsonUtilities.Defaults.cs (2)
104[JsonSerializable(typeof(ChatResponseUpdate))] 105[JsonSerializable(typeof(IReadOnlyList<ChatResponseUpdate>))]
Microsoft.Extensions.AI.Abstractions.Tests (130)
ChatCompletion\ChatClientExtensionsTests.cs (5)
151await foreach (var update in client.GetStreamingResponseAsync("hello", expectedOptions, cts.Token)) 238await foreach (var update in client.GetStreamingResponseAsync([], expectedChatOptions, cts.Token)) 247private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(params ChatResponseUpdate[] updates) 250foreach (var update in updates)
ChatCompletion\ChatResponseTests.cs (7)
250ChatResponseUpdate[] updates = response.ToChatResponseUpdates(); 254ChatResponseUpdate update0 = updates[0]; 263ChatResponseUpdate update1 = updates[1]; 292ChatResponseUpdate[] updates = response.ToChatResponseUpdates(); 296ChatResponseUpdate update0 = updates[0]; 305ChatResponseUpdate update1 = updates[1]; 314ChatResponseUpdate update2 = updates[2];
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (30)
21Assert.Throws<ArgumentNullException>("updates", () => ((List<ChatResponseUpdate>)null!).ToChatResponse()); 29ChatResponseUpdate[] updates = 73ChatResponseUpdate[] updates = 129ChatResponseUpdate[] updates = 182ChatResponseUpdate[] updates = 241ChatResponseUpdate[] updates = 276ChatResponseUpdate[] updates = 311ChatResponseUpdate[] updates = 346ChatResponseUpdate[] updates = 379ChatResponseUpdate[] updates = 414ChatResponseUpdate[] updates = 452ChatResponseUpdate[] updates = 504ChatResponseUpdate[] updates = 537ChatResponseUpdate[] updates = 626List<ChatResponseUpdate> updates = []; 687ChatResponseUpdate[] updates = 725ChatResponseUpdate[] updates = 762ChatResponseUpdate[] updates = 802ChatResponseUpdate[] updates = 830ChatResponseUpdate[] updates = 901ChatResponseUpdate[] updates = 928ChatResponseUpdate[] updates = 985ChatResponseUpdate[] updates = 1018ChatResponseUpdate[] updates = 1065ChatResponseUpdate[] updates = 1084ChatResponseUpdate[] updates = 1114ChatResponseUpdate[] updates = 1143private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(IEnumerable<ChatResponseUpdate> updates) 1145foreach (ChatResponseUpdate update in updates)
ChatCompletion\ChatResponseUpdateTests.cs (20)
16ChatResponseUpdate update = new(); 33ChatResponseUpdate update = new(); 87ChatResponseUpdate update = new() 115ChatResponseUpdate original = new() 139ChatResponseUpdate? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatResponseUpdate); 178ChatResponseUpdate original = new() 203ChatResponseUpdate? result = JsonSerializer.Deserialize<ChatResponseUpdate>(json, AIJsonUtilities.DefaultOptions); 250var original = new ChatResponseUpdate 266var clone = original.Clone(); 291var original = new ChatResponseUpdate 298var clone = original.Clone(); 319var original = new ChatResponseUpdate(); 322var clone = original.Clone(); 343var original = new ChatResponseUpdate 352var clone = original.Clone(); 378var original = new ChatResponseUpdate 385var clone = original.Clone(); 432ChatResponseUpdate? result = JsonSerializer.Deserialize<ChatResponseUpdate>(Json, AIJsonUtilities.DefaultOptions);
ChatCompletion\DelegatingChatClientTests.cs (1)
59ChatResponseUpdate[] expectedResults =
ChatRouting\RoutingChatClientTests.cs (5)
131private static async Task<List<ChatResponseUpdate>> CollectAsync( 132IAsyncEnumerable<ChatResponseUpdate> updates) 134var result = new List<ChatResponseUpdate>(); 135await foreach (ChatResponseUpdate update in updates) 167public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Generated\361d1da7f942c932\TestJsonSerializerContext.ChatResponseUpdate.g.cs (58)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>? _ChatResponseUpdate; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> ChatResponseUpdate 22get => _ChatResponseUpdate ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> Create_ChatResponseUpdate(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatResponseUpdate> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 58Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AuthorName, 59Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AuthorName = value!, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 76DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 78Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Role, 79Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Role = value!, 86AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole?), global::System.Array.Empty<global::System.Type>(), null), 96DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 106AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 117DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 119Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Contents, 120Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Contents = value!, 127AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 139DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 149AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 159DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 161Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AdditionalProperties, 162Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AdditionalProperties = value!, 169AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null), 179DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 181Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ResponseId, 182Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ResponseId = value!, 189AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ResponseId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 199DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 201Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).MessageId, 202Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).MessageId = value!, 209AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 219DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 221Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ConversationId, 222Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ConversationId = value!, 229AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ConversationId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 239DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 241Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).CreatedAt, 242Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).CreatedAt = value!, 249AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 259DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 261Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).FinishReason, 262Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).FinishReason = value!, 269AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("FinishReason", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatFinishReason?), global::System.Array.Empty<global::System.Type>(), null), 279DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 281Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ModelId, 282Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ModelId = value!, 289AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ModelId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 299DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 301Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ContinuationToken, 302Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ContinuationToken = value!, 309AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ContinuationToken", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ResponseContinuationToken), global::System.Array.Empty<global::System.Type>(), null),
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (1)
118if (type == typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate))
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.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)
83public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 109await foreach (var update in
Microsoft.Extensions.AI.Integration.Tests (16)
CallCountingChatClient.cs (1)
26public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatClientIntegrationTests.cs (11)
106await foreach (var chunk in ChatClient.GetStreamingResponseAsync(chatHistory)) 141List<ChatResponseUpdate> chunks = []; 142await foreach (var chunk in response) 271await 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( 1284await foreach (var chunk in chatClient.GetStreamingResponseAsync(messages)) 1386public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
parent\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)
PromptBasedFunctionCallingChatClient.cs (2)
137public override async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 141foreach (var update in response.ToChatResponseUpdates())
Microsoft.Extensions.AI.OpenAI (23)
MicrosoftExtensionsAIChatExtensions.cs (7)
128/// sequence of <see cref="ChatResponseUpdate"/> instances. 132/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 136this IAsyncEnumerable<ChatResponseUpdate> responseUpdates, [EnumeratorCancellation] CancellationToken cancellationToken = default) 140await foreach (var update in responseUpdates.WithCancellation(cancellationToken).ConfigureAwait(false)) 266/// Creates a sequence of Microsoft.Extensions.AI <see cref="ChatResponseUpdate"/> instances from the specified 272/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 275public static IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
MicrosoftExtensionsAIResponsesExtensions.cs (3)
71/// Creates a sequence of Microsoft.Extensions.AI <see cref="ChatResponseUpdate"/> instances from the specified 77/// <returns>A sequence of converted <see cref="ChatResponseUpdate"/> instances.</returns> 79public static IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
OpenAIAssistantsChatClient.cs (3)
76public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 167ChatResponseUpdate ruUpdate = new() 253ChatResponseUpdate textUpdate = new(mcu.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant, mcu.Text)
OpenAIChatClient.cs (4)
111public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 345internal static async IAsyncEnumerable<ChatResponseUpdate> FromOpenAIStreamingChatCompletionAsync( 376ChatResponseUpdate responseUpdate = new() 450ChatResponseUpdate responseUpdate = new()
OpenAIResponsesChatClient.cs (6)
325public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( 361internal static async IAsyncEnumerable<ChatResponseUpdate> FromOpenAIStreamingResponseUpdatesAsync( 385ChatResponseUpdate CreateUpdate(AIContent? content = null) => 450var update = CreateUpdate(ToUsageDetails(completedUpdate.Response) is { } usage ? new UsageContent(usage) : null); 522var mcpUpdate = CreateUpdate(); 620var toolCallUpdate = CreateUpdate(new ToolCallContent(outputItemDoneUpdate.Item.Id));
Microsoft.Extensions.AI.OpenAI.Tests (109)
OpenAIChatClientTests.cs (11)
234List<ChatResponseUpdate> updates = []; 235await foreach (var update in client.GetStreamingResponseAsync("hello", new() 496await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 651await foreach (var update in client.GetStreamingResponseAsync("hello", chatOptions)) 1325List<ChatResponseUpdate> updates = []; 1326await foreach (var update in client.GetStreamingResponseAsync("How old is Alice?", new() 1726List<ChatResponseUpdate> updates = []; 1727await foreach (var update in client.GetStreamingResponseAsync("hello", new() 1960List<ChatResponseUpdate> updates = []; 1961await foreach (var update in client.GetStreamingResponseAsync("hello")) 2035await foreach (var update in client.GetStreamingResponseAsync("hello"))
OpenAIConversionTests.cs (16)
918List<ChatResponseUpdate> updates = []; 919await foreach (var update in CreateUpdates().AsChatResponseUpdatesAsync()) 1009List<ChatResponseUpdate> updates = []; 1010await foreach (ChatResponseUpdate update in CreateStreamingUpdates().AsChatResponseUpdatesAsync()) 1133List<ChatResponseUpdate> updates = []; 1134await foreach (ChatResponseUpdate update in CreateStreamingUpdates().AsChatResponseUpdatesAsync()) 1665var asyncEnumerable = ((IAsyncEnumerable<ChatResponseUpdate>)null!).AsOpenAIStreamingChatCompletionUpdatesAsync(); 1672var updates = new List<ChatResponseUpdate>(); 1694var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello") 1712var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!") 1741var responseUpdate = new ChatResponseUpdate 1780var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent]) 1815var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2]) 1843var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, 1891var responseUpdate = new ChatResponseUpdate(inputRole, "Test message"); 1917var responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test")
OpenAIResponseClientIntegrationTests.cs (5)
426await foreach (var update in ChatClient.GetStreamingResponseAsync("What is the capital of France?", chatOptions)) 449await foreach (var update in ChatClient.GetStreamingResponseAsync("What is the capital of France?", chatOptions)) 465await foreach (var update in ChatClient.GetStreamingResponseAsync([], chatOptions)) 490await foreach (var update in chatClient.GetStreamingResponseAsync("What time is it?", chatOptions)) 843await foreach (var update in ChatClient.GetStreamingResponseAsync(deserializedHistory, chatOptions))
OpenAIResponseClientTests.cs (77)
296List<ChatResponseUpdate> updates = []; 297await foreach (var update in client.GetStreamingResponseAsync("Calculate the sum of the first 5 positive integers.", new() 426List<ChatResponseUpdate> updates = []; 427await foreach (var update in client.GetStreamingResponseAsync("Solve this problem step by step.", new() 469var assistantUpdate = updates.First(u => u.Role == ChatRole.Assistant && !string.IsNullOrEmpty(u.Text)); 552List<ChatResponseUpdate> updates = []; 553await foreach (var update in client.GetStreamingResponseAsync("Solve this problem step by step.", new() 627List<ChatResponseUpdate> updates = []; 628await foreach (var update in client.GetStreamingResponseAsync("Solve this problem step by step.", new() 746List<ChatResponseUpdate> updates = []; 747await foreach (var update in client.GetStreamingResponseAsync("hello", new() 992List<ChatResponseUpdate> updates = []; 993await foreach (var update in client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "Search the web for the temperature today in Fremont")], chatOptions)) 3112List<ChatResponseUpdate> updates = []; 3113await foreach (var update in client.GetStreamingResponseAsync("hello", new() 3205List<ChatResponseUpdate> updates = []; 3206await foreach (var update in client.GetStreamingResponseAsync([], chatOptions)) 3272await foreach (var update in client.GetStreamingResponseAsync("Please book a hotel for me", chatOptions)) 3691List<ChatResponseUpdate> updates = []; 3692await foreach (var update in client.GetStreamingResponseAsync("Calculate the sum of numbers from 1 to 10 using Python", new() 3709foreach (var update in codeInterpreterCallUpdates) 4188List<ChatResponseUpdate> updates = []; 4189await foreach (var update in client.GetStreamingResponseAsync("hello", new() 4269List<ChatResponseUpdate> updates = []; 4270await foreach (var update in client.GetStreamingResponseAsync("hello", new() 4410List<ChatResponseUpdate> updates = []; 4411await foreach (var update in client.GetStreamingResponseAsync("hello", new() 4487List<ChatResponseUpdate> updates = []; 4488await foreach (var update in client.GetStreamingResponseAsync("hello", new() 4565List<ChatResponseUpdate> updates = []; 4566await foreach (var update in client.GetStreamingResponseAsync("hello", new() 4762List<ChatResponseUpdate> updates = []; 4763await foreach (var update in client.GetStreamingResponseAsync("hello", new() 5648List<ChatResponseUpdate> updates = []; 5649await foreach (var update in client.GetStreamingResponseAsync("test")) 5683List<ChatResponseUpdate> updates = []; 5684await foreach (var update in client.GetStreamingResponseAsync("test")) 5718List<ChatResponseUpdate> updates = []; 5719await foreach (var update in client.GetStreamingResponseAsync("test")) 5756List<ChatResponseUpdate> updates = []; 5757await foreach (var update in client.GetStreamingResponseAsync("test")) 5794List<ChatResponseUpdate> updates = []; 5795await foreach (var update in client.GetStreamingResponseAsync("test")) 5800var refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal")); 5852List<ChatResponseUpdate> updates = []; 5853await foreach (var update in client.GetStreamingResponseAsync("test")) 5858var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 5895List<ChatResponseUpdate> updates = []; 5896await foreach (var update in client.GetStreamingResponseAsync("test")) 5901var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 5938List<ChatResponseUpdate> updates = []; 5939await foreach (var update in client.GetStreamingResponseAsync("test")) 5944var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 5981List<ChatResponseUpdate> updates = []; 5982await foreach (var update in client.GetStreamingResponseAsync("test")) 5987var annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0)); 6056List<ChatResponseUpdate> updates = []; 6057await foreach (var update in client.GetStreamingResponseAsync("test")) 6063var functionCallUpdate = updates.FirstOrDefault(u => u.Contents.OfType<FunctionCallContent>().Any()); 6071var functionResultUpdate = updates.FirstOrDefault(u => u.Contents.OfType<FunctionResultContent>().Any()); 6459List<ChatResponseUpdate> updates = []; 6469await foreach (var update in client.GetStreamingResponseAsync("Generate an image of a dog", new ChatOptions 6480var createdUpdate = updates.First(u => u.CreatedAt.HasValue); 6485var toolCallUpdate = updates.FirstOrDefault(u => 6492var partialImageUpdate = updates.FirstOrDefault(u => 6498var completionUpdate = updates.FirstOrDefault(u => 6576List<ChatResponseUpdate> updates = []; 6587await foreach (var update in client.GetStreamingResponseAsync("Generate an image of a sunset", new ChatOptions 6607var partialUpdate = partialImageUpdates.FirstOrDefault(u => 6644var toolCallUpdate = updates.FirstOrDefault(u => 6777await foreach (var update in client.GetStreamingResponseAsync("hello")) 7254List<ChatResponseUpdate> updates = []; 7255await foreach (var update in client.GetStreamingResponseAsync("What is the latest news about .NET?", new() 7282var wsResultUpdate = updates.FirstOrDefault(u => u.Contents.OfType<WebSearchToolResultContent>().Any()); 8929List<ChatResponseUpdate> updates = []; 8930await foreach (var update in client.GetStreamingResponseAsync( 8937var functionCallUpdate = updates.FirstOrDefault(u => u.Contents.OfType<FunctionCallContent>().Any());
Microsoft.Extensions.AI.Tests (158)
ChatCompletion\ConfigureOptionsChatClientTests.cs (3)
89static async IAsyncEnumerable<ChatResponseUpdate> YieldUpdates(ChatResponseUpdate[] updates) 91foreach (var update in updates)
ChatCompletion\DistributedCachingChatClientTest.cs (13)
248List<ChatResponseUpdate> actualUpdate = 261List<ChatResponseUpdate> expectedCachedResponse = 312List<ChatResponseUpdate> expectedResponse = 345ChatResponseUpdate update = Assert.Single(await ToListAsync(result2)); 367List<ChatResponseUpdate> expectedResponse = 417var item = Assert.Single(items); 435List<ChatResponseUpdate> expectedResponse = 483return ToAsyncEnumerableAsync<ChatResponseUpdate>(Task.CompletedTask, 522return ToAsyncEnumerableAsync<ChatResponseUpdate>( 831private static async Task AssertResponsesEqualAsync(IReadOnlyList<ChatResponseUpdate> expected, IAsyncEnumerable<ChatResponseUpdate> actual) 835foreach (var expectedItem in expected) 839var actualItem = actualEnumerator.Current;
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (5)
1474async IAsyncEnumerable<ChatResponseUpdate> YieldInnerClientUpdates( 1499await foreach (var update in updates) 1550async IAsyncEnumerable<ChatResponseUpdate> YieldInnerClientUpdates( 1580await foreach (var update in updates) 2131public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
1186List<ChatResponseUpdate> updates; 1201foreach (var update in updates) 1761await foreach (var update in client.GetStreamingResponseAsync(
ChatCompletion\ImageGeneratingChatClientTests.cs (9)
226static async IAsyncEnumerable<ChatResponseUpdate> GetUpdatesAsync() 241await foreach (var update in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions)) 356async IAsyncEnumerable<ChatResponseUpdate> GetUpdatesAsync() 372var updates = new List<ChatResponseUpdate>(); 373await foreach (var responseUpdate in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions)) 380var update = updates[0]; 475async IAsyncEnumerable<ChatResponseUpdate> GetUpdatesAsync() 500var updates = new List<ChatResponseUpdate>(); 501await foreach (var update in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions))
ChatCompletion\LoggingChatClientTests.cs (2)
105static async IAsyncEnumerable<ChatResponseUpdate> GetUpdatesAsync() 117await foreach (var update in client.GetStreamingResponseAsync(
ChatCompletion\OpenTelemetryChatClientTests.cs (11)
66async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 153await foreach (var update in chatClient.GetStreamingResponseAsync(messages, options)) 418async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 456await foreach (var update in chatClient.GetStreamingResponseAsync(messages)) 672async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 710await foreach (var update in chatClient.GetStreamingResponseAsync(messages)) 913async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync( 932await foreach (var update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")], new ChatOptions { ModelId = "mymodel" })) 1037await foreach (var update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")])) 1091await foreach (var update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")])) 1100async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync(
ChatCompletion\ReducingChatClientTests.cs (2)
73var updates = new List<ChatResponseUpdate>(); 74await 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)
ChatRouting\FailoverChatClientTests.cs (25)
1038var updates = new List<ChatResponseUpdate>(); 1042await foreach (ChatResponseUpdate update in router.GetStreamingResponseAsync([new(ChatRole.User, "hi")])) 1079List<ChatResponseUpdate> updates = 1110List<ChatResponseUpdate> updates = 1143private static async Task<List<ChatResponseUpdate>> CollectAsync( 1144IAsyncEnumerable<ChatResponseUpdate> updates) 1146var result = new List<ChatResponseUpdate>(); 1147await foreach (ChatResponseUpdate update in updates) 1155private static async Task ConsumeOneAsync(IAsyncEnumerable<ChatResponseUpdate> updates) 1157await using IAsyncEnumerator<ChatResponseUpdate> enumerator = updates.GetAsyncEnumerator(); 1161internal static async IAsyncEnumerable<ChatResponseUpdate> YieldUpdates(params string[] texts) 1170internal static async IAsyncEnumerable<ChatResponseUpdate> ThrowingStream(string message) 1181private static async IAsyncEnumerable<ChatResponseUpdate> CanceledStream( 1237private sealed class ThrowingGetAsyncEnumeratorEnumerable : IAsyncEnumerable<ChatResponseUpdate> 1246public IAsyncEnumerator<ChatResponseUpdate> GetAsyncEnumerator( 1251private sealed class ThrowingCurrentAsyncEnumerable(Exception exception) : IAsyncEnumerable<ChatResponseUpdate> 1255public IAsyncEnumerator<ChatResponseUpdate> GetAsyncEnumerator( 1261Exception exception) : IAsyncEnumerator<ChatResponseUpdate> 1263public ChatResponseUpdate Current => throw exception; 1275private sealed class TrackingAsyncEnumerable : IAsyncEnumerable<ChatResponseUpdate> 1277private readonly IReadOnlyList<ChatResponseUpdate> _updates; 1283IReadOnlyList<ChatResponseUpdate> updates, 1296public IAsyncEnumerator<ChatResponseUpdate> GetAsyncEnumerator( 1300private sealed class Enumerator : IAsyncEnumerator<ChatResponseUpdate> 1310public ChatResponseUpdate Current { get; private set; } = null!;
ChatRouting\OrderedFailoverChatClientTests.cs (2)
204await using (IAsyncEnumerator<ChatResponseUpdate> enumerator = 386public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ChatRouting\SemanticRoutingChatClientTests.cs (1)
247public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
Generated\361d1da7f942c932\TestJsonSerializerContext.ChatResponseUpdate.g.cs (58)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>? _ChatResponseUpdate; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> ChatResponseUpdate 22get => _ChatResponseUpdate ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> Create_ChatResponseUpdate(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatResponseUpdate> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 58Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AuthorName, 59Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AuthorName = value!, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 76DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 78Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Role, 79Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Role = value!, 86AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole?), global::System.Array.Empty<global::System.Type>(), null), 96DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 106AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 117DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 119Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Contents, 120Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).Contents = value!, 127AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 139DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 149AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 159DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 161Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AdditionalProperties, 162Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).AdditionalProperties = value!, 169AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null), 179DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 181Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ResponseId, 182Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ResponseId = value!, 189AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ResponseId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 199DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 201Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).MessageId, 202Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).MessageId = value!, 209AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 219DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 221Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ConversationId, 222Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ConversationId = value!, 229AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ConversationId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 239DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 241Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).CreatedAt, 242Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).CreatedAt = value!, 249AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 259DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 261Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).FinishReason, 262Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).FinishReason = value!, 269AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("FinishReason", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatFinishReason?), global::System.Array.Empty<global::System.Type>(), null), 279DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 281Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ModelId, 282Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ModelId = value!, 289AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ModelId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 299DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate), 301Getter = static obj => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ContinuationToken, 302Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatResponseUpdate)obj).ContinuationToken = value!, 309AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate).GetProperty("ContinuationToken", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ResponseContinuationToken), global::System.Array.Empty<global::System.Type>(), null),
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (2)
98if (type == typeof(global::Microsoft.Extensions.AI.ChatResponseUpdate)) 302if (type == typeof(global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>))
Generated\361d1da7f942c932\TestJsonSerializerContext.IReadOnlyListChatResponseUpdate.g.cs (12)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>>? _IReadOnlyListChatResponseUpdate; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> IReadOnlyListChatResponseUpdate 22get => _IReadOnlyListChatResponseUpdate ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> Create_IReadOnlyListChatResponseUpdate(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> jsonTypeInfo)) 29var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>> 35jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIEnumerableInfo<global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>, global::Microsoft.Extensions.AI.ChatResponseUpdate>(options, info); 45private void IReadOnlyListChatResponseUpdateSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IReadOnlyList<global::Microsoft.Extensions.AI.ChatResponseUpdate>? value) 55foreach (global::Microsoft.Extensions.AI.ChatResponseUpdate element in value)
parent\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.Extensions.DataIngestion.Tests (2)
parent\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.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]))