11 types derived from AIContent
Microsoft.Extensions.AI.Abstractions (8)
Contents\DataContent.cs (1)
37public 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\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)
1310private class DerivedAIContent : AIContent
Microsoft.Extensions.AI.Tests (2)
ChatCompletion\DistributedCachingChatClientTest.cs (2)
841public class CustomAIContent1(string text, DateTime date) : AIContent 847public class CustomAIContent2(string text, int number) : AIContent
5 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 (2)
OpenAIResponseChatClient.cs (2)
132message.Contents.Add(new() 588results.Add(new()
164 references to AIContent
Microsoft.Extensions.AI (5)
ChatCompletion\FunctionInvokingChatClient.cs (3)
344IList<AIContent> contents = update.Contents; 513IList<AIContent> content, [NotNullWhen(true)] ref List<FunctionCallContent>? functionCalls) 748var 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 (45)
ChatCompletion\ChatMessage.cs (5)
17private IList<AIContent>? _contents; 38public ChatMessage(ChatRole role, IList<AIContent>? contents) 80public IList<AIContent> Contents 104/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary> 106private AIContent? ContentForDebuggerDisplay => _contents is { Count: > 0 } ? _contents[0] : null;
ChatCompletion\ChatResponseExtensions.cs (12)
53/// contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 72/// <param name="filter">A predicate to filter which <see cref="AIContent"/> gets included in the message.</param> 79public static void AddMessages(this IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool>? filter = null) 106/// contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 129/// message boundaries, as well as coalescing contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 157/// message boundaries, as well as coalescing contiguous <see cref="AIContent"/> items where applicable, e.g. multiple 183/// <summary>Coalesces sequential <see cref="AIContent"/> content elements.</summary> 184internal static void CoalesceTextContent(List<AIContent> contents) 190static void Coalesce<TContent>(List<AIContent> contents, Func<string, TContent> fromText) 191where TContent : AIContent 245CoalesceTextContent((List<AIContent>)response.Messages[i].Contents); 300foreach (var content in update.Contents)
ChatCompletion\ChatResponseUpdate.cs (5)
36private IList<AIContent>? _contents; 58public ChatResponseUpdate(ChatRole? role, IList<AIContent>? contents) 83public IList<AIContent> Contents 142/// <summary>Gets a <see cref="AIContent"/> object to display in the debugger display.</summary> 144private AIContent? ContentForDebuggerDisplay => _contents is { Count: > 0 } ? _contents[0] : null;
Contents\AIContent.cs (2)
21/// Initializes a new instance of the <see cref="AIContent"/> class. 29/// 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)
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)
115[JsonSerializable(typeof(AIContent))]
Microsoft.Extensions.AI.Abstractions.Tests (26)
ChatCompletion\ChatMessageTests.cs (6)
71message = new(ChatRole.User, (IList<AIContent>?)null); 75message = new ChatMessage(ChatRole.User, Array.Empty<AIContent>()); 86List<AIContent> content = []; 168Assert.IsType<List<AIContent>>(new ChatMessage().Contents); 177List<AIContent> contents = []; 237IList<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)));
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)
430JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options); 942AIContent c = new DerivedAIContent { DerivedValue = 42 }; 946AIContent? deserialized = JsonSerializer.Deserialize<AIContent>(json, options); 969Assert.Throws<ArgumentException>(() => options.AddAIContentType<AIContent>("discriminator")); 980AIContent c = new DerivedAIContent();
Microsoft.Extensions.AI.AzureAIInference (5)
AzureAIInferenceChatClient.cs (5)
447foreach (AIContent item in input.Contents) 491foreach (var content in input.Contents) 508/// <summary>Converts a list of <see cref="AIContent"/> to a list of <see cref="ChatMessageContentItem"/>.</summary> 509private static List<ChatMessageContentItem> GetContentParts(IList<AIContent> contents) 514foreach (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) 342if (x?.Contents is IList<AIContent> xContents && y?.Contents is IList<AIContent> yContents) 354private class AIContentComparer : IEqualityComparer<AIContent> 358public bool Equals(AIContent? x, AIContent? y) 373public 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 (2)
PromptBasedFunctionCallingChatClient.cs (1)
90var contentItem = message.Contents.SingleOrDefault();
ReducingChatClientTests.cs (1)
158foreach (AIContent content in message.Contents)
Microsoft.Extensions.AI.Ollama (2)
OllamaChatClient.cs (2)
261List<AIContent> contents = []; 415foreach (var item in content.Contents)
Microsoft.Extensions.AI.OpenAI (28)
OpenAIAssistantChatClient.cs (2)
399foreach (AIContent content in chatMessage.Contents) 420case AIContent when content.RawRepresentation is MessageContent rawRep:
OpenAIChatClient.cs (14)
136foreach (AIContent item in input.Contents) 162foreach (var content in input.Contents) 213/// <summary>Converts a list of <see cref="AIContent"/> to a list of <see cref="ChatMessageContentPart"/>.</summary> 214private static List<ChatMessageContentPart> ToOpenAIChatContent(IList<AIContent> contents) 218foreach (var content in contents) 234private static ChatMessageContentPart? ToChatMessageContentPart(AIContent content) 263case AIContent when content.RawRepresentation is ChatMessageContentPart rawContentPart: 270private static ChatImageDetailLevel? GetImageDetail(AIContent content) 324if (ToAIContent(contentPart) is AIContent aiContent) 420if (ToAIContent(contentPart) is AIContent aiContent) 609/// <summary>Creates an <see cref="AIContent"/> from a <see cref="ChatMessageContentPart"/>.</summary> 611/// <returns>The constructed <see cref="AIContent"/>, or <see langword="null"/> if the content part could not be converted.</returns> 612private static AIContent? ToAIContent(ChatMessageContentPart contentPart) 614AIContent? aiContent = null;
OpenAIResponseChatClient.cs (12)
106Debug.Assert(message.Contents is List<AIContent>, "Expected a List<AIContent> for message contents."); 117((List<AIContent>)message.Contents).AddRange(ToAIContents(messageItem.Content)); 482foreach (AIContent item in input.Contents) 510foreach (AIContent item in input.Contents) 527case AIContent when item.RawRepresentation is ResponseItem rawRep: 563/// <summary>Convert a sequence of <see cref="ResponseContentPart"/>s to a list of <see cref="AIContent"/>.</summary> 564private static List<AIContent> ToAIContents(IEnumerable<ResponseContentPart> contents) 566List<AIContent> results = []; 599/// <summary>Convert a list of <see cref="AIContent"/>s to a list of <see cref="ResponseContentPart"/>.</summary> 600private static List<ResponseContentPart> ToOpenAIResponsesContent(IList<AIContent> contents) 603foreach (var content in contents) 628case AIContent when content.RawRepresentation is ResponseContentPart rawRep:
Microsoft.Extensions.AI.Tests (11)
ChatCompletion\DistributedCachingChatClientTest.cs (5)
648if (typeInfo.Type == typeof(AIContent)) 768var expectedItem = expectedMessage.Contents[itemIndex]; 769var actualItem = actualMessage.Contents[itemIndex]; 802var expectedItemItem = expectedItem.Contents[itemIndex]; 803var actualItemItem = actualItem.Contents[itemIndex];
ChatCompletion\FunctionInvokingChatClientTests.cs (6)
423IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 766AIContent[] resultContents = existingSearchResult is not null && existingSearchResult.Contents.OfType<FunctionResultContent>().ToList() is { } frcs 986var expectedItem = expectedMessage.Contents[j]; 987var chatItem = chatMessage.Contents[j]; 1080var expectedItem = expectedMessage.Contents[j]; 1081var chatItem = chatMessage.Contents[j];