73 writes to Contents
Microsoft.Extensions.AI (3)
ChatCompletion\FunctionInvokingChatClient.cs (2)
583updateToYield.Contents = updatedContents; 656Contents = message.Contents,
ChatCompletion\ImageGeneratingChatClient.cs (1)
115modifiedUpdate.Contents = newContents;
Microsoft.Extensions.AI.Abstractions (2)
ChatCompletion\ChatResponse.cs (1)
152Contents = message.Contents,
ChatCompletion\ChatResponseUpdate.cs (1)
74Contents = Contents,
Microsoft.Extensions.AI.Abstractions.Tests (43)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (37)
35new() { Contents = [new UsageContent(new() { InputTokenCount = 1, OutputTokenCount = 2 })] }, 36new() { Contents = [new UsageContent(new() { InputTokenCount = 4, OutputTokenCount = 5 })] }, 662updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] }); 692new() { Contents = [new TextReasoningContent("D")] }, 693new() { Contents = [new TextReasoningContent("E")] }, 694new() { Contents = [new TextReasoningContent("F")] }, 697new() { Contents = [new TextReasoningContent("I")] }, 698new() { Contents = [new TextReasoningContent("J")] }, 700new() { Contents = [new TextReasoningContent("L")] }, 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")] }, 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()] }] }, 775new() { Contents = [new TextContent("L") { Annotations = [new()] }] }, 778new() { Contents = [new TextContent("O") { Annotations = [new()] }] }, 779new() { Contents = [new TextContent("P") { Annotations = [new()] }] }, 806new() { Contents = [new UsageContent(new() { TotalTokenCount = 42 })] }, 934new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image1] }] }, 937new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image2] }] }, 940new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img1", Outputs = [image3] }] }, 943new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img2", Outputs = [image4] }] }, 988new() { Contents = [new ImageGenerationToolResultContent { ImageId = null, Outputs = [image1] }] }, 991new() { Contents = [new ImageGenerationToolResultContent { ImageId = "", Outputs = [image2] }] }, 994new() { 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)
1213Contents =
Microsoft.Extensions.AI.Tests (24)
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)
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\OpenTelemetryChatClientTests.cs (13)
83Contents = [new UsageContent(new() 375yield return new() { Contents = [new TextReasoningContent("This is reasoning")] }; 376yield return new() { Contents = [new FunctionCallContent("call-123", "GetWeather", new Dictionary<string, object?> { ["location"] = "Seattle" })] }; 377yield return new() { Contents = [new FunctionResultContent("call-123", "72°F and sunny")] }; 378yield return new() { Contents = [new DataContent(Convert.FromBase64String("aGVsbG8gd29ybGQ="), "image/png")] }; 379yield return new() { Contents = [new UriContent(new Uri("https://example.com/image.jpg"), "image/jpeg")] }; 380yield return new() { Contents = [new HostedFileContent("file-abc123")] }; 629yield return new() { Contents = [new CodeInterpreterToolCallContent { CallId = "ci-call-1", Inputs = [new TextContent("print('hello')")] }] }; 630yield return new() { Contents = [new CodeInterpreterToolResultContent { CallId = "ci-call-1", Outputs = [new TextContent("hello")] }] }; 631yield return new() { Contents = [new ImageGenerationToolCallContent { ImageId = "img-123" }] }; 632yield return new() { Contents = [new ImageGenerationToolResultContent { ImageId = "img-123", Outputs = [new UriContent(new Uri("https://example.com/image.png"), "image/png")] }] }; 633yield return new() { Contents = [new McpServerToolCallContent("mcp-call-1", "myTool", "myServer") { Arguments = new Dictionary<string, object?> { ["param1"] = "value1" } }] }; 634yield return new() { Contents = [new McpServerToolResultContent("mcp-call-1") { Output = [new TextContent("Tool result")] }] };
130 references to Contents
Aspire.Dashboard (3)
Model\Assistant\AIHelpers.cs (3)
334foreach (var item in update.Contents.OfType<TextContent>()) 353var contentsList = filter is null ? update.Contents : update.Contents.Where(filter).ToList();
Microsoft.Extensions.AI (5)
ChatCompletion\FunctionInvokingChatClient.cs (3)
521_ = CopyFunctionCalls(update.Contents, ref functionCallContents); 525IList<AIContent> contents = update.Contents; 581if (TryReplaceFunctionCallsWithApprovalRequests(updateToYield.Contents, out var updatedContents))
ChatCompletion\ImageGeneratingChatClient.cs (2)
109var newContents = requestState.ReplaceImageGenerationFunctionResults(update.Contents); 111if (!ReferenceEquals(newContents, update.Contents))
Microsoft.Extensions.AI.Abstractions (6)
ChatCompletion\ChatResponse.cs (1)
137extra.Contents.Add(new UsageContent(usage));
ChatCompletion\ChatResponseExtensions.cs (3)
87var contentsList = filter is null ? update.Contents : update.Contents.Where(filter).ToList(); 567foreach (var content in update.Contents)
ChatCompletion\ChatResponseUpdate.cs (2)
74Contents = Contents, 97/// 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)
148var usage = update.Contents.FirstOrDefault(c => c is UsageContent) is UsageContent usageContent ? 155var toolCallUpdates = update.Contents.OfType<FunctionCallContent>().Select((fcc, index) => 165new(OpenAIChatClient.ToOpenAIChatContent(update.Contents)),
OpenAIAssistantsChatClient.cs (5)
181ruUpdate.Contents.Add(new UsageContent(new() 196ruUpdate.Contents.Add(fcc); 284if (textUpdate.Contents.Count == 0) 287textUpdate.Contents.Add(new TextContent(string.Empty)); 290(((TextContent)textUpdate.Contents[0]).Annotations ??= []).Add(new CitationAnnotation
OpenAIChatClient.cs (6)
378ConvertContentParts(update.ContentUpdate, responseUpdate.Contents); 385responseUpdate.Contents.Add(new TextReasoningContent(reasoningText)); 390responseUpdate.Contents.Add(new DataContent(audioUpdate.AudioBytesUpdate.ToMemory(), GetOutputAudioMimeType(options)) 425responseUpdate.Contents.Add(new UsageContent(FromOpenAIUsage(tokenUsage)) 457responseUpdate.Contents.Add(callContent); 465responseUpdate.Contents.Add(new ErrorContent(refusal.ToString()) { ErrorCode = "Refusal" });
OpenAIResponsesChatClient.cs (1)
449AddMcpToolCallContent(mtci, mcpUpdate.Contents);
Microsoft.Extensions.AI.OpenAI.Tests (53)
OpenAIChatClientTests.cs (5)
255Assert.Equal(i == 10 ? 0 : 1, updates[i].Contents.Count); 259UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 1347FunctionCallContent fcc = Assert.IsType<FunctionCallContent>(Assert.Single(updates[updates.Count - 1].Contents)); 1352UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 2008string reasoningText = string.Concat(updates.SelectMany(u => u.Contents).OfType<TextReasoningContent>().Select(r => r.Text));
OpenAIResponseClientTests.cs (48)
328Assert.Single(updates[i].Contents); 331var reasoning = Assert.IsType<TextReasoningContent>(updates[i].Contents.Single()); 338Assert.Single(updates[i].Contents); 343Assert.Empty(updates[i].Contents); 349UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 461Assert.Single(u.Contents); 463var reasoning = Assert.IsType<TextReasoningContent>(u.Contents.Single()); 468var allReasoningText = string.Concat(reasoningUpdates.Select(u => u.Contents.OfType<TextReasoningContent>().First().Text)); 476UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 570var reasoningContents = updates.SelectMany(u => u.Contents).OfType<TextReasoningContent>().ToList(); 682Assert.Equal((i >= 4 && i <= 12) || i == 16 ? 1 : 0, updates[i].Contents.Count); 691UsageContent usage = updates.SelectMany(u => u.Contents).OfType<UsageContent>().Single(); 920Assert.Equal(i >= 3 ? 1 : 0, updates[i].Contents.Count); 925AIContent content = Assert.Single(updates[3].Contents); 930UsageContent usage = Assert.IsType<UsageContent>(Assert.Single(updates[4].Contents)); 2654Assert.Equal((i >= 5 && i <= 13) || i == 17 ? 1 : 0, updates[i].Contents.Count); 2738Assert.Single(updates[i].Contents); 2748Assert.Empty(updates[i].Contents); 2754Assert.Single(updates[i].Contents); 3208u.Contents != null && u.Contents.Any(c => c is CodeInterpreterToolCallContent)).ToList(); 3217var content = update.Contents.OfType<CodeInterpreterToolCallContent>().First(); 3236u.Contents != null && u.Contents.Any(c => c is CodeInterpreterToolResultContent)).ToList(); 5165var refusalUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent ec && ec.ErrorCode == "Refusal")); 5168var errorContent = refusalUpdate.Contents.OfType<ErrorContent>().First(); 5223var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 5226var errorContent = errorUpdate.Contents.OfType<ErrorContent>().First(); 5266var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 5269var errorContent = errorUpdate.Contents.OfType<ErrorContent>().First(); 5309var errorUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c is ErrorContent)); 5312var errorContent = errorUpdate.Contents.OfType<ErrorContent>().First(); 5352var annotatedUpdate = updates.FirstOrDefault(u => u.Contents.Any(c => c.Annotations?.Count > 0)); 5354Assert.NotEmpty(annotatedUpdate.Contents.First().Annotations!); 5740u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolCallContent)); 5742var toolCall = toolCallUpdate.Contents.OfType<ImageGenerationToolCallContent>().First(); 5747u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolResultContent result && 5753u.Contents != null && u.Contents.Any(c => c is UsageContent)); 5755var usage = completionUpdate.Contents.OfType<UsageContent>().First(); 5853u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolResultContent result && 5862u.Contents.OfType<ImageGenerationToolResultContent>().Any(result => 5899u.Contents != null && u.Contents.Any(c => c is ImageGenerationToolCallContent)); 5901var 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)
996var functionCall = update.Contents.OfType<FunctionCallContent>().First(); 1075Assert.Equal("Text 1", update.Contents.OfType<TextContent>().First().Text); 1081Assert.Equal("Text 2", update.Contents.OfType<TextContent>().First().Text); 1087var approvalRequest1 = update.Contents.OfType<FunctionApprovalRequestContent>().First(); 1095var approvalRequest2 = update.Contents.OfType<FunctionApprovalRequestContent>().First(); 1103var approvalRequest3 = update.Contents.OfType<FunctionApprovalRequestContent>().First();
ChatCompletion\ImageGeneratingChatClientTests.cs (2)
381Assert.Single(update.Contents); 383var imageToolCallContent = Assert.IsType<ImageGenerationToolCallContent>(update.Contents[0]);