40 instantiations of TextContent
Microsoft.Extensions.AI.Abstractions (2)
ChatCompletion\ChatResponseExtensions.cs (1)
291contents[start] = new TextContent(coalescedText.ToString())
ChatCompletion\ChatResponseUpdate.cs (1)
51: this(role, content is null ? null : [new TextContent(content)])
Microsoft.Extensions.AI.Abstractions.Tests (13)
ChatCompletion\ChatMessageTests.cs (5)
89content.Add(new TextContent($"text-{i}")); 147new TextContent("text-1"), 148new TextContent("text-2"), 239new TextContent("content-1") 251new TextContent("content-4")
ChatCompletion\ChatResponseUpdateTests.cs (6)
43update.Contents.Add(new TextContent("text")); 47IList<AIContent> newList = [new TextContent("text")]; 90new TextContent("text-1"), 91new TextContent("text-2"), 116new TextContent("text-1"), 120new TextContent("text-2"),
Contents\TextContentTests.cs (2)
16TextContent c = new(text); 25TextContent c = new(null);
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
178responseUpdate.Contents.Add(new TextContent(update));
Microsoft.Extensions.AI.AzureAIInference.Tests (3)
AzureAIInferenceChatClientTests.cs (3)
156[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] : 228[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] : 617new TextContent("Describe this picture."),
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (1)
SerializationChainingTests.cs (1)
34new TextContent("A user message"),
Microsoft.Extensions.AI.Integration.Tests (3)
ChatClientIntegrationTests.cs (1)
177new TextContent("What does this logo say?"),
PromptBasedFunctionCallingChatClient.cs (2)
73message.Contents[itemIndex] = new TextContent( 80message.Contents[itemIndex] = new TextContent(
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
271contents.Insert(0, new TextContent(message.Content));
Microsoft.Extensions.AI.OpenAI (2)
OpenAIModelMapper.ChatCompletion.cs (1)
565aiContent = new TextContent(contentPart.Text);
OpenAIModelMapper.ChatMessage.cs (1)
204contents.Add(new TextContent(openAiContentPart.Text));
Microsoft.Extensions.AI.OpenAI.Tests (5)
OpenAIChatClientTests.cs (3)
550new(ChatRole.System, [new TextContent("You are a really nice friend."), new TextContent("Really nice.")]), 1018new TextContent("hi, how are you?"),
OpenAISerializationTests.cs (2)
469new TextContent("Hello! How can I assist you today?"), 568List<AIContent> contents = [new TextContent($"Streaming update {i}")];
Microsoft.Extensions.AI.Tests (9)
ChatCompletion\DistributedCachingChatClientTest.cs (5)
338new() { Role = ChatRole.Assistant, Contents = [new TextContent("Hello")] }, 339new() { Role = ChatRole.Assistant, Contents = [new TextContent(" world, ")] }, 345new TextContent("how ") 356new TextContent("are you?") 666new ChatMessage(ChatRole.Assistant, [new TextContent("Hey")])));
ChatCompletion\FunctionInvokingChatClientTests.cs (4)
219new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new FunctionCallContent("callId1", "Func1"), new TextContent("stuff")]), 223new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } }), new TextContent("more")]), 415updates = [new() { Contents = [new TextContent("OK bye")] }];
88 references to TextContent
Microsoft.Extensions.AI (1)
ChatCompletion\OpenTelemetryChatClient.cs (1)
535string content = string.Concat(contents.OfType<TextContent>());
Microsoft.Extensions.AI.Abstractions (20)
ChatCompletion\ChatMessage.cs (1)
71/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
ChatCompletion\ChatResponseExtensions.cs (12)
53/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 79/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 102/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 130/// <see cref="TextContent"/> instances in a row may be combined into a single <see cref="TextContent"/>. 256/// <summary>Coalesces sequential <see cref="TextContent"/> content elements.</summary> 266if (contents[start] is not TextContent firstText) 272if (contents[start + 1] is not TextContent secondText) 284for (; i < contents.Count && contents[i] is TextContent next; i++)
ChatCompletion\ChatResponseUpdate.cs (1)
76/// This property concatenates the text of all <see cref="TextContent"/> objects in <see cref="Contents"/>.
Contents\AIContent.cs (1)
13[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; 48if (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.
Microsoft.Extensions.AI.Abstractions.Tests (24)
ChatCompletion\ChatMessageTests.cs (11)
48TextContent tc = Assert.IsType<TextContent>(message.Contents[0]); 107TextContent tc = Assert.IsType<TextContent>(message.Contents[i]); 152TextContent textContent = Assert.IsType<TextContent>(message.Contents[3]); 157((TextContent)message.Contents[3]).Text = "text-3"; 265((TextContent)chatMessage.Contents[0]).Text = "content-1-override"; // Override the content of the first text content item that has the "content-1" content 280var textContent = deserializedMessage.Contents[0] as TextContent; 303textContent = deserializedMessage.Contents[3] as TextContent;
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (3)
139TextContent[] contents = message.Contents.OfType<TextContent>().ToArray(); 164Assert.Equal("Hello, world!", Assert.IsType<TextContent>(Assert.Single(Assert.Single(response.Messages).Contents)).Text);
ChatCompletion\ChatResponseUpdateTests.cs (7)
96TextContent textContent = Assert.IsType<TextContent>(update.Contents[3]); 101((TextContent)update.Contents[3]).Text = "text-3"; 136Assert.IsType<TextContent>(result.Contents[0]); 137Assert.Equal("text-1", ((TextContent)result.Contents[0]).Text); 148Assert.IsType<TextContent>(result.Contents[4]); 149Assert.Equal("text-2", ((TextContent)result.Contents[4]).Text);
Contents\TextContentTests.cs (2)
16TextContent c = new(text); 25TextContent c = new(null);
Utilities\AIJsonUtilitiesTests.cs (1)
400Assert.Throws<ArgumentException>(() => options.AddAIContentType<TextContent>("discriminator"));
Microsoft.Extensions.AI.AzureAIInference (3)
AzureAIInferenceChatClient.cs (3)
454if (input.Contents.All(c => c is TextContent)) 471ChatRequestAssistantMessage message = new(string.Concat(input.Contents.Where(c => c is TextContent))); 500case TextContent textContent:
Microsoft.Extensions.AI.Integration.Tests (6)
ChatClientIntegrationTests.cs (4)
161var singleTextContent = (TextContent)history[1].Contents.Single(); 370((TextContent)message.Contents[0]).Text += "!"; 404((TextContent)message.Contents[0]).Text += "!";
PromptBasedFunctionCallingChatClient.cs (1)
178existingToolPrompt.Contents.OfType<TextContent>().First().Text = $$"""
ReducingChatClientTests.cs (1)
160if (content is TextContent text)
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
431case TextContent textContent:
Microsoft.Extensions.AI.Ollama.Tests (1)
OllamaChatClientTests.cs (1)
200Assert.IsType<TextContent>(updates[updates.Count - 1].Contents[0]);
Microsoft.Extensions.AI.OpenAI (4)
OpenAIAssistantClient.cs (3)
286foreach (var textContent in chatMessage.Contents.OfType<TextContent>()) 298case TextContent tc:
OpenAIModelMapper.ChatMessage.cs (1)
228case TextContent textContent:
Microsoft.Extensions.AI.OpenAI.Tests (20)
OpenAISerializationTests.cs (20)
50TextContent textContent = Assert.IsType<TextContent>(content); 83TextContent textContent = Assert.IsType<TextContent>(content); 115TextContent textContent = Assert.IsType<TextContent>(content); 190TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 202TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 214TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 226TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 287TextContent text = Assert.IsType<TextContent>(content); 295TextContent text = Assert.IsType<TextContent>(content); 308TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents));
Microsoft.Extensions.AI.Tests (8)
ChatCompletion\DistributedCachingChatClientTest.cs (4)
316c => Assert.Equal("This becomes one chunk", Assert.IsType<TextContent>(c).Text), 318c => Assert.Equal("... and this becomes another one.", Assert.IsType<TextContent>(c).Text)); 392var content = Assert.IsType<TextContent>(Assert.Single(item.Contents));
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
439m => Assert.Equal("OK bye", Assert.IsType<TextContent>(Assert.Single(m.Contents)).Text)); 479Assert.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)";