17 types derived from AIContent
Microsoft.AspNetCore.Components.AI (1)
Blocks\RichText\RichTextContent.cs (1)
17public class RichTextContent : AIContent
Microsoft.Extensions.AI.Abstractions (12)
Contents\DataContent.cs (1)
41public class DataContent : AIContent
Contents\ErrorContent.cs (1)
15public class ErrorContent : AIContent
Contents\HostedFileContent.cs (1)
21public sealed class HostedFileContent : AIContent
Contents\HostedVectorStoreContent.cs (1)
19public sealed class HostedVectorStoreContent : AIContent
Contents\InputRequestContent.cs (1)
14public class InputRequestContent : AIContent
Contents\InputResponseContent.cs (1)
14public class InputResponseContent : AIContent
Contents\TextContent.cs (1)
13public sealed class TextContent : AIContent
Contents\TextReasoningContent.cs (1)
18public sealed class TextReasoningContent : AIContent
Contents\ToolCallContent.cs (1)
18public class ToolCallContent : AIContent
Contents\ToolResultContent.cs (1)
18public class ToolResultContent : AIContent
Contents\UriContent.cs (1)
20public class UriContent : AIContent
Contents\UsageContent.cs (1)
14public class UsageContent : AIContent
Microsoft.Extensions.AI.Abstractions.Tests (1)
Utilities\AIJsonUtilitiesTests.cs (1)
1920private class DerivedAIContent : AIContent
Microsoft.Extensions.AI.Tests (3)
ChatCompletion\DistributedCachingChatClientTest.cs (2)
885public class CustomAIContent1(string text, DateTime date) : AIContent 891public class CustomAIContent2(string text, int number) : AIContent
ChatCompletion\OpenTelemetryChatClientTests.cs (1)
998private sealed class NonSerializableAIContent : AIContent;
12 instantiations of AIContent
Microsoft.Extensions.AI.Abstractions.Tests (3)
Contents\AIContentTests.cs (3)
15AIContent c = new(); 23AIContent c = new(); 39AIContent original = new()
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (1)
ScenarioRunResultTests.cs (1)
237new AIContent(),
Microsoft.Extensions.AI.OpenAI (4)
OpenAIResponsesChatClient.cs (4)
313message.Contents.Add(new() { RawRepresentation = outputItem }); 588AIContent annotatedContent = new(); // do not include RawRepresentation to avoid duplication with already yielded deltas 635yield return CreateUpdate(new AIContent { RawRepresentation = outputItemDoneUpdate.Item }); 1741content = new();
Microsoft.Extensions.AI.OpenAI.Tests (4)
OpenAIConversionTests.cs (4)
851new AIContent { RawRepresentation = ResponseItem.CreateWebSearchCallItem() }, 852new AIContent { RawRepresentation = ResponseItem.CreateReferenceItem("123") }, 859new AIContent { RawRepresentation = ResponseItem.CreateReasoningItem("text") }, 863new AIContent { RawRepresentation = ResponseItem.CreateSystemMessageItem("test") },
504 references to AIContent
Microsoft.AspNetCore.Components.AI (24)
Blocks\FunctionApprovalBlock.cs (2)
21private readonly TaskCompletionSource<AIContent> _resultSource = 102public Task<AIContent> GetResultAsync(CancellationToken cancellationToken = default)
Blocks\IInteractiveBlock.cs (1)
18Task<AIContent> GetResultAsync(CancellationToken cancellationToken = default);
Blocks\UIActionBlock.cs (2)
26private readonly TaskCompletionSource<AIContent> _resultSource = 75public Task<AIContent> GetResultAsync(CancellationToken cancellationToken = default)
Engine\AgentContext.cs (2)
313IReadOnlyList<AIContent> results) 316foreach (var result in results)
Pipeline\BlockMappingContext.cs (7)
42public void MarkHandled(AIContent content) 80public ContentBlock? CreateInnerBlock(AIContent content) 118private readonly IList<AIContent> _contents; 121internal UnhandledContentsEnumerable(IList<AIContent> contents, bool[] handled) 139private readonly IList<AIContent> _contents; 143internal UnhandledContentsEnumerator(IList<AIContent> contents, bool[] handled) 153public AIContent Current => _contents[_index];
Pipeline\FunctionApprovalHandler.cs (1)
18foreach (var content in context.UnhandledContents)
Pipeline\FunctionInvocationHandler.cs (2)
22foreach (var content in context.UnhandledContents) 36foreach (var content in context.UnhandledContents)
Pipeline\RichTextContentHandler.cs (2)
14foreach (var content in context.UnhandledContents) 36foreach (var content in context.UnhandledContents)
Pipeline\StateMapperContext.cs (3)
30public IEnumerable<AIContent> UnhandledContents 49public void MarkHandled(AIContent content) 105var filtered = new List<AIContent>();
Pipeline\TextBlockHandler.cs (1)
16foreach (var content in context.UnhandledContents)
Pipeline\UIActionHandler.cs (1)
24foreach (var content in context.UnhandledContents)
Microsoft.Extensions.AI (37)
ChatCompletion\FunctionInvokingChatClient.cs (14)
555IList<AIContent> contents = update.Contents; 903IList<AIContent> content, [NotNullWhen(true)] ref List<FunctionCallContent>? functionCalls) 931IList<AIContent> contents = messages[i].Contents; 950IList<AIContent> contents = messages[i].Contents; 980IList<AIContent> contents = updates[i].Contents; 1270var contents = new List<AIContent>(results.Length); 1383List<AIContent>? rejectedFunctionCallResults = GenerateRejectedFunctionResults(notInvokedResponses.rejections); 1444List<AIContent>? keptContents = null; 1449var content = message.Contents[j]; 1548/// <returns>The <see cref="AIContent"/> for the rejected function calls.</returns> 1549private List<AIContent>? GenerateRejectedFunctionResults(List<ApprovalResultWithRequestMessage>? rejections) => 1567return (AIContent)new FunctionResultContent(m.ResponseFunctionCallContent.CallId, result); 1698IList<AIContent> content, 1700out List<AIContent>? updatedContent)
ChatCompletion\ImageGeneratingChatClient.cs (14)
147private readonly Dictionary<string, List<AIContent>> _imageContentByCallId = []; 148private readonly Dictionary<string, AIContent> _imageContentById = new(StringComparer.OrdinalIgnoreCase); 170List<AIContent>? newContents = null; 173var content = message.Contents[contentIndex]; 199foreach (var output in toolResultContent.Outputs ?? []) 318public IList<AIContent> ReplaceImageGenerationFunctionResults(IList<AIContent> contents) 320List<AIContent>? newContents = null; 325var content = contents[i]; 391List<AIContent> imageContents = _imageContentByCallId[callId] = []; 392foreach (var content in response.Contents) 454List<AIContent> imageContents = _imageContentByCallId[callId] = []; 455foreach (var content in response.Contents) 487if (_imageContentById.TryGetValue(imageId, out var imageContent))
ChatCompletion\OpenTelemetryImageGenerator.cs (1)
176List<AIContent> content = [];
ChatReduction\SummarizingChatReducer.cs (3)
202/// <summary>Returns whether the given <see cref="AIContent"/> relates to tool calling capabilities.</summary> 204/// This method returns <see langword="true"/> for content types whose meaning depends on other related <see cref="AIContent"/> 208private static bool IsToolRelatedContent(AIContent content) => content
Common\OtelMessageSerializer.cs (3)
63foreach (AIContent content in message.Contents) 283private static string? ExtractCodeFromInputs(IList<AIContent>? inputs) 287foreach (var input in inputs)
Realtime\FunctionInvokingRealtimeClientSession.cs (1)
220foreach (var content in message.Item.Contents)
Realtime\OpenTelemetryRealtimeClientSession.cs (1)
525foreach (var content in item.Contents)
Microsoft.Extensions.AI.Abstractions (104)
ChatCompletion\ChatMessage.cs (5)
17private IList<AIContent>? _contents; 38public ChatMessage(ChatRole role, IList<AIContent>? contents) 84public IList<AIContent> Contents 108/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary> 110private AIContent? ContentForDebuggerDisplay
ChatCompletion\ChatResponseExtensions.cs (22)
56/// contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 75/// <param name="filter">A predicate to filter which <see cref="AIContent"/> gets included in the message.</param> 82public static void AddMessages(this IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool>? filter = null) 110/// contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 133/// message boundaries, as well as coalescing contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 161/// message boundaries, as well as coalescing contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 188/// Coalesces image result content elements in the provided list of <see cref="AIContent"/> items. 192private static void CoalesceImageResultContent(IList<AIContent> contents) 229/// Coalesces web search tool call content elements in the provided list of <see cref="AIContent"/> items. 233private static void CoalesceWebSearchToolCallContent(IList<AIContent> contents) 281/// <summary>Coalesces sequential <see cref="AIContent"/> content elements.</summary> 282internal static void CoalesceContent(IList<AIContent> contents) 366List<AIContent>? inputs = null; 403List<AIContent>? output = null; 422static string MergeText(IList<AIContent> contents, int start, int end) 436IList<AIContent> contents, 439Func<IList<AIContent>, int, int, TContent> merge) 440where TContent : AIContent 479static bool TryAsCoalescable(AIContent content, [NotNullWhen(true)] out TContent? coalescable) 500if (contents is List<AIContent> contentsList) 531CoalesceContent((List<AIContent>)response.Messages[i].Contents); 620foreach (var content in update.Contents)
ChatCompletion\ChatResponseUpdate.cs (5)
36private IList<AIContent>? _contents; 55public ChatResponseUpdate(ChatRole? role, IList<AIContent>? contents) 103public IList<AIContent> Contents 175/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary> 177private AIContent? ContentForDebuggerDisplay
Contents\AIAnnotation.cs (1)
23/// <summary>Gets or sets any target regions for the annotation, pointing to where in the associated <see cref="AIContent"/> this annotation applies.</summary>
Contents\AIContent.cs (2)
38/// Initializes a new instance of the <see cref="AIContent"/> class. 51/// If an <see cref="AIContent"/> is created to represent some underlying object from another object
Contents\AIContentExtensions.cs (3)
15/// <summary>Internal extensions for working with <see cref="AIContent"/>.</summary> 19public static string ConcatText(this IEnumerable<AIContent> contents) 21if (contents is IList<AIContent> list)
Contents\AnnotatedRegion.cs (1)
8/// <summary>Describes the portion of an associated <see cref="AIContent"/> to which an annotation applies.</summary>
Contents\CodeInterpreterToolCallContent.cs (2)
31/// <see cref="DataContent"/> for binary data, or other <see cref="AIContent"/> types as supported 35public IList<AIContent>? Inputs { get; set; }
Contents\CodeInterpreterToolResultContent.cs (2)
28/// or other <see cref="AIContent"/> types as supported by the service. 30public IList<AIContent>? Outputs { get; set; }
Contents\ImageGenerationToolResultContent.cs (1)
33public IList<AIContent>? Outputs { get; set; }
Contents\McpServerToolResultContent.cs (1)
33public IList<AIContent>? Outputs { get; set; }
Contents\TextSpanAnnotatedRegion.cs (3)
9/// <summary>Describes a location in the associated <see cref="AIContent"/> based on starting and ending character indices.</summary> 22/// Gets or sets the start character index (inclusive) of the annotated span in the <see cref="AIContent"/>. 28/// Gets or sets the end character index (exclusive) of the annotated span in the <see cref="AIContent"/>.
Contents\WebSearchToolResultContent.cs (3)
13/// The results contain a list of <see cref="AIContent"/> items describing the web pages 32/// If a title is available for a result, it may be stored in the item's <see cref="AIContent.AdditionalProperties"/> 35public IList<AIContent>? Outputs { get; set; }
Functions\AIFunctionFactory.cs (14)
110/// However, return values whose declared type is <see cref="AIContent"/>, a derived type of <see cref="AIContent"/>, or 190/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. However, return values whose declared type is <see cref="AIContent"/>, a 191/// derived type of <see cref="AIContent"/>, or any type assignable from <see cref="IEnumerable{AIContent}"/> are not serialized; 281/// However, return values whose declared type is <see cref="AIContent"/>, a derived type of <see cref="AIContent"/>, or 369/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. However, return values whose declared type is <see cref="AIContent"/>, a 370/// derived type of <see cref="AIContent"/>, or any type assignable from <see cref="IEnumerable{AIContent}"/> are returned 473/// However, return values whose declared type is <see cref="AIContent"/>, a derived type of <see cref="AIContent"/>, or any type 1223typeof(AIContent).IsAssignableFrom(type) || 1224typeof(IEnumerable<AIContent>).IsAssignableFrom(type); 1253if (typeof(IEnumerable<AIContent>).IsAssignableFrom(type)) 1255return typeof(IEnumerable<AIContent>);
Image\ImageGenerationRequest.cs (2)
29public ImageGenerationRequest(string prompt, IEnumerable<AIContent>? originalImages) 45public IEnumerable<AIContent>? OriginalImages { get; set; }
Image\ImageGenerationResponse.cs (2)
23public ImageGenerationResponse(IList<AIContent>? contents) 45public IList<AIContent> Contents
Image\ImageGeneratorExtensions.cs (1)
120IEnumerable<AIContent> originalImages,
Realtime\RealtimeConversationItem.cs (2)
26public RealtimeConversationItem(IList<AIContent> contents, string? id = null, ChatRole? role = null) 54public IList<AIContent> Contents { get; set; }
SpeechToText\SpeechToTextResponse.cs (4)
18private IList<AIContent>? _contents; 28public SpeechToTextResponse(IList<AIContent> contents) 78IList<AIContent> contents = Contents; 101public IList<AIContent> Contents
SpeechToText\SpeechToTextResponseUpdate.cs (3)
35private IList<AIContent>? _contents; 45public SpeechToTextResponseUpdate(IList<AIContent> contents) 93public IList<AIContent> Contents
SpeechToText\SpeechToTextResponseUpdateExtensions.cs (3)
34ChatResponseExtensions.CoalesceContent((List<AIContent>)response.Contents); 60ChatResponseExtensions.CoalesceContent((List<AIContent>)response.Contents); 95foreach (var content in update.Contents)
TextToSpeech\TextToSpeechResponse.cs (3)
24public TextToSpeechResponse(IList<AIContent> contents) 51IList<AIContent> contents = Contents; 72public IList<AIContent> Contents
TextToSpeech\TextToSpeechResponseUpdate.cs (2)
42public TextToSpeechResponseUpdate(IList<AIContent> contents) 70public IList<AIContent> Contents
TextToSpeech\TextToSpeechResponseUpdateExtensions.cs (1)
79foreach (var content in update.Contents)
Tools\HostedCodeInterpreterTool.cs (2)
36/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the code interpreter tool.</summary> 42public IList<AIContent>? Inputs { get; set; }
Tools\HostedFileSearchTool.cs (2)
36/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the file search tool.</summary> 43public IList<AIContent>? Inputs { get; set; }
Utilities\AIJsonUtilities.cs (10)
25/// Adds a custom content type to the polymorphic configuration for <see cref="AIContent"/>. 34where TContent : AIContent 43/// Adds a custom content type to the polymorphic configuration for <see cref="AIContent"/>. 49/// <exception cref="ArgumentException"><paramref name="contentType"/> is a built-in content type or does not derive from <see cref="AIContent"/>.</exception> 57if (!typeof(AIContent).IsAssignableFrom(contentType)) 59Throw.ArgumentException(nameof(contentType), $"The content type must derive from {nameof(AIContent)}."); 190/// Walks the inheritance chain from <paramref name="contentType"/> up to and including <see cref="AIContent"/>, 195if (checkBuiltIn && (contentType.Assembly == typeof(AIContent).Assembly)) 197Throw.ArgumentException(nameof(contentType), $"Cannot register built-in {nameof(AIContent)} types."); 201baseType is not null && typeof(AIContent).IsAssignableFrom(baseType);
Utilities\AIJsonUtilities.Defaults.cs (2)
109[JsonSerializable(typeof(AIContent))] 110[JsonSerializable(typeof(IEnumerable<AIContent>))]
Microsoft.Extensions.AI.Abstractions.Tests (138)
AssertExtensions.cs (2)
33var expectedItem = expectedMessage.Contents[j]; 34var chatItem = chatMessage.Contents[j];
ChatCompletion\ChatMessageTests.cs (6)
72message = new(ChatRole.User, (IList<AIContent>?)null); 76message = new ChatMessage(ChatRole.User, Array.Empty<AIContent>()); 87List<AIContent> content = []; 170Assert.IsType<List<AIContent>>(new ChatMessage().Contents); 179List<AIContent> contents = []; 253IList<AIContent> items =
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (2)
966var firstOutput = Assert.Single(firstImageResult.Outputs); 972var secondOutput = Assert.Single(secondImageResult.Outputs);
ChatCompletion\ChatResponseUpdateTests.cs (3)
48IList<AIContent> newList = [new TextContent("text")]; 246var originalContents = new List<AIContent> { new TextContent("text1"), new TextContent("text2") }; 376var sharedContents = new List<AIContent> { new TextContent("initial") };
Contents\AIContentTests.cs (10)
15AIContent c = new(); 23AIContent c = new(); 39AIContent original = new() 48string json = JsonSerializer.Serialize(original, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent))); 51AIContent? deserialized = (AIContent?)JsonSerializer.Deserialize(json, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent))); 92foreach (AIContent content in message.Contents) 95var deserializedElement = JsonSerializer.Deserialize<AIContent>(serializedElement, options);
Contents\CodeInterpreterToolCallContentTests.cs (3)
30IList<AIContent> inputs = [new TextContent("print('hello')")]; 109AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\CodeInterpreterToolResultContentTests.cs (3)
30IList<AIContent> output = [new TextContent("Hello, World!")]; 111AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\DataContentTests.cs (2)
991AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ErrorContentTests.cs (2)
82AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\FunctionCallContentTests.cs (4)
419AssertSerializationRoundtrips<AIContent>(content); 422where T : AIContent 455AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\FunctionResultContentTests.cs (4)
102AssertSerializationRoundtrips<AIContent>(content); 105where T : AIContent 131AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\HostedFileContentTests.cs (2)
257AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\HostedVectorStoreContentTests.cs (2)
79AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ImageGenerationToolCallContentTests.cs (5)
53AIContent content = new ImageGenerationToolCallContent("img456"); 59var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 79AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ImageGenerationToolResultContentTests.cs (6)
31IList<AIContent> outputs = [new DataContent(new byte[] { 1, 2, 3 }, "image/png")]; 94AIContent content = new ImageGenerationToolResultContent("img789") 107var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 140AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\McpServerToolCallContentTests.cs (4)
72AssertSerializationRoundtrips<AIContent>(content); 75where T : AIContent 108AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\McpServerToolResultContentTests.cs (5)
41IList<AIContent> outputs = [new TextContent("test result")]; 63AssertSerializationRoundtrips<AIContent>(content); 66where T : AIContent 98AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\TextContentTests.cs (2)
77AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\TextReasoningContentTests.cs (2)
86AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ToolApprovalRequestContentTests.cs (4)
86AssertSerializationRoundtrips<AIContent>(content); 89where T : AIContent 121AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ToolApprovalResponseContentTests.cs (4)
58AssertSerializationRoundtrips<AIContent>(content); 61where T : AIContent 120AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ToolCallContentTests.cs (3)
64foreach (var content in message.Contents) 98AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\ToolResultContentTests.cs (3)
63foreach (var content in message.Contents) 97AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\UriContentTests.cs (2)
235AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\UsageContentTests.cs (2)
102AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\WebSearchToolCallContentTests.cs (5)
63AIContent content = new WebSearchToolCallContent("ws_call456") 69var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 90AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Contents\WebSearchToolResultContentTests.cs (6)
31IList<AIContent> results = 106AIContent content = new WebSearchToolResultContent("ws_call456") 115var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 146AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Image\ImageGenerationResponseTests.cs (4)
30List<AIContent> content = []; 72List<AIContent> contents = [ 98List<AIContent> contents = [ 136List<AIContent> contents = [
Image\ImageGeneratorTests.cs (1)
139AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];
Realtime\RealtimeClientMessageTests.cs (1)
40var contents = new List<AIContent> { new TextContent("Hello") };
Realtime\RealtimeConversationItemTests.cs (5)
16IList<AIContent> contents = [new TextContent("Hello")]; 28IList<AIContent> contents = [new TextContent("Hello"), new TextContent("World")]; 39IList<AIContent> contents = [new TextContent("Initial")]; 42IList<AIContent> newContents = [new TextContent("Updated")]; 58IList<AIContent> contents = [functionCall];
SpeechToText\SpeechToTextResponseTests.cs (4)
17Assert.Throws<ArgumentNullException>("contents", () => new SpeechToTextResponse((IList<AIContent>)null!)); 64Assert.Throws<ArgumentNullException>("contents", () => new SpeechToTextResponse((IList<AIContent>)null!)); 73List<AIContent> content = []; 133List<AIContent> newContents = [new TextContent("text1"), new TextContent("text2")];
SpeechToText\SpeechToTextResponseUpdateTests.cs (1)
41List<AIContent> newList = [new TextContent("content1")];
TextToSpeech\TextToSpeechResponseTests.cs (2)
38List<AIContent> content = []; 84List<AIContent> newContents = [new DataContent(new byte[] { 1 }, "audio/mpeg"), new DataContent(new byte[] { 2 }, "audio/mpeg")];
TextToSpeech\TextToSpeechResponseUpdateTests.cs (1)
33List<AIContent> newList = [new DataContent(new byte[] { 1 }, "audio/mpeg")];
Utilities\AIJsonUtilitiesTests.cs (21)
706JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options); 1240AIContent c = new DerivedAIContent { DerivedValue = 42 }; 1244AIContent? deserialized = JsonSerializer.Deserialize<AIContent>(json, options); 1267Assert.Throws<ArgumentException>("contentType", () => options.AddAIContentType<AIContent>("discriminator")); 1281AIContent c = new DerivedAIContent(); 1317var aiContentTypes = options.GetTypeInfo(typeof(AIContent)).PolymorphismOptions!.DerivedTypes; 1333AIContent ac = new LeafContent { DerivedValue = 2, LeafValue = 99 }; 1339LeafContent deserializedAc = Assert.IsType<LeafContent>(JsonSerializer.Deserialize<AIContent>(json2, options)); 1369var aiContentTypes = options.GetTypeInfo(typeof(AIContent)).PolymorphismOptions!.DerivedTypes; 1383AIContent ac = new DerivedToolCallContent { CustomValue = 99 }; 1388DerivedToolCallContent deserializedAc = Assert.IsType<DerivedToolCallContent>(JsonSerializer.Deserialize<AIContent>(json2, options)); 1407var aiContentDerivedTypes = options.GetTypeInfo(typeof(AIContent)).PolymorphismOptions!.DerivedTypes; 1414AIContent ac = new DerivedAIContent { DerivedValue = 1 }; 1417DerivedAIContent deserializedDc = Assert.IsType<DerivedAIContent>(JsonSerializer.Deserialize<AIContent>(json, options)); 1429AIContent ac2 = new LeafContent { DerivedValue = 3, LeafValue = 99 }; 1432LeafContent deserializedAc = Assert.IsType<LeafContent>(JsonSerializer.Deserialize<AIContent>(json3, options)); 1453var aiContentDerivedTypes = options.GetTypeInfo(typeof(AIContent)).PolymorphismOptions!.DerivedTypes; 1460AIContent ac = new LeafContent { DerivedValue = 1, LeafValue = 42 }; 1463Assert.IsType<LeafContent>(JsonSerializer.Deserialize<AIContent>(json, options)); 1466AIContent unregistered = new DerivedAIContent { DerivedValue = 99 };
Microsoft.Extensions.AI.Evaluation (14)
ChatMessageExtensions.cs (2)
99/// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s 138/// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s
ChatResponseExtensions.cs (1)
20/// This function only considers the <see cref="ChatResponse.Text"/> and ignores any <see cref="AIContent"/>s
EvaluationContext.cs (11)
28/// <see cref="AIContent"/>s that represent <b>all</b> the contextual information that is modeled by the 41/// <see cref="Contents"/> property returns a collection of <see cref="AIContent"/>s that represent <b>all</b> the 53/// Gets or sets a list of <see cref="AIContent"/> objects that include all the information present in this 60/// images, and other similar <see cref="AIContent"/> objects for other modalities such as audio and video in the 70/// <see cref="AIContent"/>s that represent <b>all</b> the contextual information that is modeled by the 84/// <see cref="Contents"/> property returns a collection of <see cref="AIContent"/>s that represent <b>all</b> the 89/// A list of <see cref="AIContent"/> objects that include all the information present in this 92public IList<AIContent> Contents { get; set; } 101protected EvaluationContext(string name, IEnumerable<AIContent> contents) 114protected EvaluationContext(string name, params AIContent[] contents) 115: this(name, contents as IEnumerable<AIContent>)
Microsoft.Extensions.AI.Evaluation.Quality (1)
ChatResponseExtensions.cs (1)
29foreach (AIContent content in modelResponse.Messages.SelectMany(m => m.Contents))
Microsoft.Extensions.AI.Evaluation.Reporting (5)
JsonSerialization\EvaluationContextConverter.cs (5)
14private sealed class DeserializedEvaluationContext(string name, IReadOnlyList<AIContent> contents) 31IReadOnlyList<AIContent>? contents = null; 68JsonTypeInfo contentsTypeInfo = options.GetTypeInfo(typeof(IReadOnlyList<AIContent>)); 69contents = JsonSerializer.Deserialize(ref reader, contentsTypeInfo) as IReadOnlyList<AIContent>; 90JsonTypeInfo contentsTypeInfo = options.GetTypeInfo(typeof(IReadOnlyList<AIContent>));
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (5)
src\Libraries\Microsoft.Extensions.AI.Evaluation.Reporting\CSharp\JsonSerialization\EvaluationContextConverter.cs (5)
14private sealed class DeserializedEvaluationContext(string name, IReadOnlyList<AIContent> contents) 31IReadOnlyList<AIContent>? contents = null; 68JsonTypeInfo contentsTypeInfo = options.GetTypeInfo(typeof(IReadOnlyList<AIContent>)); 69contents = JsonSerializer.Deserialize(ref reader, contentsTypeInfo) as IReadOnlyList<AIContent>; 90JsonTypeInfo contentsTypeInfo = options.GetTypeInfo(typeof(IReadOnlyList<AIContent>));
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (7)
ScenarioRunResultTests.cs (7)
18private sealed class TestContext(string name, params AIContent[] contents) 460if (x?.Contents is IList<AIContent> xContents && y?.Contents is IList<AIContent> yContents) 472private class AIContentComparer : IEqualityComparer<AIContent> 476public bool Equals(AIContent? x, AIContent? y) 491public int GetHashCode(AIContent obj)
Microsoft.Extensions.AI.Evaluation.Safety (5)
AIContentExtensions.cs (2)
10internal static bool IsTextOrUsage(this AIContent content) 13internal static bool IsImageWithSupportedFormat(this AIContent content) =>
ContentSafetyEvaluator.cs (1)
112relevantContext.SelectMany(c => c.Contents) is IEnumerable<AIContent> contents && contents.Any() &&
ContentSafetyServicePayloadUtilities.cs (2)
316foreach (AIContent content in message.Contents) 452foreach (AIContent content in message.Contents)
Microsoft.Extensions.AI.Integration.Tests (12)
ImageGeneratingChatClientIntegrationTests.cs (2)
173var originalImage = Assert.Single(request.OriginalImages); 222var editContent = Assert.Single(secondRequest.OriginalImages);
ImageGeneratorIntegrationTests.cs (4)
46var content = Assert.Single(response.Contents); 80foreach (var content in response.Contents) 95AIContent[] originalImages = [new DataContent(imageData, "image/png") { Name = "dotnet.png" }]; 108var content = response.Contents[0];
PromptBasedFunctionCallingChatClient.cs (1)
90var contentItem = message.Contents.SingleOrDefault();
ReducingChatClientTests.cs (1)
98foreach (AIContent content in message.Contents)
TextToSpeechClientIntegrationTests.cs (4)
41var content = Assert.Single(response.Contents); 60var content = Assert.Single(response.Contents); 79var content = Assert.Single(response.Contents); 98var content = Assert.Single(response.Contents);
Microsoft.Extensions.AI.OpenAI (52)
MicrosoftExtensionsAIChatExtensions.cs (2)
89static IEnumerable<ChatMessageAnnotation> ConvertAnnotations(IEnumerable<AIContent>? contents) 96foreach (var content in contents)
OpenAIChatClient.cs (15)
183foreach (AIContent item in input.Contents) 209foreach (var content in input.Contents) 260/// <summary>Converts a list of <see cref="AIContent"/> to a list of <see cref="ChatMessageContentPart"/>.</summary> 261internal static List<ChatMessageContentPart> ToOpenAIChatContent(IEnumerable<AIContent> contents) 265foreach (var content in contents) 288private static ChatMessageContentPart? ToChatMessageContentPart(AIContent content) 292case AIContent when content.RawRepresentation is ChatMessageContentPart rawContentPart: 329private static ChatImageDetailLevel? GetImageDetail(AIContent content) 516if (ToAIContent(contentPart) is AIContent aiContent) 768/// <summary>Creates <see cref="AIContent"/>s from <see cref="ChatMessageContent"/>.</summary> 771internal static void ConvertContentParts(ChatMessageContent content, IList<AIContent> results) 782/// <summary>Creates an <see cref="AIContent"/> from a <see cref="ChatMessageContentPart"/>.</summary> 784/// <returns>The constructed <see cref="AIContent"/>, or <see langword="null"/> if the content part could not be converted.</returns> 785private static AIContent? ToAIContent(ChatMessageContentPart contentPart) 787AIContent? aiContent = null;
OpenAIImageGenerator.cs (2)
57var originalImage = request.OriginalImages.FirstOrDefault(); 114List<AIContent> contents = [];
OpenAIRealtimeClientSession.cs (6)
634var firstContent = contentItem.Contents[0]; 666foreach (var content in contentItem.Contents) 1123var contents = new List<AIContent>(); 1184var contents = new List<AIContent> 1195AIContent resultContent = mcpItem.Error is not null 1236var contents = new List<AIContent>();
OpenAIResponsesChatClient.cs (27)
203((List<AIContent>)message.Contents).AddRange(ToAIContents(messageItem.Content)); 385ChatResponseUpdate CreateUpdate(AIContent? content = null) => 588AIContent annotatedContent = new(); // do not include RawRepresentation to avoid duplication with already yielded deltas 929/// in <see cref="AIContent.AdditionalProperties"/> so it roundtrips back to the service.</summary> 1317foreach (AIContent item in input.Contents) 1346case AIContent when item.RawRepresentation is ResponseContentPart rawRep: 1405foreach (AIContent item in input.Contents) 1409case AIContent when item.RawRepresentation is ResponseItem rawRep: 1418static FunctionCallOutputResponseItem SerializeAIContent(string callId, IEnumerable<AIContent> contents) 1422foreach (var content in contents) 1505case AIContent ac: 1509case IEnumerable<AIContent> items: 1539foreach (AIContent item in input.Contents) 1543case AIContent when item.RawRepresentation is ResponseItem rawRep: 1682/// <summary>Convert a sequence of <see cref="ResponseContentPart"/>s to a list of <see cref="AIContent"/>.</summary> 1683private static List<AIContent> ToAIContents(IEnumerable<ResponseContentPart> contents) 1685List<AIContent> results = []; 1689AIContent content; 1753private static void PopulateAnnotations(ResponseContentPart source, AIContent destination) 1820private static List<AIContent>? GetWebSearchSources(WebSearchCallResponseItem wscri) 1827List<AIContent>? results = null; 1842/// <summary>Adds new <see cref="AIContent"/> for the specified <paramref name="mtci"/> into <paramref name="contents"/>.</summary> 1843private static void AddMcpToolCallContent(McpToolCallItem mtci, IList<AIContent> contents) 1875List<AIContent>? outputContents = null; 1917private static void AddHostedFileContents(List<AIContent> contents, CodeInterpreterCallOutput output, string? containerId) 1968private static void AddImageGenerationContents(ImageGenerationCallResponseItem outputItem, CreateResponseOptions? options, IList<AIContent> contents) 2056private static ResponseImageDetailLevel? GetImageDetail(AIContent content)
Microsoft.Extensions.AI.OpenAI.Tests (20)
OpenAIConversionTests.cs (8)
1101AIContent? apCallContent = updates[9].Contents.FirstOrDefault(c => c.RawRepresentation == applyPatchItem); 1106AIContent? apOutputContent = updates[10].Contents.FirstOrDefault(c => c.RawRepresentation == applyPatchOutputItem); 1145AIContent? genericContent = updates[0].Contents.FirstOrDefault(c => c.RawRepresentation == mcpApprovalResponse); 1437AIContent? genericContent = message.Contents.FirstOrDefault(c => c.RawRepresentation == mcpApprovalResponseItem); 1458AIContent content = Assert.Single(message.Contents); 1459Assert.IsType<AIContent>(content, exactMatch: true); 1478AIContent content = Assert.Single(message.Contents); 1479Assert.IsType<AIContent>(content, exactMatch: true);
OpenAIHostedFileClientIntegrationTests.cs (3)
285foreach (var content in msg.Contents) 355foreach (var content in msg.Contents) 403foreach (var content in msg.Contents)
OpenAIResponseClientIntegrationTests.cs (2)
587Tools = [AIFunctionFactory.Create((string city) => new List<AIContent> 663Tools = [AIFunctionFactory.Create(() => new List<AIContent>
OpenAIResponseClientTests.cs (5)
910AIContent computerUserItem = Assert.Single(responseMessage.Contents, content => content is ToolCallContent); 1759AIContent anchorContent = role == "user" 4880new FunctionResultContent("call_456", new List<AIContent> 5115new FunctionResultContent("call_mixed", new List<AIContent> 6668static bool HasCorrectImageData(AIContent o, int index)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (2)
33var expectedItem = expectedMessage.Contents[j]; 34var chatItem = chatMessage.Contents[j];
Microsoft.Extensions.AI.Stabilization.Tests (33)
AIContentSerializationRegressionContext.cs (1)
16[JsonSerializable(typeof(List<AIContent>))]
AIContentSerializationRegressionTests.cs (2)
21List<AIContent> contents = 28List<AIContent>? roundtripped = JsonSerializer.Deserialize(json, AIContentSerializationRegressionContext.Default.ListAIContent);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolCallContentTests.cs (3)
30IList<AIContent> inputs = [new TextContent("print('hello')")]; 109AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\CodeInterpreterToolResultContentTests.cs (3)
30IList<AIContent> output = [new TextContent("Hello, World!")]; 111AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\HostedFileContentTests.cs (2)
257AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolCallContentTests.cs (5)
53AIContent content = new ImageGenerationToolCallContent("img456"); 59var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 79AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\ImageGenerationToolResultContentTests.cs (6)
31IList<AIContent> outputs = [new DataContent(new byte[] { 1, 2, 3 }, "image/png")]; 94AIContent content = new ImageGenerationToolResultContent("img789") 107var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 140AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\WebSearchToolCallContentTests.cs (5)
63AIContent content = new WebSearchToolCallContent("ws_call456") 69var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 90AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\Contents\WebSearchToolResultContentTests.cs (6)
31IList<AIContent> results = 106AIContent content = new WebSearchToolResultContent("ws_call456") 115var deserialized = JsonSerializer.Deserialize<AIContent>(json, AIJsonUtilities.DefaultOptions); 146AIContent? result = JsonSerializer.Deserialize<AIContent>(Json, AIJsonUtilities.DefaultOptions);
Microsoft.Extensions.AI.Tests (45)
ChatCompletion\DistributedCachingChatClientTest.cs (5)
695if (typeInfo.Type == typeof(AIContent)) 812var expectedItem = expectedMessage.Contents[itemIndex]; 813var actualItem = actualMessage.Contents[itemIndex]; 846var expectedItemItem = expectedItem.Contents[itemIndex]; 847var actualItemItem = actualItem.Contents[itemIndex];
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (4)
1904Array.Empty<AIContent>() 1923Array.Empty<AIContent>() 2092private static AIContent CloneFcc(AIContent c) => c switch
ChatCompletion\FunctionInvokingChatClientTests.cs (6)
1000IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 1361AIContent[] resultContents = existingSearchResult is not null && existingSearchResult.Contents.OfType<FunctionResultContent>().ToList() is { } frcs 2321private static List<AIContent> CloneContents(IList<AIContent> contents) 2323var cloned = new List<AIContent>(contents.Count); 2324foreach (var content in contents)
ChatCompletion\ImageGeneratingChatClientTests.cs (2)
403IList<AIContent> contents = position switch 478IList<AIContent> contents = position switch
Functions\AIFunctionFactoryTest.cs (25)
1162AIFunctionFactory.Create(() => (AIContent)new TextContent("text")), 1163AIFunctionFactory.Create(async () => (AIContent)new TextContent("text")), 1164AIFunctionFactory.Create(async ValueTask<AIContent> () => (AIContent)new TextContent("text")), 1167AIFunctionFactory.Create(async ValueTask<AIContent> () => new TextContent("text")), 1177await ValidateAsync<IEnumerable<AIContent>>( 1179AIFunctionFactory.Create(() => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1180AIFunctionFactory.Create(async () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1181AIFunctionFactory.Create(async ValueTask<IEnumerable<AIContent>> () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1184await ValidateAsync<AIContent[]>( 1186AIFunctionFactory.Create(() => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1187AIFunctionFactory.Create(async () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1188AIFunctionFactory.Create(async ValueTask<AIContent[]> () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1191await ValidateAsync<List<AIContent>>( 1193AIFunctionFactory.Create(() => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1194AIFunctionFactory.Create(async () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1195AIFunctionFactory.Create(async ValueTask<List<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1198await ValidateAsync<IEnumerable<AIContent>>( 1200AIFunctionFactory.Create(() => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1201AIFunctionFactory.Create(async () => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]), 1202AIFunctionFactory.Create(async ValueTask<IList<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
Image\LoggingImageGeneratorTests.cs (1)
116AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (2)
33var expectedItem = expectedMessage.Contents[j]; 34var chatItem = chatMessage.Contents[j];
Microsoft.Extensions.DataIngestion (2)
Processors\ImageAlternativeTextEnricher.cs (1)
90List<AIContent> contents = new(batch.Count);
Utils\Batching.cs (1)
30List<AIContent> contents = new(batch.Length);