13 types derived from AIContent
Microsoft.Extensions.AI.Abstractions (10)
Contents\DataContent.cs (1)
38public class DataContent : AIContent
Contents\ErrorContent.cs (1)
15public class ErrorContent : AIContent
Contents\FunctionCallContent.cs (1)
17public sealed class FunctionCallContent : AIContent
Contents\FunctionResultContent.cs (1)
16public sealed class FunctionResultContent : AIContent
Contents\HostedFileContent.cs (1)
18public sealed class HostedFileContent : AIContent
Contents\HostedVectorStoreContent.cs (1)
19public sealed class HostedVectorStoreContent : AIContent
Contents\TextContent.cs (1)
13public sealed class TextContent : AIContent
Contents\TextReasoningContent.cs (1)
18public sealed class TextReasoningContent : AIContent
Contents\UriContent.cs (1)
19public class UriContent : AIContent
Contents\UsageContent.cs (1)
14public class UsageContent : AIContent
Microsoft.Extensions.AI.Abstractions.Tests (1)
Utilities\AIJsonUtilitiesTests.cs (1)
1354private class DerivedAIContent : AIContent
Microsoft.Extensions.AI.Tests (2)
ChatCompletion\DistributedCachingChatClientTest.cs (2)
887public class CustomAIContent1(string text, DateTime date) : AIContent 893public class CustomAIContent2(string text, int number) : AIContent
6 instantiations of AIContent
Microsoft.Extensions.AI.Abstractions.Tests (3)
Contents\AIContentTests.cs (3)
14AIContent c = new(); 22AIContent c = new(); 38AIContent original = new()
Microsoft.Extensions.AI.OpenAI (3)
OpenAIResponsesChatClient.cs (3)
166message.Contents.Add(new() { RawRepresentation = outputItem }); 258AIContent annotatedContent = new(); 663results.Add(new() { RawRepresentation = part });
201 references to AIContent
Microsoft.Extensions.AI (5)
ChatCompletion\FunctionInvokingChatClient.cs (3)
363IList<AIContent> contents = update.Contents; 532IList<AIContent> content, [NotNullWhen(true)] ref List<FunctionCallContent>? functionCalls) 791var contents = new List<AIContent>(results.Length);
ChatCompletion\OpenTelemetryChatClient.cs (2)
525private AssistantEvent CreateAssistantEvent(IEnumerable<AIContent> contents) 546private string? GetMessageContent(IEnumerable<AIContent> contents)
Microsoft.Extensions.AI.Abstractions (64)
ChatCompletion\ChatMessage.cs (5)
19private IList<AIContent>? _contents; 40public ChatMessage(ChatRole role, IList<AIContent>? contents) 86public IList<AIContent> Contents 110/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary> 112private AIContent? ContentForDebuggerDisplay
ChatCompletion\ChatResponseExtensions.cs (16)
55/// contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 74/// <param name="filter">A predicate to filter which <see cref="AIContent"/> gets included in the message.</param> 81public static void AddMessages(this IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool>? filter = null) 109/// contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 132/// message boundaries, as well as coalescing contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 160/// message boundaries, as well as coalescing contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 186/// <summary>Coalesces sequential <see cref="AIContent"/> content elements.</summary> 187internal static void CoalesceTextContent(IList<AIContent> contents) 201static string MergeText(IList<AIContent> contents, int start, int end) 212static void Coalesce<TContent>(IList<AIContent> contents, bool mergeSingle, Func<IList<AIContent>, int, int, TContent> merge) 213where TContent : AIContent 250static bool TryAsCoalescable(AIContent content, [NotNullWhen(true)] out TContent? coalescable) 264if (contents is List<AIContent> contentsList) 296CoalesceTextContent((List<AIContent>)response.Messages[i].Contents); 357foreach (var content in update.Contents)
ChatCompletion\ChatResponseUpdate.cs (5)
38private IList<AIContent>? _contents; 60public ChatResponseUpdate(ChatRole? role, IList<AIContent>? contents) 85public IList<AIContent> Contents 144/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary> 146private 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)
24/// Initializes a new instance of the <see cref="AIContent"/> class. 37/// 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\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"/>.
HostedCodeInterpreterTool.cs (2)
20/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the code interpreter tool.</summary> 26public IList<AIContent>? Inputs { get; set; }
HostedFileSearchTool.cs (2)
20/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the file search tool.</summary> 27public IList<AIContent>? Inputs { get; set; }
Image\ImageGenerationRequest.cs (2)
28public ImageGenerationRequest(string prompt, IEnumerable<AIContent>? originalImages) 44public IEnumerable<AIContent>? OriginalImages { get; set; }
Image\ImageGenerationResponse.cs (3)
17private IList<AIContent>? _contents; 27public ImageGenerationResponse(IList<AIContent>? contents) 47public IList<AIContent> Contents
Image\ImageGeneratorExtensions.cs (1)
131IEnumerable<AIContent> originalImages,
SpeechToText\SpeechToTextResponse.cs (4)
19private IList<AIContent>? _contents; 29public SpeechToTextResponse(IList<AIContent> contents) 79IList<AIContent> contents = Contents; 102public IList<AIContent> Contents
SpeechToText\SpeechToTextResponseUpdate.cs (3)
36private IList<AIContent>? _contents; 46public SpeechToTextResponseUpdate(IList<AIContent> contents) 94public IList<AIContent> Contents
SpeechToText\SpeechToTextResponseUpdateExtensions.cs (3)
35ChatResponseExtensions.CoalesceTextContent((List<AIContent>)response.Contents); 61ChatResponseExtensions.CoalesceTextContent((List<AIContent>)response.Contents); 96foreach (var content in update.Contents)
Utilities\AIJsonUtilities.cs (7)
28/// Adds a custom content type to the polymorphic configuration for <see cref="AIContent"/>. 37where TContent : AIContent 46/// Adds a custom content type to the polymorphic configuration for <see cref="AIContent"/>. 52/// <exception cref="ArgumentException"><paramref name="contentType"/> is a built-in content type or does not derived from <see cref="AIContent"/>.</exception> 60if (!typeof(AIContent).IsAssignableFrom(contentType)) 194if (contentType.Assembly == typeof(AIContent).Assembly) 202if (typeInfo.Type == typeof(AIContent))
Utilities\AIJsonUtilities.Defaults.cs (1)
117[JsonSerializable(typeof(AIContent))]
Microsoft.Extensions.AI.Abstractions.Tests (31)
ChatCompletion\ChatMessageTests.cs (6)
73message = new(ChatRole.User, (IList<AIContent>?)null); 77message = new ChatMessage(ChatRole.User, Array.Empty<AIContent>()); 88List<AIContent> content = []; 171Assert.IsType<List<AIContent>>(new ChatMessage().Contents); 180List<AIContent> contents = []; 254IList<AIContent> items =
ChatCompletion\ChatResponseUpdateTests.cs (1)
48IList<AIContent> newList = [new TextContent("text")];
Contents\AIContentTests.cs (7)
14AIContent c = new(); 22AIContent c = new(); 38AIContent original = new() 47string json = JsonSerializer.Serialize(original, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent))); 50AIContent? deserialized = (AIContent?)JsonSerializer.Deserialize(json, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent)));
Image\ImageGenerationResponseTests.cs (4)
30List<AIContent> content = []; 72List<AIContent> contents = [ 98List<AIContent> contents = [ 136List<AIContent> contents = [
Image\ImageGeneratorTests.cs (1)
140AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];
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 (2)
41List<AIContent> newList = new(); 92Contents = new List<AIContent>
Utilities\AIJsonUtilitiesTests.cs (6)
473JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options); 986AIContent c = new DerivedAIContent { DerivedValue = 42 }; 990AIContent? deserialized = JsonSerializer.Deserialize<AIContent>(json, options); 1013Assert.Throws<ArgumentException>(() => options.AddAIContentType<AIContent>("discriminator")); 1024AIContent c = new DerivedAIContent();
Microsoft.Extensions.AI.AzureAIInference (5)
AzureAIInferenceChatClient.cs (5)
448foreach (AIContent item in input.Contents) 492foreach (var content in input.Contents) 509/// <summary>Converts a list of <see cref="AIContent"/> to a list of <see cref="ChatMessageContentItem"/>.</summary> 510private static List<ChatMessageContentItem> GetContentParts(IList<AIContent> contents) 515foreach (var content in contents)
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
145[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] : 218[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] :
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 60/// Gets or sets a list of <see cref="AIContent"/> objects that include all the information present in this 67/// images, and other similar <see cref="AIContent"/> objects for other modalities such as audio and video in the 77/// <see cref="AIContent"/>s that represent <b>all</b> the contextual information that is modeled by the 91/// <see cref="Contents"/> property returns a collection of <see cref="AIContent"/>s that represent <b>all</b> the 96/// A list of <see cref="AIContent"/> objects that include all the information present in this 99public IList<AIContent> Contents { get; set; } 109protected EvaluationContext(string name, IEnumerable<AIContent> contents) 122protected EvaluationContext(string name, params AIContent[] contents) 123: 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 (8)
ScenarioRunResultTests.cs (7)
17private sealed class TestContext(string name, params AIContent[] contents) 344if (x?.Contents is IList<AIContent> xContents && y?.Contents is IList<AIContent> yContents) 356private class AIContentComparer : IEqualityComparer<AIContent> 360public bool Equals(AIContent? x, AIContent? y) 375public int GetHashCode(AIContent obj)
SerializationChainingTests.cs (1)
32Contents = new List<AIContent>
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)
120relevantContext.SelectMany(c => c.Contents) is IEnumerable<AIContent> contents && contents.Any() &&
ContentSafetyServicePayloadUtilities.cs (2)
320foreach (AIContent content in message.Contents) 456foreach (AIContent content in message.Contents)
Microsoft.Extensions.AI.Integration.Tests (6)
ImageGeneratorIntegrationTests.cs (4)
48var content = response.Contents[0]; 71foreach (var content in response.Contents) 86AIContent[] originalImages = [new DataContent(imageData, "image/png") { Name = "dotnet.png" }]; 99var content = response.Contents[0];
PromptBasedFunctionCallingChatClient.cs (1)
90var contentItem = message.Contents.SingleOrDefault();
ReducingChatClientTests.cs (1)
99foreach (AIContent content in message.Contents)
Microsoft.Extensions.AI.OpenAI (38)
MicrosoftExtensionsAIChatExtensions.cs (2)
76static IEnumerable<ChatMessageAnnotation> ConvertAnnotations(IEnumerable<AIContent>? contents) 83foreach (var content in contents)
OpenAIAssistantsChatClient.cs (4)
362foreach (var input in codeInterpreterTool.Inputs) 383foreach (var input in fileSearchInputs) 489foreach (AIContent content in chatMessage.Contents) 493case AIContent when content.RawRepresentation is MessageContent rawRep:
OpenAIChatClient.cs (15)
148foreach (AIContent item in input.Contents) 174foreach (var content in input.Contents) 225/// <summary>Converts a list of <see cref="AIContent"/> to a list of <see cref="ChatMessageContentPart"/>.</summary> 226internal static List<ChatMessageContentPart> ToOpenAIChatContent(IEnumerable<AIContent> contents) 230foreach (var content in contents) 253private static ChatMessageContentPart? ToChatMessageContentPart(AIContent content) 257case AIContent when content.RawRepresentation is ChatMessageContentPart rawContentPart: 292private static ChatImageDetailLevel? GetImageDetail(AIContent content) 459if (ToAIContent(contentPart) is AIContent aiContent) 659/// <summary>Creates <see cref="AIContent"/>s from <see cref="ChatMessageContent"/>.</summary> 662internal static void ConvertContentParts(ChatMessageContent content, IList<AIContent> results) 673/// <summary>Creates an <see cref="AIContent"/> from a <see cref="ChatMessageContentPart"/>.</summary> 675/// <returns>The constructed <see cref="AIContent"/>, or <see langword="null"/> if the content part could not be converted.</returns> 676private static AIContent? ToAIContent(ChatMessageContentPart contentPart) 678AIContent? aiContent = null;
OpenAIImageGenerator.cs (2)
78var originalImage = request.OriginalImages.FirstOrDefault(); 157List<AIContent> contents = new();
OpenAIResponsesChatClient.cs (15)
148((List<AIContent>)message.Contents).AddRange(ToAIContents(messageItem.Content)); 206ChatResponseUpdate CreateUpdate(AIContent? content = null) => 258AIContent annotatedContent = new(); 526foreach (AIContent item in input.Contents) 530case AIContent when item.RawRepresentation is ResponseItem rawRep: 558foreach (AIContent item in input.Contents) 562case AIContent when item.RawRepresentation is ResponseItem rawRep: 619/// <summary>Convert a sequence of <see cref="ResponseContentPart"/>s to a list of <see cref="AIContent"/>.</summary> 620private static List<AIContent> ToAIContents(IEnumerable<ResponseContentPart> contents) 622List<AIContent> results = []; 672private static void PopulateAnnotations(ResponseContentPart source, AIContent destination) 690/// <summary>Convert a list of <see cref="AIContent"/>s to a list of <see cref="ResponseContentPart"/>.</summary> 691private static List<ResponseContentPart> ToResponseContentParts(IList<AIContent> contents) 694foreach (var content in contents) 698case AIContent when content.RawRepresentation is ResponseContentPart rawRep:
Microsoft.Extensions.AI.Tests (12)
ChatCompletion\DistributedCachingChatClientTest.cs (5)
694if (typeInfo.Type == typeof(AIContent)) 814var expectedItem = expectedMessage.Contents[itemIndex]; 815var actualItem = actualMessage.Contents[itemIndex]; 848var expectedItemItem = expectedItem.Contents[itemIndex]; 849var actualItemItem = actualItem.Contents[itemIndex];
ChatCompletion\FunctionInvokingChatClientTests.cs (6)
569IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 912AIContent[] resultContents = existingSearchResult is not null && existingSearchResult.Contents.OfType<FunctionResultContent>().ToList() is { } frcs 1132var expectedItem = expectedMessage.Contents[j]; 1133var chatItem = chatMessage.Contents[j]; 1226var expectedItem = expectedMessage.Contents[j]; 1227var chatItem = chatMessage.Contents[j];
Image\LoggingImageGeneratorTests.cs (1)
117AIContent[] originalImages = [new DataContent((byte[])[1, 2, 3, 4], "image/png")];