97 instantiations of TextContent
Microsoft.Extensions.AI.Abstractions (5)
ChatCompletion\ChatMessage.cs (1)
31: this(role, content is null ? [] : [new TextContent(content)])
ChatCompletion\ChatResponseExtensions.cs (1)
188Coalesce<TextContent>(contents, static text => new(text));
ChatCompletion\ChatResponseUpdate.cs (1)
51: this(role, content is null ? null : [new TextContent(content)])
SpeechToText\SpeechToTextResponse.cs (1)
37: this(content is null ? [] : [new TextContent(content)])
SpeechToText\SpeechToTextResponseUpdate.cs (1)
54: this(content is null ? [] : [new TextContent(content)])
Microsoft.Extensions.AI.Abstractions.Tests (40)
ChatCompletion\ChatMessageTests.cs (5)
91content.Add(new TextContent($"text-{i}")); 150new TextContent("text-1"), 151new TextContent("text-2"), 256new TextContent("content-1") 268new TextContent("content-4")
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (10)
255new() { Contents = [new TextContent("D") { Annotations = [new()] }] }, 256new() { Contents = [new TextContent("E") { Annotations = [new()] }] }, 257new() { Contents = [new TextContent("F") { Annotations = [new()] }] }, 258new() { Contents = [new TextContent("G") { Annotations = [] }] }, 259new() { Contents = [new TextContent("H") { Annotations = [] }] }, 260new() { Contents = [new TextContent("I") { Annotations = [new()] }] }, 261new() { Contents = [new TextContent("J") { Annotations = [new()] }] }, 263new() { Contents = [new TextContent("L") { Annotations = [new()] }] }, 266new() { Contents = [new TextContent("O") { Annotations = [new()] }] }, 267new() { Contents = [new TextContent("P") { Annotations = [new()] }] },
ChatCompletion\ChatResponseUpdateTests.cs (6)
44update.Contents.Add(new TextContent("text")); 48IList<AIContent> newList = [new TextContent("text")]; 95new TextContent("text-1"), 96new TextContent("text-2"), 121new TextContent("text-1"), 125new TextContent("text-2"),
Contents\TextContentTests.cs (2)
16TextContent c = new(text); 25TextContent c = new(null);
SpeechToText\SpeechToTextClientExtensionsTests.cs (1)
65update.Contents.Add(new TextContent("world"));
SpeechToText\SpeechToTextResponseTests.cs (9)
76content.Add(new TextContent($"text-{i}")); 133List<AIContent> newContents = [new TextContent("text1"), new TextContent("text2")]; 150new TextContent("Text1"), 151new TextContent("Text2"), 152new TextContent("Text3"), 153new TextContent("Text4"), 210new TextContent("Hello, "), 212new TextContent("world!")
SpeechToText\SpeechToTextResponseUpdateExtensionsTests.cs (3)
52new([new TextContent("You?")]) { ModelId = "model123", StartTime = TimeSpan.FromSeconds(24), EndTime = TimeSpan.FromSeconds(25), AdditionalProperties = new() { ["c"] = "d" } }, 139new() { Contents = [new TextContent("Hello, ")] }, 141new() { Contents = [new TextContent("world!")] },
SpeechToText\SpeechToTextResponseUpdateTests.cs (4)
42newList.Add(new TextContent("content1")); 66new TextContent("text-1"), 67new TextContent("text-2"), 94new TextContent("text-1"),
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
180responseUpdate.Contents.Add(new TextContent(update));
Microsoft.Extensions.AI.AzureAIInference.Tests (3)
AzureAIInferenceChatClientTests.cs (3)
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())] : 1069new TextContent("Describe this picture."),
Microsoft.Extensions.AI.Evaluation (1)
EvaluationContext.cs (1)
135: this(name, contents: new TextContent(content))
Microsoft.Extensions.AI.Evaluation.Integration.Tests (6)
SafetyEvaluatorTests.cs (6)
337new TextContent("What does this image depict?"), 375new TextContent("Here's an image pertaining to DotNet:"), 409new TextContent("What does this image depict?"), 422new TextContent("Here's an image pertaining to Microsoft Copilot:"), 458new TextContent("What does this image depict?"), 471new TextContent("Here's an image pertaining to Microsoft Copilot:"),
Microsoft.Extensions.AI.Evaluation.NLP (2)
BLEUEvaluatorContext.cs (1)
59contents: [.. references.Select(c => new TextContent(c))])
GLEUEvaluatorContext.cs (1)
59contents: [.. references.Select(c => new TextContent(c))])
Microsoft.Extensions.AI.Evaluation.Quality (4)
IntentResolutionEvaluatorContext.cs (1)
43: base(name: ToolDefinitionsContextName, contents: [new TextContent(toolDefinitions.RenderAsJson())])
RetrievalEvaluatorContext.cs (1)
47contents: [.. retrievedContextChunks.Select(c => new TextContent(c))])
TaskAdherenceEvaluatorContext.cs (1)
44: base(name: ToolDefinitionsContextName, contents: [new TextContent(toolDefinitions.RenderAsJson())])
ToolCallAccuracyEvaluatorContext.cs (1)
45: base(name: ToolDefinitionsContextName, contents: [new TextContent(toolDefinitions.RenderAsJson())])
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (7)
ScenarioRunResultTests.cs (6)
23var content1 = new TextContent("content1"); 24var content2 = new TextContent("content2"); 25var content3 = new TextContent("content3"); 114var content1 = new TextContent("content1"); 115var content2 = new TextContent("content2"); 116var content3 = new TextContent("content3");
SerializationChainingTests.cs (1)
34new TextContent("A user message"),
Microsoft.Extensions.AI.Integration.Tests (2)
ChatClientIntegrationTests.cs (2)
186new TextContent("What does this logo say?"), 204new TextContent("What text does this document contain?"),
Microsoft.Extensions.AI.OpenAI (6)
OpenAIChatClient.cs (2)
499annotationContent = new(null); 681aiContent = new TextContent(contentPart.Text);
OpenAIResponsesChatClient.cs (1)
626TextContent text = new(part.Text)
OpenAISpeechToTextClient.cs (3)
85response.Contents = [new TextContent(translation.Text)]; 99response.Contents = [new TextContent(transcription.Text)]; 157result.Contents = [new TextContent(deltaUpdate.Delta)];
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIChatClientTests.cs (4)
911new(ChatRole.System, [new TextContent("You are a really nice friend."), new TextContent("Really nice.")]), 1453new TextContent("hi, how are you?"), 1571new TextContent("What does this logo say?"),
OpenAIConversionTests.cs (6)
94new TextContent("Hi there!"), 160new TextContent("Hi there!"), 363new TextContent("I'll call a function."), 399new TextContent("Here's an image and some text."), 468new TextContent("I'll process this complex data."), 723new TextContent("Processing your request..."),
Microsoft.Extensions.AI.Tests (10)
ChatCompletion\DistributedCachingChatClientTest.cs (5)
368new() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] }, 369new() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] }, 375new TextContent("how ") 386new TextContent("are you?") 744new ChatMessage(ChatRole.Assistant, [new TextContent("Hey")])));
ChatCompletion\FunctionInvokingChatClientTests.cs (5)
553new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new FunctionCallContent("callId1", "Func1"), new TextContent("stuff")]), 557new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } }), new TextContent("more")]), 749updates = [new() { Contents = [new TextContent("OK bye")] }]; 913? [new TextContent($"The search results were '{string.Join(", ", frcs.Select(frc => frc.Result))}'")]
136 references to TextContent
Microsoft.Extensions.AI (1)
ChatCompletion\OpenTelemetryChatClient.cs (1)
550string content = string.Concat(contents.OfType<TextContent>());
Microsoft.Extensions.AI.Abstractions (24)
ChatCompletion\ChatMessage.cs (1)
77/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
ChatCompletion\ChatResponseExtensions.cs (10)
55/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 109/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 132/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 160/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 188Coalesce<TextContent>(contents, static text => new(text)); 239if (content is TContent && (content is not TextContent tc || tc.Annotations is not { Count: > 0 }))
ChatCompletion\ChatResponseUpdate.cs (1)
76/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
Contents\AIAnnotation.cs (1)
26/// for <see cref="TextContent"/>.
Contents\AIContent.cs (1)
15[JsonDerivedType(typeof(TextContent), typeDiscriminator: "text")]
Contents\AIContentExtensions.cs (4)
18/// <summary>Concatenates the text of all <see cref="TextContent"/> instances in the list.</summary> 30return (list[0] as TextContent)?.Text ?? string.Empty; 37if (list[i] is TextContent text) 59return string.Concat(contents.OfType<TextContent>());
Contents\TextContent.cs (1)
18/// Initializes a new instance of the <see cref="TextContent"/> class.
Contents\TextReasoningContent.cs (2)
13/// <see cref="TextReasoningContent"/> is distinct from <see cref="TextContent"/>. <see cref="TextReasoningContent"/> 15/// the model, which is represented by <see cref="TextContent"/>. Neither types derives from the other.
Contents\TextSpanAnnotatedRegion.cs (1)
10/// <remarks>This <see cref="AnnotatedRegion"/> typically applies to <see cref="TextContent"/>.</remarks>
SpeechToText\SpeechToTextResponse.cs (1)
67/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
SpeechToText\SpeechToTextResponseUpdate.cs (1)
87/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
Microsoft.Extensions.AI.Abstractions.Tests (52)
ChatCompletion\ChatMessageTests.cs (11)
49TextContent tc = Assert.IsType<TextContent>(message.Contents[0]); 109TextContent tc = Assert.IsType<TextContent>(message.Contents[i]); 155TextContent textContent = Assert.IsType<TextContent>(message.Contents[3]); 160((TextContent)message.Contents[3]).Text = "text-3"; 282((TextContent)chatMessage.Contents[0]).Text = "content-1-override"; // Override the content of the first text content item that has the "content-1" content 297var textContent = deserializedMessage.Contents[0] as TextContent; 320textContent = deserializedMessage.Contents[3] as TextContent;
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (19)
199TextContent[] contents = message.Contents.OfType<TextContent>().ToArray(); 235Assert.Equal("ABC", Assert.IsType<TextContent>(message.Contents[0]).Text); 237Assert.Equal("GH", Assert.IsType<TextContent>(message.Contents[2]).Text); 239Assert.Equal("K", Assert.IsType<TextContent>(message.Contents[4]).Text); 241Assert.Equal("MN", Assert.IsType<TextContent>(message.Contents[6]).Text); 273Assert.Equal("ABC", Assert.IsType<TextContent>(message.Contents[0]).Text); 274Assert.Equal("D", Assert.IsType<TextContent>(message.Contents[1]).Text); 275Assert.Equal("E", Assert.IsType<TextContent>(message.Contents[2]).Text); 276Assert.Equal("F", Assert.IsType<TextContent>(message.Contents[3]).Text); 277Assert.Equal("GH", Assert.IsType<TextContent>(message.Contents[4]).Text); 278Assert.Equal("I", Assert.IsType<TextContent>(message.Contents[5]).Text); 279Assert.Equal("J", Assert.IsType<TextContent>(message.Contents[6]).Text); 280Assert.Equal("K", Assert.IsType<TextContent>(message.Contents[7]).Text); 281Assert.Equal("L", Assert.IsType<TextContent>(message.Contents[8]).Text); 282Assert.Equal("MN", Assert.IsType<TextContent>(message.Contents[9]).Text); 283Assert.Equal("O", Assert.IsType<TextContent>(message.Contents[10]).Text); 284Assert.Equal("P", Assert.IsType<TextContent>(message.Contents[11]).Text); 304Assert.Equal("Hello, world!", Assert.IsType<TextContent>(Assert.Single(Assert.Single(response.Messages).Contents)).Text);
ChatCompletion\ChatResponseUpdateTests.cs (7)
101TextContent textContent = Assert.IsType<TextContent>(update.Contents[3]); 106((TextContent)update.Contents[3]).Text = "text-3"; 142Assert.IsType<TextContent>(result.Contents[0]); 143Assert.Equal("text-1", ((TextContent)result.Contents[0]).Text); 154Assert.IsType<TextContent>(result.Contents[4]); 155Assert.Equal("text-2", ((TextContent)result.Contents[4]).Text);
Contents\TextContentTests.cs (2)
16TextContent c = new(text); 25TextContent c = new(null);
SpeechToText\SpeechToTextResponseTests.cs (7)
52TextContent tc = Assert.IsType<TextContent>(response.Contents[0]); 92TextContent tc = Assert.IsType<TextContent>(response.Contents[i]); 173Assert.Equal($"Text{i + 1}", ((TextContent)result.Contents[i]).Text); 236Assert.Equal("Hello, ", Assert.IsType<TextContent>(update.Contents[0]).Text); 238Assert.Equal("world!", Assert.IsType<TextContent>(update.Contents[2]).Text);
SpeechToText\SpeechToTextResponseUpdateExtensionsTests.cs (3)
126TextContent[] contents = response.Contents.OfType<TextContent>().ToArray(); 153Assert.Equal("Hello, world!", Assert.IsType<TextContent>(Assert.Single(response.Contents)).Text);
SpeechToText\SpeechToTextResponseUpdateTests.cs (2)
72TextContent textContent = Assert.IsType<TextContent>(update.Contents[3]);
Utilities\AIJsonUtilitiesTests.cs (1)
1014Assert.Throws<ArgumentException>(() => options.AddAIContentType<TextContent>("discriminator"));
Microsoft.Extensions.AI.AzureAIInference (3)
AzureAIInferenceChatClient.cs (3)
473if (input.Contents.All(c => c is TextContent)) 490ChatRequestAssistantMessage message = new(string.Concat(input.Contents.Where(c => c is TextContent))); 519case TextContent textContent:
Microsoft.Extensions.AI.Evaluation (11)
ChatMessageExtensions.cs (6)
101/// <see cref="TextContent"/>s. If the <paramref name="message"/> does not contain any <see cref="TextContent"/>s 116if (!message.Contents.OfType<TextContent>().Any()) 140/// <see cref="TextContent"/>s. Any <paramref name="messages"/> that contain no <see cref="TextContent"/>s will be 142/// <see cref="TextContent"/>s then this function will return an empty string.
ChatResponseExtensions.cs (3)
22/// <see cref="TextContent"/>s. Any <see cref="ChatResponse.Messages"/> that contain no <see cref="TextContent"/>s 24/// <see cref="TextContent"/>s then this function will return an empty string.
EvaluationContext.cs (2)
66/// <see cref="TextContent"/> objects for text, <see cref="DataContent"/> or <see cref="UriContent"/> objects for 72/// <see cref="TextContent"/> object that includes the contained text.
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (8)
ScenarioRunResultTests.cs (8)
23var content1 = new TextContent("content1"); 24var content2 = new TextContent("content2"); 25var content3 = new TextContent("content3"); 114var content1 = new TextContent("content1"); 115var content2 = new TextContent("content2"); 116var content3 = new TextContent("content3"); 365if (x is TextContent xText && y is TextContent yText)
Microsoft.Extensions.AI.Evaluation.Safety (6)
AIContentExtensions.cs (1)
11=> content is TextContent || content is UsageContent;
ContentSafetyEvaluator.cs (2)
121contents.OfType<TextContent>() is IEnumerable<TextContent> textContents && textContents.Any() &&
ContentSafetyServicePayloadUtilities.cs (3)
324if (content is TextContent textContent) 519$"The current evaluation being performed by {evaluatorName} only supports content of type '{nameof(TextContent)}', '{nameof(UriContent)}' and '{nameof(DataContent)}'. " + 528$"The current evaluation being performed by {evaluatorName} only supports content of type '{nameof(TextContent)}'. " +
Microsoft.Extensions.AI.Integration.Tests (5)
ChatClientIntegrationTests.cs (4)
170var singleTextContent = (TextContent)history[1].Contents.Single(); 667((TextContent)message.Contents[0]).Text += "!"; 701((TextContent)message.Contents[0]).Text += "!";
ReducingChatClientTests.cs (1)
160if (content is TextContent text)
Microsoft.Extensions.AI.OpenAI (10)
OpenAIAssistantsChatClient.cs (4)
243(((TextContent)textUpdate.Contents[0]).Annotations ??= []).Add(new CitationAnnotation 432foreach (var textContent in chatMessage.Contents.OfType<TextContent>()) 448case TextContent text:
OpenAIChatClient.cs (3)
262case TextContent textContent: 496TextContent? annotationContent = returnMessage.Contents.OfType<TextContent>().FirstOrDefault();
OpenAIResponsesChatClient.cs (3)
563case TextContent textContent: 626TextContent text = new(part.Text) 681case TextContent textContent:
Microsoft.Extensions.AI.OpenAI.Tests (8)
OpenAIChatClientTests.cs (2)
1235TextContent fcc = Assert.IsType<TextContent>(response.Messages.Single().Contents[0]);
OpenAIConversionTests.cs (4)
232Assert.Equal("Hello, world!", Assert.IsType<TextContent>(message.Contents[0]).Text); 263Assert.Equal("Hello, world!", Assert.IsType<TextContent>(message.Contents[0]).Text); 376var textContent = message.Contents.OfType<TextContent>().FirstOrDefault();
OpenAIResponseClientIntegrationTests.cs (2)
34TextContent tc = m.Contents.OfType<TextContent>().First();
Microsoft.Extensions.AI.Tests (8)
ChatCompletion\DistributedCachingChatClientTest.cs (4)
346c => Assert.Equal("This becomes one chunk", Assert.IsType<TextContent>(c).Text), 348c => Assert.Equal("... and this becomes another one.", Assert.IsType<TextContent>(c).Text)); 424var content = Assert.IsType<TextContent>(Assert.Single(item.Contents));
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
773m => Assert.Equal("OK bye", Assert.IsType<TextContent>(Assert.Single(m.Contents)).Text)); 813Assert.IsType<TextContent>(Assert.Single(response.Messages[4].Contents));
ChatCompletion\UseDelegateChatClientTests.cs (2)
103cc.Messages.SelectMany(c => c.Contents).OfType<TextContent>().Last().Text += " world"; 206cc.Messages.SelectMany(c => c.Contents).OfType<TextContent>().Last().Text += " world (non-streaming)";