5 writes to Contents
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvokingChatClient.cs (1)
259response.Message.Contents = [.. response.Message.Contents, new UsageContent(usage)];
Microsoft.Extensions.AI.Abstractions (1)
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (1)
173entry.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;
114 references to Contents
Microsoft.Extensions.AI (11)
ChatCompletion\ChatCompletion{T}.cs (2)
120var content = choice?.Contents.Count == 1 ? choice.Contents[0] : null;
ChatCompletion\FunctionInvokingChatClient.cs (6)
225FunctionCallContent[] functionCallContents = response.Message.Contents.OfType<FunctionCallContent>().ToArray(); 241if (functionCallContents.Length == response.Message.Contents.Count) 259response.Message.Contents = [.. response.Message.Contents, new UsageContent(usage)]; 432for (int c = message.Contents.Count - 1; c >= 0; c--) 434if (contentToRemove.Contains(message.Contents[c])) 436message.Contents.RemoveAt(c);
ChatCompletion\OpenTelemetryChatClient.cs (3)
421foreach (FunctionResultContent frc in message.Contents.OfType<FunctionResultContent>()) 482var toolCalls = message.Contents.OfType<FunctionCallContent>().Select(fc => new ToolCall 505string 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); 161CoalesceTextContent((List<AIContent>)entry.Value.Contents); 168foreach (var content in entry.Value.Contents) 173entry.Value.Contents = entry.Value.Contents.ToList(); 174_ = 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 (4)
AzureAIInferenceChatClient.cs (4)
114message.Contents.Add(callContent); 421foreach (AIContent item in input.Contents) 444yield return new ChatRequestUserMessage(GetContentParts(input.Contents)); 452foreach (var content in input.Contents)
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
149Assert.Single(response.Message.Contents); 411Assert.Single(response.Message.Contents);
Microsoft.Extensions.AI.Integration.Tests (6)
ChatClientIntegrationTests.cs (1)
183UsageContent? intermediate = messages.SelectMany(m => m.Contents).OfType<UsageContent>().FirstOrDefault();
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)
354foreach (var item in content.Contents)
Microsoft.Extensions.AI.Ollama.Tests (1)
OllamaChatClientTests.cs (1)
121Assert.Single(response.Message.Contents);
Microsoft.Extensions.AI.OpenAI (6)
OpenAIChatClient.cs (6)
131returnMessage.Contents.Add(aiContent); 145returnMessage.Contents.Add(callContent); 586var parts = GetContentParts(input.Contents); 593foreach (AIContent item in input.Contents) 616AssistantChatMessage message = new(GetContentParts(input.Contents)) 621foreach (var content in input.Contents)
Microsoft.Extensions.AI.OpenAI.Tests (4)
OpenAIChatClientTests.cs (4)
192Assert.Single(response.Message.Contents); 465Assert.Single(response.Message.Contents); 558Assert.Single(response.Message.Contents); 909Assert.Single(response.Message.Contents);
Microsoft.Extensions.AI.Tests (14)
ChatCompletion\FunctionInvokingChatClientTests.cs (14)
242IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 310IEnumerable<AIContent> content = finalChat.SelectMany(m => m.Contents); 520return new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])); 541Assert.Equal(expectedMessage.Contents.Count, chatMessage.Contents.Count); 542for (int j = 0; j < expectedMessage.Contents.Count; j++) 544var expectedItem = expectedMessage.Contents[j]; 545var chatItem = chatMessage.Contents[j]; 587return YieldAsync(new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])).ToStreamingChatCompletionUpdates()); 608Assert.Equal(expectedMessage.Contents.Count, chatMessage.Contents.Count); 609for (int j = 0; j < expectedMessage.Contents.Count; j++) 611var expectedItem = expectedMessage.Contents[j]; 612var chatItem = chatMessage.Contents[j];