42 writes to Contents
Microsoft.Extensions.AI (2)
ChatCompletion\FunctionInvokingChatClient.cs (2)
575updateToYield.Contents = updatedContents; 640Contents = message.Contents,
Microsoft.Extensions.AI.Abstractions (1)
ChatCompletion\ChatResponse.cs (1)
135Contents = message.Contents,
Microsoft.Extensions.AI.Abstractions.Tests (26)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (22)
35new() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] }, 36new() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] }, 243updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] }); 273new() { Contents = [new TextReasoningContent("D")] }, 274new() { Contents = [new TextReasoningContent("E")] }, 275new() { Contents = [new TextReasoningContent("F")] }, 278new() { Contents = [new TextReasoningContent("I")] }, 279new() { Contents = [new TextReasoningContent("J")] }, 281new() { Contents = [new TextReasoningContent("L")] }, 284new() { Contents = [new TextReasoningContent("O")] }, 285new() { Contents = [new TextReasoningContent("P")] }, 311new() { Contents = [new TextContent("D") { Annotations = [new()] }] }, 312new() { Contents = [new TextContent("E") { Annotations = [new()] }] }, 313new() { Contents = [new TextContent("F") { Annotations = [new()] }] }, 314new() { Contents = [new TextContent("G") { Annotations = [] }] }, 315new() { Contents = [new TextContent("H") { Annotations = [] }] }, 316new() { Contents = [new TextContent("I") { Annotations = [new()] }] }, 317new() { Contents = [new TextContent("J") { Annotations = [new()] }] }, 319new() { Contents = [new TextContent("L") { Annotations = [new()] }] }, 322new() { Contents = [new TextContent("O") { Annotations = [new()] }] }, 323new() { Contents = [new TextContent("P") { Annotations = [new()] }] }, 350new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] },
ChatCompletion\ChatResponseUpdateTests.cs (4)
49update.Contents = newList; 51update.Contents = null; 90Contents = 119Contents =
Microsoft.Extensions.AI.OpenAI.Tests (1)
OpenAIConversionTests.cs (1)
622Contents =
Microsoft.Extensions.AI.Tests (12)
ChatCompletion\DistributedCachingChatClientTest.cs (8)
252Contents = 265Contents = [new FunctionCallContent("someCallId", "someFn", new Dictionary<string, object?> { ["arg1"] = "value1" })], 269Contents = [new UsageContent(new() { InputTokenCount = 123, OutputTokenCount = 456, TotalTokenCount = 99999 })], 315new() { Role = ChatRole.Assistant, Contents = [new FunctionCallContent("callId1", "separator")] }, 368new() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] }, 369new() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] }, 373Contents = 384Contents =
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
742new() { Contents = [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["text"] = "Input 1" })] }, 743new() { Contents = [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["text"] = "Input 2" })] } 748updates = [new() { Contents = [new TextContent("OK bye")] }];
ChatCompletion\OpenTelemetryChatClientTests.cs (1)
82Contents = [new UsageContent(new()
76 references to Contents
Microsoft.Extensions.AI (3)
ChatCompletion\FunctionInvokingChatClient.cs (3)
513_ = CopyFunctionCalls(update.Contents, ref functionCallContents); 517IList<AIContent> contents = update.Contents; 573if (TryReplaceFunctionCallsWithApprovalRequests(updateToYield.Contents, out var updatedContents))
Microsoft.Extensions.AI.Abstractions (5)
ChatCompletion\ChatResponse.cs (1)
120extra.Contents.Add(new UsageContent(usage));
ChatCompletion\ChatResponseExtensions.cs (3)
86var contentsList = filter is null ? update.Contents : update.Contents.Where(filter).ToList(); 363foreach (var content in update.Contents)
ChatCompletion\ChatResponseUpdate.cs (1)
78/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
Microsoft.Extensions.AI.Abstractions.Tests (23)
ChatCompletion\ChatResponseUpdateTests.cs (23)
20Assert.Empty(update.Contents); 43Assert.Empty(update.Contents); 44update.Contents.Add(new TextContent("text")); 45Assert.Single(update.Contents); 47Assert.Same(update.Contents, update.Contents); 50Assert.Same(newList, update.Contents); 52Assert.NotNull(update.Contents); 53Assert.Empty(update.Contents); 101TextContent textContent = Assert.IsType<TextContent>(update.Contents[3]); 106((TextContent)update.Contents[3]).Text = "text-3"; 108Assert.Same(textContent, update.Contents[3]); 140Assert.Equal(5, result.Contents.Count); 142Assert.IsType<TextContent>(result.Contents[0]); 143Assert.Equal("text-1", ((TextContent)result.Contents[0]).Text); 145Assert.IsType<DataContent>(result.Contents[1]); 146Assert.Equal("data:image/png;base64,aGVsbG8=", ((DataContent)result.Contents[1]).Uri); 148Assert.IsType<FunctionCallContent>(result.Contents[2]); 149Assert.Equal("fc1", ((FunctionCallContent)result.Contents[2]).Name); 151Assert.IsType<DataContent>(result.Contents[3]); 152Assert.Equal("data"u8.ToArray(), ((DataContent)result.Contents[3]).Data.ToArray()); 154Assert.IsType<TextContent>(result.Contents[4]); 155Assert.Equal("text-2", ((TextContent)result.Contents[4]).Text);
Microsoft.Extensions.AI.AzureAIInference (3)
AzureAIInferenceChatClient.cs (3)
180responseUpdate.Contents.Add(new TextContent(update)); 213responseUpdate.Contents.Add(new UsageContent(new() 247responseUpdate.Contents.Add(callContent);
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
242Assert.Equal(i is < 10 or 11 ? 1 : 0, updates[i].Contents.Count); 1358FunctionCallContent fcc = Assert.IsType<FunctionCallContent>(Assert.Single(updates[updates.Count - 1].Contents));
Microsoft.Extensions.AI.Integration.Tests (1)
ChatClientIntegrationTests.cs (1)
150UsageContent usage = chunks.SelectMany(c => c.Contents).OfType<UsageContent>().Single();
Microsoft.Extensions.AI.OpenAI (14)
MicrosoftExtensionsAIChatExtensions.cs (3)
134var usage = update.Contents.FirstOrDefault(c => c is UsageContent) is UsageContent usageContent ? 141var toolCallUpdates = update.Contents.OfType<FunctionCallContent>().Select((fcc, index) => 149new(OpenAIChatClient.ToOpenAIChatContent(update.Contents)),
OpenAIAssistantsChatClient.cs (5)
188ruUpdate.Contents.Add(new UsageContent(new() 203ruUpdate.Contents.Add(fcc); 239if (textUpdate.Contents.Count == 0) 242textUpdate.Contents.Add(new TextContent(string.Empty)); 245(((TextContent)textUpdate.Contents[0]).Annotations ??= []).Add(new CitationAnnotation
OpenAIChatClient.cs (5)
335ConvertContentParts(update.ContentUpdate, responseUpdate.Contents); 340responseUpdate.Contents.Add(new DataContent(audioUpdate.AudioBytesUpdate.ToMemory(), GetOutputAudioMimeType(options)) 375responseUpdate.Contents.Add(new UsageContent(FromOpenAIUsage(tokenUsage)) 407responseUpdate.Contents.Add(callContent); 415responseUpdate.Contents.Add(new ErrorContent(refusal.ToString()) { ErrorCode = "Refusal" });
OpenAIResponsesChatClient.cs (1)
282AddMcpToolCallContent(mtci, mcpUpdate.Contents);
Microsoft.Extensions.AI.OpenAI.Tests (11)
OpenAIChatClientTests.cs (4)
252Assert.Equal(i == 10 ? 0 : 1, updates[i].Contents.Count); 256UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 1312FunctionCallContent fcc = Assert.IsType<FunctionCallContent>(Assert.Single(updates[updates.Count - 1].Contents)); 1317UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single();
OpenAIResponseClientTests.cs (7)
324Assert.Single(updates[i].Contents); 327var reasoning = Assert.IsType<TextReasoningContent>(updates[i].Contents.Single()); 334Assert.Single(updates[i].Contents); 339Assert.Empty(updates[i].Contents); 345UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 451Assert.Equal((i >= 4 && i <= 12) || i == 16 ? 1 : 0, updates[i].Contents.Count); 460UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single();
Microsoft.Extensions.AI.Tests (14)
ChatCompletion\DistributedCachingChatClientTest.cs (8)
345Assert.Collection(update.Contents, 355c => Assert.IsType<FunctionCallContent>(Assert.Single(c.Contents)), 424var content = Assert.IsType<TextContent>(Assert.Single(item.Contents)); 844Assert.Equal(expectedItem.Contents.Count, actualItem.Contents.Count); 846for (var itemIndex = 0; itemIndex < expectedItem.Contents.Count; itemIndex++) 848var expectedItemItem = expectedItem.Contents[itemIndex]; 849var actualItemItem = actualItem.Contents[itemIndex];
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (6)
664var functionCall = update.Contents.OfType<FunctionCallContent>().First(); 743Assert.Equal("Text 1", update.Contents.OfType<TextContent>().First().Text); 749Assert.Equal("Text 2", update.Contents.OfType<TextContent>().First().Text); 755var approvalRequest1 = update.Contents.OfType<FunctionApprovalRequestContent>().First(); 763var approvalRequest2 = update.Contents.OfType<FunctionApprovalRequestContent>().First(); 771var approvalRequest3 = update.Contents.OfType<FunctionApprovalRequestContent>().First();