113 instantiations of ChatMessage
Aspire.Azure.AI.OpenAI.Tests (1)
Aspire.OpenAI.Tests (1)
Microsoft.Extensions.AI (4)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (3)
70CompleteAsync<T>(chatClient, [new ChatMessage(ChatRole.User, chatMessage)], options, useNativeJsonSchema, cancellationToken);
92CompleteAsync<T>(chatClient, [new ChatMessage(ChatRole.User, chatMessage)], serializerOptions, options, useNativeJsonSchema, cancellationToken);
174promptAugmentation = new ChatMessage(ChatRole.User, $$"""
Microsoft.Extensions.AI.Abstractions (3)
Microsoft.Extensions.AI.Abstractions.Tests (29)
ChatCompletion\ChatCompletionTests.cs (18)
23ChatMessage message = new();
35new ChatMessage(),
36new ChatMessage(),
37new ChatMessage(),
57ChatMessage message = new();
67ChatMessage first = new();
70new ChatMessage(),
120List<ChatMessage> newChoices = [new ChatMessage(), new ChatMessage()];
130new ChatMessage(ChatRole.Assistant, "Choice1"),
131new ChatMessage(ChatRole.Assistant, "Choice2"),
132new ChatMessage(ChatRole.Assistant, "Choice3"),
133new ChatMessage(ChatRole.Assistant, "Choice4"),
176new ChatMessage(ChatRole.Assistant, "This is a test." + Environment.NewLine + "It's multiple lines.")
187new ChatMessage(ChatRole.Assistant, "This is a test." + Environment.NewLine + "It's multiple lines."),
188new ChatMessage(ChatRole.Assistant, "So is" + Environment.NewLine + " this."),
189new ChatMessage(ChatRole.Assistant, "And this."),
208ChatCompletion completion = new(new ChatMessage(new ChatRole("customRole"), "Text"))
Microsoft.Extensions.AI.AzureAIInference (1)
Microsoft.Extensions.AI.Integration.Tests (9)
ReducingChatClientTests.cs (5)
47new ChatMessage(ChatRole.User, "Hi there! Can you tell me about golden retrievers?"),
48new ChatMessage(ChatRole.Assistant, "Of course! Golden retrievers are known for their friendly and tolerant attitudes. They're great family pets and are very intelligent and easy to train."),
49new ChatMessage(ChatRole.User, "What kind of exercise do they need?"),
50new ChatMessage(ChatRole.Assistant, "Golden retrievers are quite active and need regular exercise. Daily walks, playtime, and activities like fetching or swimming are great for them."),
51new ChatMessage(ChatRole.User, "Are they good with kids?"),
Microsoft.Extensions.AI.Ollama (1)
Microsoft.Extensions.AI.OpenAI (1)
Microsoft.Extensions.AI.Tests (51)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (13)
56var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
81var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult))]);
113var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, "This is not valid JSON")]);
119var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
132var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, "null")]);
138var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
157var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
193var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
227var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
248var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(payload))]);
255var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
301var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
329var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\FunctionInvokingChatClientTests.cs (28)
57new ChatMessage(ChatRole.User, "hello"),
64new ChatMessage(ChatRole.Assistant, "world"),
88new ChatMessage(ChatRole.User, "hello"),
111new ChatMessage(ChatRole.Assistant, "world"),
140new ChatMessage(ChatRole.User, "hello"),
151new ChatMessage(ChatRole.Assistant, "done"),
183new ChatMessage(ChatRole.User, "hello"),
194new ChatMessage(ChatRole.Assistant, "done"),
219new ChatMessage(ChatRole.User, "hello"),
226new ChatMessage(ChatRole.Assistant, "world"),
231new ChatMessage(ChatRole.User, "hello"),
232new ChatMessage(ChatRole.Assistant, "world")
271new ChatMessage(ChatRole.User, "hello"),
278new ChatMessage(ChatRole.Assistant, "world"),
286new ChatMessage(ChatRole.User, "hello"),
288new ChatMessage(ChatRole.Assistant, "more"),
289new ChatMessage(ChatRole.Assistant, "world"),
294new ChatMessage(ChatRole.User, "hello"),
301new ChatMessage(ChatRole.Assistant, "extrastuffmoreworld"),
304new ChatMessage(ChatRole.User, "hello"),
305new ChatMessage(ChatRole.Assistant, "extrastuffmoreworld"),
337new ChatMessage(ChatRole.User, "hello"),
340new ChatMessage(ChatRole.Assistant, "world"),
375List<ChatMessage> chat = [new ChatMessage(ChatRole.User, "hello")];
396new ChatMessage(ChatRole.User, "hello"),
399new ChatMessage(ChatRole.Assistant, "world"),
452new ChatMessage(ChatRole.User, "hello"),
455new ChatMessage(ChatRole.Assistant, "world"),
Microsoft.ML.GenAI.Core (1)
Microsoft.ML.GenAI.Core.Tests (3)
Microsoft.ML.GenAI.LLaMA.Tests (3)
Microsoft.ML.GenAI.Samples (5)
218 references to ChatMessage
Aspire.Azure.AI.OpenAI.Tests (1)
Aspire.OpenAI.Tests (1)
Microsoft.Extensions.AI (49)
ChatCompletion\AnonymousDelegatingChatClient.cs (9)
20private readonly Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? _completeFunc;
28private readonly Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? _completeStreamingFunc;
74Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? completeFunc,
75Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? completeStreamingFunc)
86IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
94async Task<ChatCompletion> CompleteViaSharedAsync(IList<ChatMessage> chatMessages, ChatOptions? options, CancellationToken cancellationToken)
124IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
209IList<ChatMessage> chatMessages,
211Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task> nextAsync,
ChatCompletion\CachingChatClient.cs (6)
48public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
68IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
135/// This is used when there is a call to <see cref="IChatClient.CompleteAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>.
144/// This is used when there is a call to <see cref="IChatClient.CompleteStreamingAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>.
153/// This is used when there is a call to <see cref="IChatClient.CompleteAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>.
163/// This is used when there is a call to <see cref="IChatClient.CompleteStreamingAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>.
ChatCompletion\FunctionInvokingChatClient.cs (18)
190public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
195HashSet<ChatMessage>? messagesToRemove = null;
299IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
303HashSet<ChatMessage>? messagesToRemove = null;
363ChatMessage functionCallMessage = new(ChatRole.Assistant, [.. functionCallContents]);
416HashSet<ChatMessage>? messagesToRemove,
418IList<ChatMessage> messages)
428ChatMessage message = messages[m];
458private async Task<(ContinueMode Mode, IList<ChatMessage> MessagesAdded)> ProcessFunctionCallsAsync(
459IList<ChatMessage> chatMessages, ChatOptions options, IReadOnlyList<FunctionCallContent> functionCallContents, int iteration, CancellationToken cancellationToken)
471IList<ChatMessage> added = AddResponseMessages(chatMessages, [result]);
496IList<ChatMessage> added = AddResponseMessages(chatMessages, results);
519IList<ChatMessage> chatMessages, ChatOptions options, FunctionCallContent functionCallContent,
575protected virtual IList<ChatMessage> AddResponseMessages(IList<ChatMessage> chat, ReadOnlySpan<FunctionInvocationResult> results)
585ChatMessage message = new(ChatRole.Tool, contents);
722IList<ChatMessage> chatMessages,
738public IList<ChatMessage> ChatMessages { get; set; }
Microsoft.Extensions.AI.Abstractions (26)
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (9)
29/// the manufactured <see cref="ChatMessage"/> instances. When <see langword="false"/>, the original content items are used.
39Dictionary<int, ChatMessage> messages = [];
56/// the manufactured <see cref="ChatMessage"/> instances. When <see langword="false"/>, the original content items are used.
72Dictionary<int, ChatMessage> messages = [];
87/// <param name="messages">The dictionary mapping <see cref="StreamingChatCompletionUpdate.ChoiceIndex"/> to the <see cref="ChatMessage"/> being built for that choice.</param>
89private static void ProcessUpdate(StreamingChatCompletionUpdate update, Dictionary<int, ChatMessage> messages, ChatCompletion completion)
97ChatMessage message = CollectionsMarshal.GetValueRefOrAddDefault(messages, update.ChoiceIndex, out _) ??=
135private static void AddMessagesToCompletion(Dictionary<int, ChatMessage> messages, ChatCompletion completion, bool coalesceContent)
152static void AddMessage(ChatCompletion completion, bool coalesceContent, KeyValuePair<int, ChatMessage> entry)
Microsoft.Extensions.AI.Abstractions.Tests (29)
TestChatClient.cs (4)
17public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; }
19public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? CompleteStreamingAsyncCallback { get; set; }
23public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
26public IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.AzureAIInference (7)
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
Microsoft.Extensions.AI.Integration.Tests (15)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
17public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; }
19public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? CompleteStreamingAsyncCallback { get; set; }
23public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
26public IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.Ollama (5)
Microsoft.Extensions.AI.Ollama.Tests (2)
Microsoft.Extensions.AI.OpenAI (5)
Microsoft.Extensions.AI.OpenAI.Tests (4)
Microsoft.Extensions.AI.Tests (50)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
17public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; }
19public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? CompleteStreamingAsyncCallback { get; set; }
23public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
26public IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.ML.GenAI.Core (7)
Microsoft.ML.GenAI.Core.Tests (3)
Microsoft.ML.GenAI.LLaMA (4)
Microsoft.ML.GenAI.Phi (4)
Microsoft.ML.GenAI.Samples (4)