10 writes to Contents
Microsoft.Extensions.AI.Abstractions (1)
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (1)
189entry.Value.Contents = entry.Value.Contents.ToList();
Microsoft.Extensions.AI.Abstractions.Tests (3)
ChatCompletion\ChatMessageTests.cs (3)
203message.Contents = contents; 207message.Contents = contents; 210message.Contents = null;
Microsoft.Extensions.AI.OpenAI (4)
OpenAIModelMapper.ChatMessage.cs (4)
46Contents = FromOpenAIChatContent(systemMessage.Content), 55Contents = FromOpenAIChatContent(userMessage.Content), 80Contents = new AIContent[] { new FunctionResultContent(toolMessage.ToolCallId, functionName, result) }, 90Contents = FromOpenAIChatContent(assistantMessage.Content),
Microsoft.Extensions.AI.OpenAI.Tests (2)
OpenAISerializationTests.cs (2)
439Contents = [ 682Contents = [fcc],
131 references to Contents
Microsoft.Extensions.AI (10)
ChatCompletion\ChatCompletion{T}.cs (2)
120var content = choice?.Contents.Count == 1 ? choice.Contents[0] : null;
ChatCompletion\FunctionInvokingChatClient.cs (5)
238FunctionCallContent[] functionCallContents = response.Message.Contents.OfType<FunctionCallContent>().ToArray(); 254if (functionCallContents.Length == response.Message.Contents.Count) 448for (int c = message.Contents.Count - 1; c >= 0; c--) 450if (contentToRemove.Contains(message.Contents[c])) 452message.Contents.RemoveAt(c);
ChatCompletion\OpenTelemetryChatClient.cs (3)
451foreach (FunctionResultContent frc in message.Contents.OfType<FunctionResultContent>()) 512var toolCalls = message.Contents.OfType<FunctionCallContent>().Select(fc => new ToolCall 535string content = string.Concat(message.Contents.OfType<TextContent>());
Microsoft.Extensions.AI.Abstractions (12)
ChatCompletion\ChatCompletion.cs (1)
140Contents = choice.Contents,
ChatCompletion\ChatMessage.cs (6)
53/// Gets or sets the text of the first <see cref="TextContent"/> instance in <see cref="Contents" />. 56/// If there is no <see cref="TextContent"/> instance in <see cref="Contents" />, then the getter returns <see langword="null" />, 62get => Contents.FindFirst<TextContent>()?.Text; 65if (Contents.FindFirst<TextContent>() is { } textContent) 71Contents.Add(new TextContent(value)); 97public override string ToString() => Contents.ConcatText();
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (5)
106((List<AIContent>)message.Contents).AddRange(update.Contents); 177CoalesceTextContent((List<AIContent>)entry.Value.Contents); 184foreach (var content in entry.Value.Contents) 189entry.Value.Contents = entry.Value.Contents.ToList(); 190_ = entry.Value.Contents.Remove(c);
Microsoft.Extensions.AI.Abstractions.Tests (53)
ChatCompletion\ChatMessageTests.cs (43)
19Assert.Empty(message.Contents); 22Assert.NotNull(message.Contents); 23Assert.Same(message.Contents, message.Contents); 24Assert.Empty(message.Contents); 39Assert.Same(message.Contents, message.Contents); 42Assert.Empty(message.Contents); 46Assert.Single(message.Contents); 47TextContent tc = Assert.IsType<TextContent>(message.Contents[0]); 79Assert.Same(message.Contents, message.Contents); 82Assert.Empty(message.Contents); 87Assert.Equal(messageCount, message.Contents.Count); 90TextContent tc = Assert.IsType<TextContent>(message.Contents[i]); 135TextContent textContent = Assert.IsType<TextContent>(message.Contents[3]); 143Assert.Same(textContent, message.Contents[3]); 151Assert.Empty(message.Contents); 156Assert.Single(message.Contents); 157TextContent textContent = Assert.IsType<TextContent>(message.Contents[0]); 170Assert.Equal(3, message.Contents.Count); 174Assert.Equal(4, message.Contents.Count); 178Assert.Equal(4, message.Contents.Count); 180message.Contents.RemoveAt(3); 181Assert.Equal(3, message.Contents.Count); 185Assert.Equal(4, message.Contents.Count); 193Assert.IsType<List<AIContent>>(new ChatMessage().Contents); 200Assert.Empty(message.Contents); 205Assert.Same(contents, message.Contents); 208Assert.Same(contents, message.Contents); 211Assert.NotNull(message.Contents); 212Assert.NotSame(contents, message.Contents); 213Assert.Empty(message.Contents); 309Assert.NotNull(deserializedMessage.Contents); 310Assert.Equal(items.Count, deserializedMessage.Contents.Count); 312var textContent = deserializedMessage.Contents[0] as TextContent; 319var imageContent = deserializedMessage.Contents[1] as ImageContent; 327var dataContent = deserializedMessage.Contents[2] as DataContent; 335var audioContent = deserializedMessage.Contents[3] as AudioContent; 343imageContent = deserializedMessage.Contents[4] as ImageContent; 351textContent = deserializedMessage.Contents[5] as TextContent; 358var functionCallContent = deserializedMessage.Contents[6] as FunctionCallContent; 366var functionResultContent = deserializedMessage.Contents[7] as FunctionResultContent;
ChatCompletion\StreamingChatCompletionUpdateExtensionsTests.cs (10)
92Assert.Same(updates[7].Contents[0], Assert.Single(message.Contents)); 102Assert.Equal("Hello", completion.Choices[0].Contents[0].ToString()); 103Assert.Equal(", ", completion.Choices[0].Contents[1].ToString()); 104Assert.Equal("world!", completion.Choices[0].Contents[2].ToString()); 106Assert.Equal("Hey", completion.Choices[1].Contents[0].ToString()); 107Assert.Equal(", ", completion.Choices[1].Contents[1].ToString()); 108Assert.Equal("you!", completion.Choices[1].Contents[2].ToString()); 182Assert.Equal(expected.Count + (gapLength * ((numSequences - 1) + (gapBeginningEnd ? 2 : 0))), message.Contents.Count); 184TextContent[] contents = message.Contents.OfType<TextContent>().ToArray(); 209Assert.Equal("Hello, world!", Assert.IsType<TextContent>(Assert.Single(completion.Message.Contents)).Text);
Microsoft.Extensions.AI.AzureAIInference (7)
AzureAIInferenceChatClient.cs (7)
116message.Contents.Add(callContent); 423foreach (AIContent item in input.Contents) 446yield return input.Contents.All(c => c is TextContent) ? 447new ChatRequestUserMessage(string.Concat(input.Contents)) : 448new ChatRequestUserMessage(GetContentParts(input.Contents)); 454ChatRequestAssistantMessage message = new(string.Concat(input.Contents.Where(c => c is TextContent))); 456foreach (var content in input.Contents)
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
162Assert.Single(response.Message.Contents); 660Assert.Single(response.Message.Contents);
Microsoft.Extensions.AI.Integration.Tests (5)
PromptBasedFunctionCallingChatClient.cs (5)
61for (var itemIndex = 0; itemIndex < message.Contents.Count; itemIndex++) 63if (message.Contents[itemIndex] is FunctionResultContent frc) 67message.Contents[itemIndex] = new TextContent( 70else if (message.Contents[itemIndex] is FunctionCallContent fcc) 74message.Contents[itemIndex] = new TextContent(
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
375foreach (var item in content.Contents)
Microsoft.Extensions.AI.Ollama.Tests (1)
OllamaChatClientTests.cs (1)
121Assert.Single(response.Message.Contents);
Microsoft.Extensions.AI.OpenAI (9)
OpenAIModelMapper.ChatCompletion.cs (4)
36foreach (AIContent content in chatCompletion.Message.Contents) 62content: new(ToOpenAIChatContent(chatCompletion.Message.Contents)), 87returnMessage.Contents.Add(aiContent); 101returnMessage.Contents.Add(callContent);
OpenAIModelMapper.ChatMessage.cs (5)
100message.Contents.Add(callContent); 127var parts = ToOpenAIChatContent(input.Contents); 134foreach (AIContent item in input.Contents) 157AssistantChatMessage message = new(ToOpenAIChatContent(input.Contents)) 162foreach (var content in input.Contents)
Microsoft.Extensions.AI.OpenAI.Tests (14)
OpenAIChatClientTests.cs (4)
192Assert.Single(response.Message.Contents); 539Assert.Single(response.Message.Contents); 638Assert.Single(response.Message.Contents); 1009Assert.Single(response.Message.Contents);
OpenAISerializationTests.cs (10)
48AIContent content = Assert.Single(message.Contents); 81AIContent content = Assert.Single(message.Contents); 157TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 169TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 181TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 193TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 251Assert.Collection(msg.Contents, 275TextContent text = Assert.IsType<TextContent>(Assert.Single(msg.Contents)); 411FunctionCallContent text = Assert.IsType<FunctionCallContent>(Assert.Single(msg.Contents)); 423FunctionResultContent frc = Assert.IsType<FunctionResultContent>(Assert.Single(msg.Contents));
Microsoft.Extensions.AI.Tests (17)
ChatCompletion\FunctionInvokingChatClientTests.cs (17)
242IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 310IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 542m => Assert.Equal("Hello", Assert.IsType<TextContent>(Assert.Single(m.Contents)).Text), 543m => Assert.Collection(m.Contents, 546m => Assert.Collection(m.Contents, 582return new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])) { Usage = usage }; 603Assert.Equal(expectedMessage.Contents.Count, chatMessage.Contents.Count); 604for (int j = 0; j < expectedMessage.Contents.Count; j++) 606var expectedItem = expectedMessage.Contents[j]; 607var chatItem = chatMessage.Contents[j]; 672return YieldAsync(new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])).ToStreamingChatCompletionUpdates()); 693Assert.Equal(expectedMessage.Contents.Count, chatMessage.Contents.Count); 694for (int j = 0; j < expectedMessage.Contents.Count; j++) 696var expectedItem = expectedMessage.Contents[j]; 697var chatItem = chatMessage.Contents[j];