67 writes to Contents
Microsoft.Extensions.AI (3)
ChatCompletion\FunctionInvokingChatClient.cs (2)
564updateToYield.Contents = updatedContents; 637Contents = message.Contents,
ChatCompletion\ImageGeneratingChatClient.cs (1)
114modifiedUpdate.Contents = newContents;
Microsoft.Extensions.AI.Abstractions (2)
ChatCompletion\ChatResponse.cs (1)
151Contents = message.Contents,
ChatCompletion\ChatResponseUpdate.cs (1)
73Contents = Contents,
Microsoft.Extensions.AI.Abstractions.Tests (43)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (37)
36new() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] }, 37new() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] }, 578updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] }); 608new() { Contents = [new TextReasoningContent("D")] }, 609new() { Contents = [new TextReasoningContent("E")] }, 610new() { Contents = [new TextReasoningContent("F")] }, 613new() { Contents = [new TextReasoningContent("I")] }, 614new() { Contents = [new TextReasoningContent("J")] }, 616new() { Contents = [new TextReasoningContent("L")] }, 619new() { Contents = [new TextReasoningContent("O")] }, 620new() { Contents = [new TextReasoningContent("P")] }, 643new() { Contents = [new TextReasoningContent("A") { ProtectedData = "1" }] }, 644new() { Contents = [new TextReasoningContent("B") { ProtectedData = "2" }] }, 645new() { Contents = [new TextReasoningContent("C")] }, 646new() { Contents = [new TextReasoningContent("D")] }, 647new() { Contents = [new TextReasoningContent("E") { ProtectedData = "3" }] }, 648new() { Contents = [new TextReasoningContent("F") { ProtectedData = "4" }] }, 649new() { Contents = [new TextReasoningContent("G")] }, 650new() { Contents = [new TextReasoningContent("H")] }, 683new() { Contents = [new TextContent("D") { Annotations = [new()] }] }, 684new() { Contents = [new TextContent("E") { Annotations = [new()] }] }, 685new() { Contents = [new TextContent("F") { Annotations = [new()] }] }, 686new() { Contents = [new TextContent("G") { Annotations = [] }] }, 687new() { Contents = [new TextContent("H") { Annotations = [] }] }, 688new() { Contents = [new TextContent("I") { Annotations = [new()] }] }, 689new() { Contents = [new TextContent("J") { Annotations = [new()] }] }, 691new() { Contents = [new TextContent("L") { Annotations = [new()] }] }, 694new() { Contents = [new TextContent("O") { Annotations = [new()] }] }, 695new() { Contents = [new TextContent("P") { Annotations = [new()] }] }, 722new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] }, 844new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image1] }] }, 847new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image2] }] }, 850new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image3] }] }, 853new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image4] }] }, 898new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image1] }] }, 901new() { Contents = [new ImageGenerationToolResultContent { ImageId = "", Outputs = [image2] }] }, 904new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image3] }] },
ChatCompletion\ChatResponseUpdateTests.cs (6)
49update.Contents = newList; 51update.Contents = null; 90Contents = 119Contents = 184Contents = originalContents, 311Contents = sharedContents
Microsoft.Extensions.AI.OpenAI.Tests (1)
OpenAIConversionTests.cs (1)
1127Contents =
Microsoft.Extensions.AI.Tests (18)
ChatCompletion\DistributedCachingChatClientTest.cs (8)
253Contents = 266Contents = [new FunctionCallContent("someCallId", "someFn", new Dictionary<string, object?> { ["arg1"] = "value1" })], 270Contents = [new UsageContent(new() { InputTokenCount = 123, OutputTokenCount = 456, TotalTokenCount = 99999 })], 316new() { Role = ChatRole.Assistant, Contents = [new FunctionCallContent("callId1", "separator")] }, 369new() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] }, 370new() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] }, 374Contents = 385Contents =
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
761new() { Contents = [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["text"] = "Input 1" })] }, 762new() { Contents = [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["text"] = "Input 2" })] } 767updates = [new() { Contents = [new TextContent("OK bye")] }];
ChatCompletion\OpenTelemetryChatClientTests.cs (7)
82Contents = [new UsageContent(new() 372yield return new() { Contents = [new TextReasoningContent("This is reasoning")] }; 373yield return new() { Contents = [new FunctionCallContent("call-123", "GetWeather", new Dictionary<string, object?> { ["location"] = "Seattle" })] }; 374yield return new() { Contents = [new FunctionResultContent("call-123", "72°F and sunny")] }; 375yield return new() { Contents = [new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png")] }; 376yield return new() { Contents = [new UriContent(new Uri("https://example.com/image.jpg"), "image/jpeg")] }; 377yield return new() { Contents = [new HostedFileContent("file-abc123")] };
123 references to Contents
Aspire.Dashboard (3)
Model\Assistant\AIHelpers.cs (3)
486foreach (var item in update.Contents.OfType<TextContent>()) 505var contentsList = filter is null ? update.Contents : update.Contents.Where(filter).ToList();
Microsoft.Extensions.AI (5)
ChatCompletion\FunctionInvokingChatClient.cs (3)
502_ = CopyFunctionCalls(update.Contents, ref functionCallContents); 506IList<AIContent> contents = update.Contents; 562if (TryReplaceFunctionCallsWithApprovalRequests(updateToYield.Contents, out var updatedContents))
ChatCompletion\ImageGeneratingChatClient.cs (2)
108var newContents = requestState.ReplaceImageGenerationFunctionResults(update.Contents); 110if (!ReferenceEquals(newContents, update.Contents))
Microsoft.Extensions.AI.Abstractions (6)
ChatCompletion\ChatResponse.cs (1)
136extra.Contents.Add(new UsageContent(usage));
ChatCompletion\ChatResponseExtensions.cs (3)
87var contentsList = filter is null ? update.Contents : update.Contents.Where(filter).ToList(); 538foreach (var content in update.Contents)
ChatCompletion\ChatResponseUpdate.cs (2)
73Contents = Contents, 96/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
Microsoft.Extensions.AI.Abstractions.Tests (31)
ChatCompletion\ChatResponseUpdateTests.cs (31)
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); 213Assert.Same(original.Contents, clone.Contents); 242Assert.Empty(clone.Contents); // Contents property initializes to empty list 258Assert.Empty(clone.Contents); 323Assert.Same(original.Contents, clone.Contents); 326Assert.Equal(2, original.Contents.Count); 327Assert.Equal(2, clone.Contents.Count);
Microsoft.Extensions.AI.Integration.Tests (1)
ChatClientIntegrationTests.cs (1)
159UsageContent usage = chunks.SelectMany(c => c.Contents).OfType<UsageContent>().Single();
Microsoft.Extensions.AI.OpenAI (15)
MicrosoftExtensionsAIChatExtensions.cs (3)
143var usage = update.Contents.FirstOrDefault(c => c is UsageContent) is UsageContent usageContent ? 150var toolCallUpdates = update.Contents.OfType<FunctionCallContent>().Select((fcc, index) => 160new(OpenAIChatClient.ToOpenAIChatContent(update.Contents)),
OpenAIAssistantsChatClient.cs (5)
178ruUpdate.Contents.Add(new UsageContent(new() 193ruUpdate.Contents.Add(fcc); 281if (textUpdate.Contents.Count == 0) 284textUpdate.Contents.Add(new TextContent(string.Empty)); 287(((TextContent)textUpdate.Contents[0]).Annotations ??= []).Add(new CitationAnnotation
OpenAIChatClient.cs (5)
363ConvertContentParts(update.ContentUpdate, responseUpdate.Contents); 368responseUpdate.Contents.Add(new DataContent(audioUpdate.AudioBytesUpdate.ToMemory(), GetOutputAudioMimeType(options)) 403responseUpdate.Contents.Add(new UsageContent(FromOpenAIUsage(tokenUsage)) 435responseUpdate.Contents.Add(callContent); 443responseUpdate.Contents.Add(new ErrorContent(refusal.ToString()) { ErrorCode = "Refusal" });
OpenAIResponsesChatClient.cs (2)
417AddMcpToolCallContent(mtci, mcpUpdate.Contents); 434AddCodeInterpreterContents(cicri, codeUpdate.Contents);
Microsoft.Extensions.AI.OpenAI.Tests (46)
OpenAIChatClientTests.cs (4)
253Assert.Equal(i == 10 ? 0 : 1, updates[i].Contents.Count); 257UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 1345FunctionCallContent fcc = Assert.IsType<FunctionCallContent>(Assert.Single(updates[updates.Count - 1].Contents)); 1350UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single();
OpenAIResponseClientTests.cs (42)
326Assert.Single(updates[i].Contents); 329var reasoning = Assert.IsType<TextReasoningContent>(updates[i].Contents.Single()); 336Assert.Single(updates[i].Contents); 341Assert.Empty(updates[i].Contents); 347UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 459Assert.Single(u.Contents); 461var reasoning = Assert.IsType<TextReasoningContent>(u.Contents.Single()); 466var allReasoningText = string.Concat(reasoningUpdates.Select(u => u.Contents.OfType<TextReasoningContent>().First().Text)); 474UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 580Assert.Equal((i >= 4 && i <= 12) || i == 16 ? 1 : 0, updates[i].Contents.Count); 589UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 811Assert.Equal(i >= 3 ? 1 : 0, updates[i].Contents.Count); 816AIContent content = Assert.Single(updates[3].Contents); 819UsageContent usage = Assert.IsType<UsageContent>(Assert.Single(updates[4].Contents)); 2461Assert.Equal((i >= 5 && i <= 13) || i == 17 ? 1 : 0, updates[i].Contents.Count); 2545Assert.Single(updates[i].Contents); 2555Assert.Empty(updates[i].Contents); 2561Assert.Single(updates[i].Contents); 4852var refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal")); 4855var errorContent = refusalUpdate.Contents.OfType<ErrorContent>().First(); 4910var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 4913var errorContent = errorUpdate.Contents.OfType<ErrorContent>().First(); 4953var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 4956var errorContent = errorUpdate.Contents.OfType<ErrorContent>().First(); 4996var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 4999var errorContent = errorUpdate.Contents.OfType<ErrorContent>().First(); 5039var annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0)); 5041Assert.NotEmpty(annotatedUpdate.Contents.First().Annotations!); 5301u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolCallContent)); 5303var toolCall = toolCallUpdate.Contents.OfType<ImageGenerationToolCallContent>().First(); 5308u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolResultContent result && 5314u.Contents != null && u.Contents.Any(c => c is UsageContent)); 5316var usage = completionUpdate.Contents.OfType<UsageContent>().First(); 5414u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolResultContent result && 5423u.Contents.OfType<ImageGenerationToolResultContent>().Any(result => 5460u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolCallContent)); 5462var toolCall = toolCallUpdate.Contents.OfType<ImageGenerationToolCallContent>().First();
Microsoft.Extensions.AI.Tests (16)
ChatCompletion\DistributedCachingChatClientTest.cs (8)
346Assert.Collection(update.Contents, 356c => Assert.IsType<FunctionCallContent>(Assert.Single(c.Contents)), 425var content = Assert.IsType<TextContent>(Assert.Single(item.Contents)); 842Assert.Equal(expectedItem.Contents.Count, actualItem.Contents.Count); 844for (var itemIndex = 0; itemIndex < expectedItem.Contents.Count; itemIndex++) 846var expectedItemItem = expectedItem.Contents[itemIndex]; 847var actualItemItem = actualItem.Contents[itemIndex];
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (6)
727var functionCall = update.Contents.OfType<FunctionCallContent>().First(); 806Assert.Equal("Text 1", update.Contents.OfType<TextContent>().First().Text); 812Assert.Equal("Text 2", update.Contents.OfType<TextContent>().First().Text); 818var approvalRequest1 = update.Contents.OfType<FunctionApprovalRequestContent>().First(); 826var approvalRequest2 = update.Contents.OfType<FunctionApprovalRequestContent>().First(); 834var approvalRequest3 = update.Contents.OfType<FunctionApprovalRequestContent>().First();
ChatCompletion\ImageGeneratingChatClientTests.cs (2)
381Assert.Single(update.Contents); 383var imageToolCallContent = Assert.IsType<ImageGenerationToolCallContent>(update.Contents[0]);