273 instantiations of ChatResponseUpdate
Microsoft.AspNetCore.Components.AI (4)
Engine\UIAgent.cs (2)
144
var userUpdate = new
ChatResponseUpdate
214
thread.AppendUpdate(new
ChatResponseUpdate
Pipeline\BlockMappingContext.cs (1)
89
var update = new
ChatResponseUpdate
Pipeline\StateMapperContext.cs (1)
115
return new
ChatResponseUpdate
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
708
new
()
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatResponse.cs (2)
127
extra = new
ChatResponseUpdate
145
updates[i] = new
ChatResponseUpdate
ChatCompletion\ChatResponseUpdate.cs (1)
69
new
()
Microsoft.Extensions.AI.Abstractions.Tests (185)
ChatCompletion\ChatClientExtensionsTests.cs (2)
146
return YieldAsync([new
ChatResponseUpdate
(ChatRole.Assistant, "world")]);
233
return YieldAsync([new
ChatResponseUpdate
(ChatRole.Assistant, "world")]);
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (171)
31
new
(ChatRole.Assistant, "Hello") { ResponseId = "someResponse", MessageId = "12345", CreatedAt = new DateTimeOffset(2024, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model123" },
32
new
(ChatRole.Assistant, ", ") { AuthorName = "Someone", AdditionalProperties = new() { ["a"] = "b" } },
33
new
(null, "world!") { CreatedAt = new DateTimeOffset(2025, 2, 3, 4, 5, 6, TimeSpan.Zero), ConversationId = "123", AdditionalProperties = new() { ["c"] = "d" } },
35
new
() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] },
36
new
() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] },
75
new
(null, "!") { MessageId = "1" },
76
new
(ChatRole.Assistant, "a") { MessageId = "1" },
77
new
(ChatRole.Assistant, "b") { MessageId = "2" },
78
new
(ChatRole.User, "c") { MessageId = "2" },
79
new
(ChatRole.User, "d") { MessageId = "2" },
80
new
(ChatRole.Assistant, "e") { MessageId = "3" },
81
new
(ChatRole.Tool, "f") { MessageId = "4" },
82
new
(ChatRole.Tool, "g") { MessageId = "4" },
83
new
(ChatRole.Tool, "h") { MessageId = "5" },
84
new
(new("human"), "i") { MessageId = "6" },
85
new
(new("human"), "j") { MessageId = "7" },
86
new
(new("human"), "k") { MessageId = "7" },
87
new
(null, "l") { MessageId = "7" },
88
new
(null, "m") { MessageId = "8" },
133
new
(ChatRole.Assistant, "Hello ") { AuthorName = "Alice" },
134
new
(null, "from ") { AuthorName = "Alice" },
135
new
(null, "Alice!"),
138
new
(null, "Hi ") { AuthorName = "Bob" },
139
new
(null, "from ") { AuthorName = "Bob" },
140
new
(null, "Bob!"),
143
new
(ChatRole.Assistant, "Greetings ") { AuthorName = "Charlie" },
144
new
(null, "from Charlie!") { AuthorName = "Charlie" },
147
new
(null, "Alice again!") { AuthorName = "Alice" },
150
new
(null, " Still Alice.") { AuthorName = "" },
151
new
(null, " And more."),
186
new
(ChatRole.Assistant, "A") { MessageId = "1", AuthorName = "Alice" },
187
new
(null, "B") { MessageId = "1", AuthorName = "Alice" },
190
new
(null, "C") { MessageId = "1", AuthorName = "Bob" },
193
new
(null, "D") { MessageId = "2", AuthorName = "Bob" },
194
new
(null, "E") { MessageId = "2", AuthorName = "Bob" },
197
new
(ChatRole.User, "F") { MessageId = "2", AuthorName = "Bob" },
200
new
(ChatRole.Tool, "G") { MessageId = "3", AuthorName = "Charlie" },
201
new
(null, "H") { MessageId = "3", AuthorName = "Charlie" },
245
new
(ChatRole.Assistant, "Hello") { AuthorName = "Assistant" },
248
new
(null, " world") { AuthorName = "" },
251
new
(null, "!"),
254
new
(null, " How") { AuthorName = "" },
255
new
(null, " are") { AuthorName = "" },
258
new
(null, " you?") { AuthorName = null },
280
new
(ChatRole.Assistant, "Hello") { MessageId = "1" },
281
new
(null, " there") { MessageId = "1" },
284
new
(null, " I'm Bob") { MessageId = "1", AuthorName = "Bob" },
285
new
(null, " speaking") { MessageId = "1", AuthorName = "Bob" },
288
new
(null, "Now Alice") { MessageId = "1", AuthorName = "Alice" },
315
new
(ChatRole.Assistant, "Hello"),
316
new
(null, " there"),
319
new
(null, " from") { MessageId = "msg1" },
320
new
(null, " AI") { MessageId = "msg1" },
323
new
(null, "Next message") { MessageId = "msg2" },
350
new
(ChatRole.Assistant, "Hello") { MessageId = "msg1" },
351
new
(null, " world") { MessageId = "msg1" },
354
new
(null, "!") { MessageId = "" },
357
new
(null, " How"),
360
new
(null, " are") { MessageId = "" },
361
new
(null, " you?"),
383
new
(null, "Hello") { MessageId = "1" },
384
new
(null, " there") { MessageId = "1" },
387
new
(ChatRole.Assistant, " from") { MessageId = "1" },
388
new
(null, " AI") { MessageId = "1" },
391
new
(ChatRole.User, "User message") { MessageId = "1" },
418
new
(new ChatRole("agent1"), "Hello") { MessageId = "1" },
419
new
(null, " from") { MessageId = "1" },
420
new
(new ChatRole("agent1"), " agent1") { MessageId = "1" },
423
new
(new ChatRole("agent2"), "Hi") { MessageId = "1" },
424
new
(null, " from") { MessageId = "1" },
425
new
(new ChatRole("agent2"), " agent2") { MessageId = "1" },
428
new
(ChatRole.Assistant, "Assistant here") { MessageId = "1" },
456
new
(ChatRole.Assistant, "First message") { MessageId = "msg1", AdditionalProperties = new() { ["key1"] = "value1" } },
457
new
(null, " part 2") { MessageId = "msg1", AdditionalProperties = new() { ["key2"] = "value2" } },
460
new
(ChatRole.User, "Second message") { MessageId = "msg2", AdditionalProperties = new() { ["key1"] = "different_value1" } },
461
new
(null, " part 2") { MessageId = "msg2", AdditionalProperties = new() { ["key3"] = "value3" } },
464
new
(ChatRole.Assistant, "Third message") { MessageId = "msg3" },
508
new
(ChatRole.Assistant, "Hello") { MessageId = "msg1", AdditionalProperties = new() { ["messageKey"] = "messageValue" } },
511
new
() { AdditionalProperties = new() { ["responseKey"] = "responseValue" } },
541
new
(null, "Hi! ") { CreatedAt = new DateTimeOffset(2023, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
542
new
(ChatRole.Assistant, "Hello") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 0, 0, TimeSpan.Zero), AuthorName = "Assistant" },
543
new
(null, " from") { MessageId = "msg1", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 1, 0, TimeSpan.Zero) }, // Later CreatedAt should not overwrite first
544
new
(null, " AI") { MessageId = "msg1", AuthorName = "Assistant" }, // Keep same AuthorName to avoid creating new message
547
new
(null, "More text") { MessageId = "msg2", CreatedAt = new DateTimeOffset(2024, 1, 1, 10, 2, 0, TimeSpan.Zero), AuthorName = "Assistant" },
550
new
(ChatRole.User, "How") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 0, 0, TimeSpan.Zero), AuthorName = "User" },
551
new
(null, " are") { MessageId = "msg3", CreatedAt = new DateTimeOffset(2024, 1, 1, 11, 1, 0, TimeSpan.Zero) },
552
new
(null, " you?") { MessageId = "msg3", AuthorName = "User" }, // Keep same AuthorName
555
new
(ChatRole.Assistant, "I'm doing well,") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 0, 0, TimeSpan.Zero) },
556
new
(null, " thank you!") { MessageId = "msg4", CreatedAt = new DateTimeOffset(2024, 1, 1, 12, 2, 0, TimeSpan.Zero) }, // Later CreatedAt should not overwrite first
559
new
(null, " How can I help?"),
641
updates.Add(
new
(null, text));
662
updates.Add(
new
() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
689
new
(null, "A"),
690
new
(null, "B"),
691
new
(null, "C"),
692
new
() { Contents = [new TextReasoningContent("D")] },
693
new
() { Contents = [new TextReasoningContent("E")] },
694
new
() { Contents = [new TextReasoningContent("F")] },
695
new
(null, "G"),
696
new
(null, "H"),
697
new
() { Contents = [new TextReasoningContent("I")] },
698
new
() { Contents = [new TextReasoningContent("J")] },
699
new
(null, "K"),
700
new
() { Contents = [new TextReasoningContent("L")] },
701
new
(null, "M"),
702
new
(null, "N"),
703
new
() { Contents = [new TextReasoningContent("O")] },
704
new
() { Contents = [new TextReasoningContent("P")] },
727
new
() { Contents = [new TextReasoningContent("A") { ProtectedData = "1" }] },
728
new
() { Contents = [new TextReasoningContent("B") { ProtectedData = "2" }] },
729
new
() { Contents = [new TextReasoningContent("C")] },
730
new
() { Contents = [new TextReasoningContent("D")] },
731
new
() { Contents = [new TextReasoningContent("E") { ProtectedData = "3" }] },
732
new
() { Contents = [new TextReasoningContent("F") { ProtectedData = "4" }] },
733
new
() { Contents = [new TextReasoningContent("G")] },
734
new
() { Contents = [new TextReasoningContent("H")] },
764
new
(null, "A"),
765
new
(null, "B"),
766
new
(null, "C"),
767
new
() { Contents = [new TextContent("D") { Annotations = [new()] }] },
768
new
() { Contents = [new TextContent("E") { Annotations = [new()] }] },
769
new
() { Contents = [new TextContent("F") { Annotations = [new()] }] },
770
new
() { Contents = [new TextContent("G") { Annotations = [] }] },
771
new
() { Contents = [new TextContent("H") { Annotations = [] }] },
772
new
() { Contents = [new TextContent("I") { Annotations = [new()] }] },
773
new
() { Contents = [new TextContent("J") { Annotations = [new()] }] },
774
new
(null, "K"),
775
new
() { Contents = [new TextContent("L") { Annotations = [new()] }] },
776
new
(null, "M"),
777
new
(null, "N"),
778
new
() { Contents = [new TextContent("O") { Annotations = [new()] }] },
779
new
() { Contents = [new TextContent("P") { Annotations = [new()] }] },
804
new
(null, "Hello, "),
805
new
(null, "world!"),
806
new
() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] },
834
new
(ChatRole.Tool, "a") { MessageId = "4", CreatedAt = early },
837
new
(null, "b") { CreatedAt = unixEpoch },
840
new
(null, "c") { CreatedAt = beforeEpoch },
843
new
(null, "d") { CreatedAt = middle },
846
new
(null, "e") { CreatedAt = early },
849
new
(null, "f") { CreatedAt = late },
852
new
(null, "g") { CreatedAt = unixEpoch },
855
new
(null, "h") { CreatedAt = null },
903
new
(ChatRole.Assistant, "a") { CreatedAt = first },
904
new
(null, "b") { CreatedAt = second },
930
new
(null, "Let's generate"),
931
new
(null, " some images"),
934
new
() { Contents = [new ImageGenerationToolResultContent("img1") { Outputs = [image1] }] },
937
new
() { Contents = [new ImageGenerationToolResultContent("img2") { Outputs = [image2] }] },
940
new
() { Contents = [new ImageGenerationToolResultContent("img1") { Outputs = [image3] }] },
943
new
() { Contents = [new ImageGenerationToolResultContent("img2") { Outputs = [image4] }] },
946
new
(null, "Here are those generated images"),
988
new
() { Contents = [new ImageGenerationToolResultContent("id-1") { Outputs = [image1] }] },
991
new
() { Contents = [new ImageGenerationToolResultContent("id-2") { Outputs = [image2] }] },
994
new
() { Contents = [new ImageGenerationToolResultContent("id-3") { Outputs = [image3] }] },
1020
new
(null, "Searching..."),
1023
new
() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["first query"] }] },
1026
new
(null, " found results"),
1029
new
() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["second query"], RawRepresentation = rawRepresentation, AdditionalProperties = additionalProps }] },
1032
new
() { Contents = [new WebSearchToolCallContent("ws2") { Queries = ["AI safety"] }] },
1035
new
() { Contents = [new WebSearchToolCallContent("ws1")] },
1037
new
(null, " done"),
1067
new
() { Contents = [new WebSearchToolCallContent("ws1")] },
1068
new
() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["query from second"] }] },
1086
new
() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["q1"] }] },
1087
new
() { Contents = [new WebSearchToolCallContent("ws2") { Queries = ["q2"] }] },
1088
new
() { Contents = [new WebSearchToolCallContent("ws3") { Queries = ["q3"] }] },
1116
new
(null, "Searching the web..."),
1120
new
() { Contents = [inProgress] },
1123
new
() { Contents = [new WebSearchToolCallContent("ws1") { Queries = ["dotnet extensions"] }] },
1127
new
() { Contents = [new FunctionCallContent("fc1", "SearchTool", new Dictionary<string, object?> { ["q"] = "test" })] },
ChatCompletion\ChatResponseUpdateTests.cs (10)
16
ChatResponseUpdate update =
new
();
33
ChatResponseUpdate update =
new
();
87
ChatResponseUpdate update =
new
()
115
ChatResponseUpdate original =
new
()
178
ChatResponseUpdate original =
new
()
250
var original = new
ChatResponseUpdate
291
var original = new
ChatResponseUpdate
319
var original = new
ChatResponseUpdate
();
343
var original = new
ChatResponseUpdate
378
var original = new
ChatResponseUpdate
ChatCompletion\DelegatingChatClientTests.cs (2)
61
new
(ChatRole.User, "Message 1"),
62
new
(ChatRole.User, "Message 2")
Microsoft.Extensions.AI.Evaluation.Safety (1)
ContentSafetyChatClient.cs (1)
100
yield return new
ChatResponseUpdate
(ChatRole.Assistant, annotationResult)
Microsoft.Extensions.AI.OpenAI (3)
OpenAIChatClient.cs (2)
379
ChatResponseUpdate responseUpdate =
new
()
453
ChatResponseUpdate responseUpdate =
new
()
OpenAIResponsesChatClient.cs (1)
386
new
(lastRole, content is not null ? [content] : null)
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIConversionTests.cs (10)
1694
var responseUpdate = new
ChatResponseUpdate
(ChatRole.Assistant, "Hello")
1712
var responseUpdate = new
ChatResponseUpdate
(ChatRole.Assistant, "Hello, world!")
1741
var responseUpdate = new
ChatResponseUpdate
1780
var responseUpdate = new
ChatResponseUpdate
(ChatRole.Assistant, [functionCallContent])
1815
var responseUpdate = new
ChatResponseUpdate
(ChatRole.Assistant, [functionCall1, functionCall2])
1843
var responseUpdate = new
ChatResponseUpdate
(ChatRole.Assistant,
1891
var responseUpdate = new
ChatResponseUpdate
(inputRole, "Test message");
1917
var responseUpdate = new
ChatResponseUpdate
(ChatRole.Assistant, "Test")
1938
new
ChatResponseUpdate
(ChatRole.Assistant, "Hello, ")
1945
new
ChatResponseUpdate
(ChatRole.Assistant, "world!")
Microsoft.Extensions.AI.Tests (65)
ChatCompletion\ConfigureOptionsChatClientTests.cs (1)
38
var expectedUpdates = Enumerable.Range(0, 3).Select(i => new
ChatResponseUpdate
()).ToArray();
ChatCompletion\DistributedCachingChatClientTest.cs (16)
250
new
()
263
new
()
268
new
()
314
new
(ChatRole.Assistant, "This"),
315
new
(ChatRole.Assistant, " becomes one chunk"),
316
new
() { Role = ChatRole.Assistant, Contents = [new FunctionCallContent("callId1", "separator")] },
317
new
(ChatRole.Assistant, "... and this"),
318
new
(ChatRole.Assistant, " becomes another"),
319
new
(ChatRole.Assistant, " one."),
369
new
() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] },
370
new
() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] },
371
new
()
382
new
()
437
new
(ChatRole.Assistant, "Chunk 1"),
485
() =>
new
(ChatRole.Assistant, "Chunk 1"),
524
[() =>
new
(ChatRole.Assistant, "A good result")]);
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (7)
1482
yield return new
ChatResponseUpdate
(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId };
1485
new
ChatResponseUpdate
(
1558
yield return new
ChatResponseUpdate
(ChatRole.Assistant, [new TextContent("Text 1")]) { MessageId = messageId };
1560
yield return new
ChatResponseUpdate
(ChatRole.Assistant, [new TextContent("Text 2")]) { MessageId = messageId };
1562
yield return new
ChatResponseUpdate
(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = messageId };
1564
yield return new
ChatResponseUpdate
(
1571
yield return new
ChatResponseUpdate
(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func3")]) { MessageId = messageId };
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
1192
new
() { Contents = [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["text"] = "Input 1" })] },
1193
new
() { Contents = [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["text"] = "Input 2" })] }
1198
updates = [
new
() { Contents = [new TextContent("OK bye")] }];
ChatCompletion\ImageGeneratingChatClientTests.cs (3)
229
yield return
new
(ChatRole.Assistant, "test");
359
yield return new
ChatResponseUpdate
(ChatRole.Assistant,
488
yield return new
ChatResponseUpdate
(ChatRole.Assistant, contents);
ChatCompletion\LoggingChatClientTests.cs (2)
108
yield return
new
(ChatRole.Assistant, "blue ");
109
yield return
new
(ChatRole.Assistant, "whale");
ChatCompletion\OpenTelemetryChatClientTests.cs (22)
74
yield return new
ChatResponseUpdate
(ChatRole.Assistant, text)
80
yield return new
ChatResponseUpdate
85
yield return new
ChatResponseUpdate
422
yield return
new
(ChatRole.Assistant, "Assistant response text");
423
yield return
new
() { Contents = [new TextReasoningContent("This is reasoning")] };
424
yield return
new
() { Contents = [new FunctionCallContent("call-123", "GetWeather", new Dictionary<string, object?> { ["location"] = "Seattle" })] };
425
yield return
new
() { Contents = [new FunctionResultContent("call-123", "72°F and sunny")] };
426
yield return
new
() { Contents = [new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png")] };
427
yield return
new
() { Contents = [new UriContent(new Uri("https://example.com/image.jpg"), "image/jpeg")] };
428
yield return
new
() { Contents = [new HostedFileContent("file-abc123")] };
676
yield return
new
(ChatRole.Assistant, "Processing with tools...");
677
yield return
new
() { Contents = [new CodeInterpreterToolCallContent("ci-call-1") { Inputs = [new TextContent("print('hello')")] }] };
678
yield return
new
() { Contents = [new CodeInterpreterToolResultContent("ci-call-1") { Outputs = [new TextContent("hello")] }] };
679
yield return
new
() { Contents = [new ImageGenerationToolCallContent("img-123")] };
680
yield return
new
()
690
yield return
new
() { Contents = [new McpServerToolCallContent("mcp-call-1", "myTool", "myServer") { Arguments = new Dictionary<string, object?> { ["param1"] = "value1" } }] };
691
yield return
new
() { Contents = [new McpServerToolResultContent("mcp-call-1") { Outputs = [new TextContent("Tool result")] }] };
917
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "First") { ResponseId = "id1", ModelId = "responsemodel" };
919
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "Second") { ResponseId = "id1" };
921
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "Third") { ResponseId = "id1" };
1104
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "chunk1");
1106
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "chunk2");
ChatCompletion\ReducingChatClientTests.cs (2)
51
var expectedUpdates = new[] { new
ChatResponseUpdate
(ChatRole.Assistant, "It's"), new
ChatResponseUpdate
(null, " sunny!") };
ChatCompletion\UseDelegateChatClientTests.cs (5)
51
return YieldUpdates(new
ChatResponseUpdate
(null, "world"));
133
return YieldUpdates(new
ChatResponseUpdate
(null, "hello"));
154
yield return
new
(null, " world");
193
return YieldUpdates(new
ChatResponseUpdate
(null, "streaming hello"));
225
yield return
new
(null, " world (streaming)");
ChatRouting\FailoverChatClientTests.cs (4)
1018
[new
ChatResponseUpdate
(ChatRole.Assistant, "first")],
1166
yield return new
ChatResponseUpdate
(ChatRole.Assistant, text);
1175
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "never");
1187
yield return new
ChatResponseUpdate
(ChatRole.Assistant, "never");
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
73
yield return
new
(ChatRole.Assistant, output)
443 references to ChatResponseUpdate
Microsoft.AspNetCore.Components.AI (23)
Engine\IConversationThread.cs (2)
41
void AppendUpdate(
ChatResponseUpdate
update);
52
IReadOnlyList<
ChatResponseUpdate
> GetUpdates();
Engine\UIAgent.cs (12)
144
var
userUpdate = new ChatResponseUpdate
162
var responseUpdates = new List<
ChatResponseUpdate
>();
163
var assistantUpdates = new List<
ChatResponseUpdate
>();
174
await foreach (
var
update in _chatClient.GetStreamingResponseAsync(
181
var
processUpdate = ApplyStateMapper(update);
221
foreach (
var
update in responseUpdates)
252
var assistantUpdates = new List<
ChatResponseUpdate
>();
254
foreach (
var
update in updates)
282
var
processUpdate = ApplyStateMapper(update);
306
internal virtual
ChatResponseUpdate
ApplyStateMapper(
ChatResponseUpdate
update)
319
private void AddResponseToHistory(List<
ChatResponseUpdate
> updates)
Engine\UIAgentOfT.cs (2)
86
internal override
ChatResponseUpdate
ApplyStateMapper(
ChatResponseUpdate
update)
Pipeline\BlockMappingContext.cs (3)
20
ChatResponseUpdate
update,
31
public
ChatResponseUpdate
Update { get; }
89
var
update = new ChatResponseUpdate
Pipeline\BlockMappingPipeline.cs (1)
52
ChatResponseUpdate
update,
Pipeline\StateMapperContext.cs (3)
16
internal StateMapperContext(
ChatResponseUpdate
update)
25
public
ChatResponseUpdate
Update { get; }
98
internal
ChatResponseUpdate
GetFilteredUpdate()
Microsoft.Extensions.AI (54)
ChatCompletion\AnonymousDelegatingChatClient.cs (7)
29
private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? _getStreamingResponseFunc;
78
Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? getStreamingResponseFunc)
127
public override IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
134
var updates = Channel.CreateBounded<
ChatResponseUpdate
>(1);
144
await foreach (
var
update in InnerClient.GetStreamingResponseAsync(messages, options, cancellationToken))
187
static async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsyncViaGetResponseAsync(Task<ChatResponse> task)
190
foreach (
var
update in response.ToChatResponseUpdates())
ChatCompletion\CachingChatClient.cs (12)
74
public override IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
84
private async IAsyncEnumerable<
ChatResponseUpdate
> GetCachedStreamingResponseAsync(
97
foreach (
var
chunk in chatResponse.ToChatResponseUpdates())
105
List<
ChatResponseUpdate
> capturedItems = [];
106
await foreach (
var
chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken))
123
foreach (
var
chunk in existingChunks)
132
List<
ChatResponseUpdate
> capturedItems = [];
133
await foreach (
var
chunk in base.GetStreamingResponseAsync(messages, options, cancellationToken))
163
/// Returns a previously cached list of <see cref="
ChatResponseUpdate
"/> values, if available.
170
protected abstract Task<IReadOnlyList<
ChatResponseUpdate
>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken);
185
/// Stores a list of <see cref="
ChatResponseUpdate
"/> values in the underlying cache.
194
protected abstract Task WriteCacheStreamingAsync(string key, IReadOnlyList<
ChatResponseUpdate
> value, CancellationToken cancellationToken);
ChatCompletion\ChatClientBuilder.cs (1)
144
Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? getStreamingResponseFunc)
ChatCompletion\ConfigureOptionsChatClient.cs (2)
42
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
45
await 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
"/>,
86
protected override async Task<IReadOnlyList<
ChatResponseUpdate
>?> ReadCacheStreamingAsync(string key, CancellationToken cancellationToken)
93
return (IReadOnlyList<
ChatResponseUpdate
>?)JsonSerializer.Deserialize(existingJson, JsonSerializerOptions.GetTypeInfo(typeof(IReadOnlyList<
ChatResponseUpdate
>)));
111
protected override async Task WriteCacheStreamingAsync(string key, IReadOnlyList<
ChatResponseUpdate
> value, CancellationToken cancellationToken)
117
var 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)
437
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
457
List<
ChatResponseUpdate
> updates = []; // updates from the current response
542
await foreach (
var
update in base.GetStreamingResponseAsync(messages, options, cancellationToken))
546
Throw.InvalidOperationException($"The inner {nameof(IChatClient)} streamed a null {nameof(
ChatResponseUpdate
)}.");
623
var
updateToYield = updates[lastYieldedUpdateIndex];
654
var
updateToYield = updates[lastYieldedUpdateIndex];
707
private static
ChatResponseUpdate
ConvertToolResultMessageToUpdate(ChatMessage message, string? conversationId, string? messageId) =>
968
private static void MarkServerHandledFunctionCalls(List<
ChatResponseUpdate
> updates, List<FunctionCallContent>? functionCallContents)
ChatCompletion\ImageGeneratingChatClient.cs (3)
95
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
106
await foreach (
var
update in base.GetStreamingResponseAsync(processedMessages, processedOptions, cancellationToken))
114
var
modifiedUpdate = update.Clone();
ChatCompletion\LoggingChatClient.cs (3)
100
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
115
IAsyncEnumerator<
ChatResponseUpdate
> e;
133
ChatResponseUpdate
? update = null;
ChatCompletion\OpenTelemetryChatClient.cs (4)
166
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
179
IAsyncEnumerable<
ChatResponseUpdate
> updates;
191
List<
ChatResponseUpdate
> trackedUpdates = [];
207
ChatResponseUpdate
update;
ChatCompletion\ReducingChatClient.cs (2)
41
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
46
await foreach (
var
update in base.GetStreamingResponseAsync(messages, options, cancellationToken).ConfigureAwait(false))
ChatRouting\FailoverChatClient.cs (5)
165
public sealed override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
183
IAsyncEnumerator<
ChatResponseUpdate
>? enumerator = null;
241
out
ChatResponseUpdate
current,
342
IAsyncEnumerator<
ChatResponseUpdate
> enumerator,
343
out
ChatResponseUpdate
current,
Microsoft.Extensions.AI.Abstractions (47)
ChatCompletion\ChatClientExtensions.cs (2)
131
public static IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
151
public 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>
122
public
ChatResponseUpdate
[] ToChatResponseUpdates()
124
ChatResponseUpdate
? extra = null;
139
var 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
59
public static void AddMessages(this IList<ChatMessage> list, IEnumerable<
ChatResponseUpdate
> updates)
64
if (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
82
public 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
114
this IList<ChatMessage> list, IAsyncEnumerable<
ChatResponseUpdate
> updates, CancellationToken cancellationToken = default)
122
IList<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
137
this IEnumerable<
ChatResponseUpdate
> updates)
143
foreach (
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
165
this IAsyncEnumerable<
ChatResponseUpdate
> updates, CancellationToken cancellationToken = default)
172
IAsyncEnumerable<
ChatResponseUpdate
> updates, CancellationToken cancellationToken)
176
await foreach (
var
update in updates.WithCancellation(cancellationToken).ConfigureAwait(false))
535
/// <summary>Processes the <see cref="
ChatResponseUpdate
"/>, incorporating its contents into <paramref name="response"/>.</summary>
538
private 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>
68
public
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)
48
public virtual IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
ChatCompletion\IChatClient.cs (1)
54
IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
ChatRouting\RoutingChatClient.cs (2)
80
public virtual async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
90
await foreach (
ChatResponseUpdate
update in
Utilities\AIJsonUtilities.Defaults.cs (2)
104
[JsonSerializable(typeof(
ChatResponseUpdate
))]
105
[JsonSerializable(typeof(IReadOnlyList<
ChatResponseUpdate
>))]
Microsoft.Extensions.AI.Abstractions.Tests (71)
ChatCompletion\ChatClientExtensionsTests.cs (5)
151
await foreach (
var
update in client.GetStreamingResponseAsync("hello", expectedOptions, cts.Token))
238
await foreach (
var
update in client.GetStreamingResponseAsync([], expectedChatOptions, cts.Token))
247
private static async IAsyncEnumerable<
ChatResponseUpdate
> YieldAsync(params
ChatResponseUpdate
[] updates)
250
foreach (
var
update in updates)
ChatCompletion\ChatResponseTests.cs (7)
250
ChatResponseUpdate
[] updates = response.ToChatResponseUpdates();
254
ChatResponseUpdate
update0 = updates[0];
263
ChatResponseUpdate
update1 = updates[1];
292
ChatResponseUpdate
[] updates = response.ToChatResponseUpdates();
296
ChatResponseUpdate
update0 = updates[0];
305
ChatResponseUpdate
update1 = updates[1];
314
ChatResponseUpdate
update2 = updates[2];
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (30)
21
Assert.Throws<ArgumentNullException>("updates", () => ((List<
ChatResponseUpdate
>)null!).ToChatResponse());
29
ChatResponseUpdate
[] updates =
73
ChatResponseUpdate
[] updates =
129
ChatResponseUpdate
[] updates =
182
ChatResponseUpdate
[] updates =
241
ChatResponseUpdate
[] updates =
276
ChatResponseUpdate
[] updates =
311
ChatResponseUpdate
[] updates =
346
ChatResponseUpdate
[] updates =
379
ChatResponseUpdate
[] updates =
414
ChatResponseUpdate
[] updates =
452
ChatResponseUpdate
[] updates =
504
ChatResponseUpdate
[] updates =
537
ChatResponseUpdate
[] updates =
626
List<
ChatResponseUpdate
> updates = [];
687
ChatResponseUpdate
[] updates =
725
ChatResponseUpdate
[] updates =
762
ChatResponseUpdate
[] updates =
802
ChatResponseUpdate
[] updates =
830
ChatResponseUpdate
[] updates =
901
ChatResponseUpdate
[] updates =
928
ChatResponseUpdate
[] updates =
985
ChatResponseUpdate
[] updates =
1018
ChatResponseUpdate
[] updates =
1065
ChatResponseUpdate
[] updates =
1084
ChatResponseUpdate
[] updates =
1114
ChatResponseUpdate
[] updates =
1143
private static async IAsyncEnumerable<
ChatResponseUpdate
> YieldAsync(IEnumerable<
ChatResponseUpdate
> updates)
1145
foreach (
ChatResponseUpdate
update in updates)
ChatCompletion\ChatResponseUpdateTests.cs (20)
16
ChatResponseUpdate
update = new();
33
ChatResponseUpdate
update = new();
87
ChatResponseUpdate
update = new()
115
ChatResponseUpdate
original = new()
139
ChatResponseUpdate
? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatResponseUpdate);
178
ChatResponseUpdate
original = new()
203
ChatResponseUpdate
? result = JsonSerializer.Deserialize<
ChatResponseUpdate
>(json, AIJsonUtilities.DefaultOptions);
250
var
original = new ChatResponseUpdate
266
var
clone = original.Clone();
291
var
original = new ChatResponseUpdate
298
var
clone = original.Clone();
319
var
original = new ChatResponseUpdate();
322
var
clone = original.Clone();
343
var
original = new ChatResponseUpdate
352
var
clone = original.Clone();
378
var
original = new ChatResponseUpdate
385
var
clone = original.Clone();
432
ChatResponseUpdate
? result = JsonSerializer.Deserialize<
ChatResponseUpdate
>(Json, AIJsonUtilities.DefaultOptions);
ChatCompletion\DelegatingChatClientTests.cs (1)
59
ChatResponseUpdate
[] expectedResults =
ChatRouting\RoutingChatClientTests.cs (5)
131
private static async Task<List<
ChatResponseUpdate
>> CollectAsync(
132
IAsyncEnumerable<
ChatResponseUpdate
> updates)
134
var result = new List<
ChatResponseUpdate
>();
135
await foreach (
ChatResponseUpdate
update in updates)
167
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
TestChatClient.cs (2)
22
public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? GetStreamingResponseAsyncCallback { get; set; }
32
public 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)
64
protected override async Task<IReadOnlyList<
ChatResponseUpdate
>?> ReadCacheStreamingAsync(
70
IReadOnlyList<
ChatResponseUpdate
>? updates =
122
IReadOnlyList<
ChatResponseUpdate
> value,
SimpleChatClient.cs (3)
58
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
63
List<
ChatResponseUpdate
>? updates = null;
68
await foreach (
ChatResponseUpdate
update in
Microsoft.Extensions.AI.Evaluation.Safety (2)
ContentSafetyChatClient.cs (2)
83
public async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
109
await foreach (
var
update in
Microsoft.Extensions.AI.Integration.Tests (16)
CallCountingChatClient.cs (1)
26
public override IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
ChatClientIntegrationTests.cs (11)
106
await foreach (
var
chunk in ChatClient.GetStreamingResponseAsync(chatHistory))
141
List<
ChatResponseUpdate
> chunks = [];
142
await foreach (
var
chunk in response)
271
await foreach (
var
chunk in response)
683
await foreach (
var
update in chatClient.GetStreamingResponseAsync([message]))
692
await foreach (
var
update in chatClient.GetStreamingResponseAsync([message]))
703
await foreach (
var
update in chatClient.GetStreamingResponseAsync([message]))
861
await foreach (
var
update in chatClient.GetStreamingResponseAsync("What's the biggest animal?"))
912
await foreach (
var
update in chatClient.GetStreamingResponseAsync(
1284
await foreach (
var
chunk in chatClient.GetStreamingResponseAsync(messages))
1386
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
PromptBasedFunctionCallingChatClient.cs (2)
137
public override async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
141
foreach (
var
update in response.ToChatResponseUpdates())
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22
public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? GetStreamingResponseAsyncCallback { get; set; }
32
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.OpenAI (20)
MicrosoftExtensionsAIChatExtensions.cs (7)
128
/// sequence of <see cref="
ChatResponseUpdate
"/> instances.
132
/// <returns>A sequence of converted <see cref="
ChatResponseUpdate
"/> instances.</returns>
136
this IAsyncEnumerable<
ChatResponseUpdate
> responseUpdates, [EnumeratorCancellation] CancellationToken cancellationToken = default)
140
await 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>
275
public 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>
79
public static IAsyncEnumerable<
ChatResponseUpdate
> AsChatResponseUpdatesAsync(
OpenAIChatClient.cs (4)
111
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
348
internal static async IAsyncEnumerable<
ChatResponseUpdate
> FromOpenAIStreamingChatCompletionAsync(
379
ChatResponseUpdate
responseUpdate = new()
453
ChatResponseUpdate
responseUpdate = new()
OpenAIResponsesChatClient.cs (6)
325
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
361
internal static async IAsyncEnumerable<
ChatResponseUpdate
> FromOpenAIStreamingResponseUpdatesAsync(
385
ChatResponseUpdate
CreateUpdate(AIContent? content = null) =>
450
var
update = CreateUpdate(ToUsageDetails(completedUpdate.Response) is { } usage ? new UsageContent(usage) : null);
522
var
mcpUpdate = CreateUpdate();
620
var
toolCallUpdate = CreateUpdate(new ToolCallContent(outputItemDoneUpdate.Item.Id));
Microsoft.Extensions.AI.OpenAI.Tests (111)
OpenAIChatClientTests.cs (11)
234
List<
ChatResponseUpdate
> updates = [];
235
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
496
await foreach (
var
update in client.GetStreamingResponseAsync("hello", chatOptions))
651
await foreach (
var
update in client.GetStreamingResponseAsync("hello", chatOptions))
1325
List<
ChatResponseUpdate
> updates = [];
1326
await foreach (
var
update in client.GetStreamingResponseAsync("How old is Alice?", new()
1731
List<
ChatResponseUpdate
> updates = [];
1732
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
1965
List<
ChatResponseUpdate
> updates = [];
1966
await foreach (
var
update in client.GetStreamingResponseAsync("hello"))
2040
await foreach (
var
update in client.GetStreamingResponseAsync("hello"))
OpenAIConversionTests.cs (16)
918
List<
ChatResponseUpdate
> updates = [];
919
await foreach (
var
update in CreateUpdates().AsChatResponseUpdatesAsync())
1009
List<
ChatResponseUpdate
> updates = [];
1010
await foreach (
ChatResponseUpdate
update in CreateStreamingUpdates().AsChatResponseUpdatesAsync())
1133
List<
ChatResponseUpdate
> updates = [];
1134
await foreach (
ChatResponseUpdate
update in CreateStreamingUpdates().AsChatResponseUpdatesAsync())
1665
var asyncEnumerable = ((IAsyncEnumerable<
ChatResponseUpdate
>)null!).AsOpenAIStreamingChatCompletionUpdatesAsync();
1672
var updates = new List<
ChatResponseUpdate
>();
1694
var
responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello")
1712
var
responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Hello, world!")
1741
var
responseUpdate = new ChatResponseUpdate
1780
var
responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCallContent])
1815
var
responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, [functionCall1, functionCall2])
1843
var
responseUpdate = new ChatResponseUpdate(ChatRole.Assistant,
1891
var
responseUpdate = new ChatResponseUpdate(inputRole, "Test message");
1917
var
responseUpdate = new ChatResponseUpdate(ChatRole.Assistant, "Test")
OpenAIResponseClientIntegrationTests.cs (5)
426
await foreach (
var
update in ChatClient.GetStreamingResponseAsync("What is the capital of France?", chatOptions))
449
await foreach (
var
update in ChatClient.GetStreamingResponseAsync("What is the capital of France?", chatOptions))
465
await foreach (
var
update in ChatClient.GetStreamingResponseAsync([], chatOptions))
490
await foreach (
var
update in chatClient.GetStreamingResponseAsync("What time is it?", chatOptions))
843
await foreach (
var
update in ChatClient.GetStreamingResponseAsync(deserializedHistory, chatOptions))
OpenAIResponseClientTests.cs (79)
296
List<
ChatResponseUpdate
> updates = [];
297
await foreach (
var
update in client.GetStreamingResponseAsync("Calculate the sum of the first 5 positive integers.", new()
426
List<
ChatResponseUpdate
> updates = [];
427
await foreach (
var
update in client.GetStreamingResponseAsync("Solve this problem step by step.", new()
469
var
assistantUpdate = updates.First(u => u.Role == ChatRole.Assistant && !string.IsNullOrEmpty(u.Text));
556
List<
ChatResponseUpdate
> updates = [];
557
await foreach (
var
update in client.GetStreamingResponseAsync("Solve this problem step by step.", new()
658
List<
ChatResponseUpdate
> updates = [];
659
await foreach (
var
update in client.GetStreamingResponseAsync("Solve this problem step by step.", new()
733
List<
ChatResponseUpdate
> updates = [];
734
await foreach (
var
update in client.GetStreamingResponseAsync("Solve this problem step by step.", new()
852
List<
ChatResponseUpdate
> updates = [];
853
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
1098
List<
ChatResponseUpdate
> updates = [];
1099
await foreach (
var
update in client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "Search the web for the temperature today in Fremont")], chatOptions))
3218
List<
ChatResponseUpdate
> updates = [];
3219
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
3311
List<
ChatResponseUpdate
> updates = [];
3312
await foreach (
var
update in client.GetStreamingResponseAsync([], chatOptions))
3378
await foreach (
var
update in client.GetStreamingResponseAsync("Please book a hotel for me", chatOptions))
3797
List<
ChatResponseUpdate
> updates = [];
3798
await foreach (
var
update in client.GetStreamingResponseAsync("Calculate the sum of numbers from 1 to 10 using Python", new()
3815
foreach (
var
update in codeInterpreterCallUpdates)
4294
List<
ChatResponseUpdate
> updates = [];
4295
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
4375
List<
ChatResponseUpdate
> updates = [];
4376
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
4516
List<
ChatResponseUpdate
> updates = [];
4517
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
4593
List<
ChatResponseUpdate
> updates = [];
4594
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
4671
List<
ChatResponseUpdate
> updates = [];
4672
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
4868
List<
ChatResponseUpdate
> updates = [];
4869
await foreach (
var
update in client.GetStreamingResponseAsync("hello", new()
5799
List<
ChatResponseUpdate
> updates = [];
5800
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
5834
List<
ChatResponseUpdate
> updates = [];
5835
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
5869
List<
ChatResponseUpdate
> updates = [];
5870
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
5907
List<
ChatResponseUpdate
> updates = [];
5908
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
5945
List<
ChatResponseUpdate
> updates = [];
5946
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
5951
var
refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal"));
6003
List<
ChatResponseUpdate
> updates = [];
6004
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
6009
var
errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent));
6046
List<
ChatResponseUpdate
> updates = [];
6047
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
6052
var
errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent));
6089
List<
ChatResponseUpdate
> updates = [];
6090
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
6095
var
errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent));
6132
List<
ChatResponseUpdate
> updates = [];
6133
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
6138
var
annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0));
6207
List<
ChatResponseUpdate
> updates = [];
6208
await foreach (
var
update in client.GetStreamingResponseAsync("test"))
6214
var
functionCallUpdate = updates.FirstOrDefault(u => u.Contents.OfType<FunctionCallContent>().Any());
6222
var
functionResultUpdate = updates.FirstOrDefault(u => u.Contents.OfType<FunctionResultContent>().Any());
6610
List<
ChatResponseUpdate
> updates = [];
6620
await foreach (
var
update in client.GetStreamingResponseAsync("Generate an image of a dog", new ChatOptions
6631
var
createdUpdate = updates.First(u => u.CreatedAt.HasValue);
6636
var
toolCallUpdate = updates.FirstOrDefault(u =>
6643
var
partialImageUpdate = updates.FirstOrDefault(u =>
6649
var
completionUpdate = updates.FirstOrDefault(u =>
6727
List<
ChatResponseUpdate
> updates = [];
6738
await foreach (
var
update in client.GetStreamingResponseAsync("Generate an image of a sunset", new ChatOptions
6758
var
partialUpdate = partialImageUpdates.FirstOrDefault(u =>
6795
var
toolCallUpdate = updates.FirstOrDefault(u =>
6928
await foreach (
var
update in client.GetStreamingResponseAsync("hello"))
7405
List<
ChatResponseUpdate
> updates = [];
7406
await foreach (
var
update in client.GetStreamingResponseAsync("What is the latest news about .NET?", new()
7433
var
wsResultUpdate = updates.FirstOrDefault(u => u.Contents.OfType<WebSearchToolResultContent>().Any());
9080
List<
ChatResponseUpdate
> updates = [];
9081
await foreach (
var
update in client.GetStreamingResponseAsync(
9088
var
functionCallUpdate = updates.FirstOrDefault(u => u.Contents.OfType<FunctionCallContent>().Any());
Microsoft.Extensions.AI.Tests (86)
ChatCompletion\ConfigureOptionsChatClientTests.cs (3)
89
static async IAsyncEnumerable<
ChatResponseUpdate
> YieldUpdates(
ChatResponseUpdate
[] updates)
91
foreach (
var
update in updates)
ChatCompletion\DistributedCachingChatClientTest.cs (13)
248
List<
ChatResponseUpdate
> actualUpdate =
261
List<
ChatResponseUpdate
> expectedCachedResponse =
312
List<
ChatResponseUpdate
> expectedResponse =
345
ChatResponseUpdate
update = Assert.Single(await ToListAsync(result2));
367
List<
ChatResponseUpdate
> expectedResponse =
417
var
item = Assert.Single(items);
435
List<
ChatResponseUpdate
> expectedResponse =
483
return ToAsyncEnumerableAsync<
ChatResponseUpdate
>(Task.CompletedTask,
522
return ToAsyncEnumerableAsync<
ChatResponseUpdate
>(
831
private static async Task AssertResponsesEqualAsync(IReadOnlyList<
ChatResponseUpdate
> expected, IAsyncEnumerable<
ChatResponseUpdate
> actual)
835
foreach (
var
expectedItem in expected)
839
var
actualItem = actualEnumerator.Current;
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (5)
1474
async IAsyncEnumerable<
ChatResponseUpdate
> YieldInnerClientUpdates(
1499
await foreach (
var
update in updates)
1550
async IAsyncEnumerable<
ChatResponseUpdate
> YieldInnerClientUpdates(
1580
await foreach (
var
update in updates)
2131
public override IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
1186
List<
ChatResponseUpdate
> updates;
1201
foreach (
var
update in updates)
1761
await foreach (
var
update in client.GetStreamingResponseAsync(
ChatCompletion\ImageGeneratingChatClientTests.cs (9)
226
static async IAsyncEnumerable<
ChatResponseUpdate
> GetUpdatesAsync()
241
await foreach (
var
update in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions))
356
async IAsyncEnumerable<
ChatResponseUpdate
> GetUpdatesAsync()
372
var updates = new List<
ChatResponseUpdate
>();
373
await foreach (
var
responseUpdate in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions))
380
var
update = updates[0];
475
async IAsyncEnumerable<
ChatResponseUpdate
> GetUpdatesAsync()
500
var updates = new List<
ChatResponseUpdate
>();
501
await foreach (
var
update in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions))
ChatCompletion\LoggingChatClientTests.cs (2)
105
static async IAsyncEnumerable<
ChatResponseUpdate
> GetUpdatesAsync()
117
await foreach (
var
update in client.GetStreamingResponseAsync(
ChatCompletion\OpenTelemetryChatClientTests.cs (11)
66
async static IAsyncEnumerable<
ChatResponseUpdate
> CallbackAsync(
153
await foreach (
var
update in chatClient.GetStreamingResponseAsync(messages, options))
418
async static IAsyncEnumerable<
ChatResponseUpdate
> CallbackAsync(
456
await foreach (
var
update in chatClient.GetStreamingResponseAsync(messages))
672
async static IAsyncEnumerable<
ChatResponseUpdate
> CallbackAsync(
710
await foreach (
var
update in chatClient.GetStreamingResponseAsync(messages))
913
async static IAsyncEnumerable<
ChatResponseUpdate
> CallbackAsync(
932
await foreach (
var
update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")], new ChatOptions { ModelId = "mymodel" }))
1037
await foreach (
var
update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")]))
1091
await foreach (
var
update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")]))
1100
async static IAsyncEnumerable<
ChatResponseUpdate
> CallbackAsync(
ChatCompletion\ReducingChatClientTests.cs (2)
73
var updates = new List<
ChatResponseUpdate
>();
74
await foreach (
var
update in client.GetStreamingResponseAsync(originalMessages))
ChatCompletion\UseDelegateChatClientTests.cs (7)
146
static async IAsyncEnumerable<
ChatResponseUpdate
> Impl(
149
await foreach (
var
update in innerClient.GetStreamingResponseAsync(messages, options, cancellationToken))
217
static async IAsyncEnumerable<
ChatResponseUpdate
> Impl(
220
await foreach (
var
update in innerClient.GetStreamingResponseAsync(messages, options, cancellationToken))
239
private static async IAsyncEnumerable<
ChatResponseUpdate
> YieldUpdates(params
ChatResponseUpdate
[] updates)
241
foreach (
var
update in updates)
ChatRouting\FailoverChatClientTests.cs (25)
1038
var updates = new List<
ChatResponseUpdate
>();
1042
await foreach (
ChatResponseUpdate
update in router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]))
1079
List<
ChatResponseUpdate
> updates =
1110
List<
ChatResponseUpdate
> updates =
1143
private static async Task<List<
ChatResponseUpdate
>> CollectAsync(
1144
IAsyncEnumerable<
ChatResponseUpdate
> updates)
1146
var result = new List<
ChatResponseUpdate
>();
1147
await foreach (
ChatResponseUpdate
update in updates)
1155
private static async Task ConsumeOneAsync(IAsyncEnumerable<
ChatResponseUpdate
> updates)
1157
await using IAsyncEnumerator<
ChatResponseUpdate
> enumerator = updates.GetAsyncEnumerator();
1161
internal static async IAsyncEnumerable<
ChatResponseUpdate
> YieldUpdates(params string[] texts)
1170
internal static async IAsyncEnumerable<
ChatResponseUpdate
> ThrowingStream(string message)
1181
private static async IAsyncEnumerable<
ChatResponseUpdate
> CanceledStream(
1237
private sealed class ThrowingGetAsyncEnumeratorEnumerable : IAsyncEnumerable<
ChatResponseUpdate
>
1246
public IAsyncEnumerator<
ChatResponseUpdate
> GetAsyncEnumerator(
1251
private sealed class ThrowingCurrentAsyncEnumerable(Exception exception) : IAsyncEnumerable<
ChatResponseUpdate
>
1255
public IAsyncEnumerator<
ChatResponseUpdate
> GetAsyncEnumerator(
1261
Exception exception) : IAsyncEnumerator<
ChatResponseUpdate
>
1263
public
ChatResponseUpdate
Current => throw exception;
1275
private sealed class TrackingAsyncEnumerable : IAsyncEnumerable<
ChatResponseUpdate
>
1277
private readonly IReadOnlyList<
ChatResponseUpdate
> _updates;
1283
IReadOnlyList<
ChatResponseUpdate
> updates,
1296
public IAsyncEnumerator<
ChatResponseUpdate
> GetAsyncEnumerator(
1300
private sealed class Enumerator : IAsyncEnumerator<
ChatResponseUpdate
>
1310
public
ChatResponseUpdate
Current { get; private set; } = null!;
ChatRouting\OrderedFailoverChatClientTests.cs (2)
204
await using (IAsyncEnumerator<
ChatResponseUpdate
> enumerator =
386
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
ChatRouting\SemanticRoutingChatClientTests.cs (1)
247
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22
public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? GetStreamingResponseAsyncCallback { get; set; }
32
public 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)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
22
public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<
ChatResponseUpdate
>>? GetStreamingResponseAsyncCallback { get; set; }
32
public IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
57
public virtual async IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
Microsoft.ML.GenAI.LLaMA (1)
Llama3CausalLMChatClient.cs (1)
46
public override IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
Microsoft.ML.GenAI.Phi (1)
Phi3\Phi3CausalLMChatClient.cs (1)
51
public override IAsyncEnumerable<
ChatResponseUpdate
> GetStreamingResponseAsync(
Microsoft.ML.GenAI.Samples (2)
MEAI\Llama3_1.cs (1)
49
await foreach (
var
response in client.GetStreamingResponseAsync([chatMessage]))
MEAI\Phi3.cs (1)
39
await foreach (
var
response in client.GetStreamingResponseAsync([chatMessage]))