39 instantiations of TextContent
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatMessage.cs (1)
87Contents.Add(new TextContent(value));
ChatCompletion\StreamingChatCompletionUpdate.cs (1)
77Contents.Add(new TextContent(value));
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (1)
234contents[start] = new TextContent(coalescedText.ToString())
Microsoft.Extensions.AI.Abstractions.Tests (15)
ChatCompletion\ChatCompletionTests.cs (2)
241new TextContent("Hello, "), 243new TextContent("world!"),
ChatCompletion\ChatMessageTests.cs (5)
72content.Add(new TextContent($"text-{i}")); 130new TextContent("text-1"), 131new TextContent("text-2"), 264new TextContent("content-1") 276new TextContent("content-4")
ChatCompletion\StreamingChatCompletionUpdateTests.cs (6)
44update.Contents.Add(new TextContent("text")); 48IList<AIContent> newList = [new TextContent("text")]; 97new TextContent("text-1"), 98new TextContent("text-2"), 171new TextContent("text-1"), 175new TextContent("text-2"),
Contents\TextContentTests.cs (2)
16TextContent c = new(text); 25TextContent c = new(null);
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
183completionUpdate.Contents.Add(new TextContent(update));
Microsoft.Extensions.AI.AzureAIInference.Tests (3)
AzureAIInferenceChatClientTests.cs (3)
151[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())] : 589new TextContent("Describe this picture."),
Microsoft.Extensions.AI.Integration.Tests (3)
ChatClientIntegrationTests.cs (1)
148new TextContent("What does this logo say?"),
PromptBasedFunctionCallingChatClient.cs (2)
67message.Contents[itemIndex] = new TextContent( 74message.Contents[itemIndex] = new TextContent(
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
265contents.Insert(0, new TextContent(message.Content));
Microsoft.Extensions.AI.OpenAI (2)
OpenAIModelMapper.ChatCompletion.cs (1)
574aiContent = 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.")]), 1019new TextContent("hi, how are you?"),
OpenAISerializationTests.cs (2)
473new TextContent("Hello! How can I assist you today?"), 594List<AIContent> contents = [new TextContent($"Streaming update {i}")];
Microsoft.Extensions.AI.Tests (6)
ChatCompletion\FunctionInvokingChatClientTests.cs (6)
278new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new FunctionCallContent("callId1", "Func1"), new TextContent("stuff")]), 282new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } }), new TextContent("more")]), 294new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new TextContent("stuff")]), 541new StreamingChatCompletionUpdate { Contents = [new TextContent("OK bye")] });
80 references to TextContent
Microsoft.Extensions.AI (2)
ChatCompletion\ChatCompletion{T}.cs (1)
121return (content as TextContent)?.Text;
ChatCompletion\OpenTelemetryChatClient.cs (1)
537string content = string.Concat(message.Contents.OfType<TextContent>());
Microsoft.Extensions.AI.Abstractions (19)
ChatCompletion\ChatMessage.cs (5)
69/// Gets or sets the text of the first <see cref="TextContent"/> instance in <see cref="Contents" />. 72/// If there is no <see cref="TextContent"/> instance in <see cref="Contents" />, then the getter returns <see langword="null" />, 73/// and the setter adds a new <see cref="TextContent"/> instance with the provided value. 78get => Contents.FindFirst<TextContent>()?.Text; 81if (Contents.FindFirst<TextContent>() is { } textContent)
ChatCompletion\StreamingChatCompletionUpdate.cs (5)
59/// Gets or sets the text of the first <see cref="TextContent"/> instance in <see cref="Contents" />. 62/// If there is no <see cref="TextContent"/> instance in <see cref="Contents" />, then the getter returns <see langword="null" />, 63/// and the setter will add new <see cref="TextContent"/> instance with the provided value. 68get => Contents.FindFirst<TextContent>()?.Text; 71if (Contents.FindFirst<TextContent>() is { } textContent)
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (4)
199/// <summary>Coalesces sequential <see cref="TextContent"/> content elements.</summary> 209if (contents[start] is not TextContent firstText) 215if (contents[start + 1] is not TextContent secondText) 227for (; i < contents.Count && contents[i] is TextContent next; i++)
Contents\AIContent.cs (1)
13[JsonDerivedType(typeof(TextContent), typeDiscriminator: "text")]
Contents\AIContentExtensions.cs (3)
33/// <summary>Concatenates the text of all <see cref="TextContent"/> instances in the list.</summary> 43return contents[0] is TextContent tc ? tc.Text : string.Empty; 50if (contents[i] is TextContent text)
Contents\TextContent.cs (1)
16/// Initializes a new instance of the <see cref="TextContent"/> class.
Microsoft.Extensions.AI.Abstractions.Tests (27)
ChatCompletion\ChatCompletionTests.cs (2)
277Assert.Equal("Hello, ", Assert.IsType<TextContent>(update0.Contents[0]).Text); 279Assert.Equal("world!", Assert.IsType<TextContent>(update0.Contents[2]).Text);
ChatCompletion\ChatMessageTests.cs (11)
47TextContent tc = Assert.IsType<TextContent>(message.Contents[0]); 90TextContent tc = Assert.IsType<TextContent>(message.Contents[i]); 135TextContent textContent = Assert.IsType<TextContent>(message.Contents[3]); 157TextContent textContent = Assert.IsType<TextContent>(message.Contents[0]); 304var textContent = deserializedMessage.Contents[0] as TextContent; 327textContent = deserializedMessage.Contents[3] as TextContent;
ChatCompletion\StreamingChatCompletionUpdateExtensionsTests.cs (3)
187TextContent[] contents = message.Contents.OfType<TextContent>().ToArray(); 212Assert.Equal("Hello, world!", Assert.IsType<TextContent>(Assert.Single(completion.Message.Contents)).Text);
ChatCompletion\StreamingChatCompletionUpdateTests.cs (8)
103TextContent textContent = Assert.IsType<TextContent>(update.Contents[3]); 128TextContent textContent = Assert.IsType<TextContent>(update.Contents[0]); 192Assert.IsType<TextContent>(result.Contents[0]); 193Assert.Equal("text-1", ((TextContent)result.Contents[0]).Text); 204Assert.IsType<TextContent>(result.Contents[4]); 205Assert.Equal("text-2", ((TextContent)result.Contents[4]).Text);
Contents\TextContentTests.cs (2)
16TextContent c = new(text); 25TextContent c = new(null);
Utilities\AIJsonUtilitiesTests.cs (1)
352Assert.Throws<ArgumentException>(() => options.AddAIContentType<TextContent>("discriminator"));
Microsoft.Extensions.AI.AzureAIInference (3)
AzureAIInferenceChatClient.cs (3)
429yield return input.Contents.All(c => c is TextContent) ? 437ChatRequestAssistantMessage message = new(string.Concat(input.Contents.Where(c => c is TextContent))); 466case TextContent textContent:
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
425case TextContent textContent:
Microsoft.Extensions.AI.Ollama.Tests (1)
OllamaChatClientTests.cs (1)
199Assert.IsType<TextContent>(updates[updates.Count - 1].Contents[0]);
Microsoft.Extensions.AI.OpenAI (4)
OpenAIAssistantClient.cs (3)
273foreach (var textContent in chatMessage.Contents.OfType<TextContent>()) 285case 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 (3)
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
555m => Assert.Equal("Hello", Assert.IsType<TextContent>(Assert.Single(m.Contents)).Text), 565var singleUpdateContent = Assert.IsType<TextContent>(Assert.Single(allUpdateContents));