128 instantiations of ChatMessage
Aspire.Azure.AI.OpenAI.Tests (1)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (1)
221=> Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "Hello from middleware")));
Aspire.OpenAI.Tests (1)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (1)
222=> Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "Hello from middleware")));
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, $$"""
ChatCompletion\FunctionInvokingChatClient.cs (1)
601ChatMessage message = new(ChatRole.Tool, contents);
Microsoft.Extensions.AI.Abstractions (3)
ChatCompletion\ChatClientExtensions.cs (2)
45return client.CompleteAsync([new ChatMessage(ChatRole.User, chatMessage)], options, cancellationToken); 63return client.CompleteStreamingAsync([new ChatMessage(ChatRole.User, chatMessage)], options, cancellationToken);
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (1)
98new(default, new List<AIContent>());
Microsoft.Extensions.AI.Abstractions.Tests (29)
ChatCompletion\ChatClientExtensionsTests.cs (1)
51var expectedResponse = new ChatCompletion([new ChatMessage()]);
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"))
ChatCompletion\ChatMessageTests.cs (10)
17ChatMessage message = new(); 35ChatMessage message = new(ChatRole.Assistant, text); 60Assert.Throws<ArgumentNullException>("contents", () => new ChatMessage(ChatRole.User, (IList<AIContent>)null!)); 75ChatMessage message = new(ChatRole.System, content); 109ChatMessage message = new() 193Assert.IsType<List<AIContent>>(new ChatMessage().Contents); 199ChatMessage message = new(); 219ChatMessage message = new(); 240ChatMessage message = new(); 293var chatMessageJson = JsonSerializer.Serialize(new ChatMessage(ChatRole.User, contents: items)
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
96ChatMessage message = new()
Microsoft.Extensions.AI.AzureAIInference.Tests (4)
AzureAIInferenceChatClientTests.cs (4)
150[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] : 151[new ChatMessage(ChatRole.User, "hello")]; 217[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] : 218[new ChatMessage(ChatRole.User, "hello")];
Microsoft.Extensions.AI.Integration.Tests (9)
ChatClientIntegrationTests.cs (3)
318var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 335var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 361var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000");
PromptBasedFunctionCallingChatClient.cs (1)
157existingToolPrompt = new ChatMessage(ChatRole.System, (string?)null);
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)
OllamaChatClient.cs (1)
253return new ChatMessage(new(message.Role), contents);
Microsoft.Extensions.AI.OpenAI (5)
OpenAIModelMapper.ChatCompletion.cs (1)
76ChatMessage returnMessage = new()
OpenAIModelMapper.ChatMessage.cs (4)
42yield return new ChatMessage 51yield return new ChatMessage 77yield return new ChatMessage 86ChatMessage message = new()
Microsoft.Extensions.AI.OpenAI.Tests (6)
OpenAISerializationTests.cs (6)
436ChatMessage message = new() 533ChatMessage message1 = new() 539ChatMessage message2 = new() 638await Assert.ThrowsAsync<ArgumentNullException>(() => OpenAISerializationHelpers.SerializeAsync(null!, new(new ChatMessage()))); 658await Assert.ThrowsAsync<TaskCanceledException>(() => OpenAISerializationHelpers.SerializeAsync(stream, new(new ChatMessage()), cancellationToken: canceledToken)); 679ChatCompletion completion = new(new ChatMessage
Microsoft.Extensions.AI.Tests (52)
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") }; 195var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 229var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 250var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(payload))]); 257var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 303var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 331var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\DistributedCachingChatClientTest.cs (6)
86var result1 = await outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 91var result2 = await outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 98await outer.CompleteAsync([new ChatMessage(ChatRole.User, "some modified input")]); 123var result1 = outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 124var result2 = outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 135var result3 = outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]);
ChatCompletion\FunctionInvokingChatClientTests.cs (29)
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"), 514new(ChatRole.User, "Hello"),
ChatCompletion\OpenTelemetryChatClientTests.cs (1)
42return new ChatCompletion([new ChatMessage(ChatRole.Assistant, "The blue whale, I think.")])
ChatCompletion\UseDelegateChatClientTests.cs (3)
50return Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "hello"))); 99return Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "hello"))); 192return Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "non-streaming hello")));
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
48var chatMessage = new ChatMessage(ChatRole.Assistant, output);
Microsoft.ML.GenAI.Core.Tests (3)
CasualLMDatasetTest.cs (3)
86new ChatMessage(ChatRole.System, "You are a helpful contoso assistant"), 87new ChatMessage(ChatRole.User, "What is contoso"), 93new ChatMessage(ChatRole.Assistant, "Contoso is a company"),
Microsoft.ML.GenAI.LLaMA.Tests (3)
LLaMA3_1Tests.cs (3)
134new ChatMessage(ChatRole.System, "You are a helpful AI assistant."), 135new ChatMessage(ChatRole.User, "Hello?"), 136new ChatMessage(ChatRole.Assistant, "World!"),
Microsoft.ML.GenAI.Samples (5)
Llama\SFT_Llama_3_2_1B.cs (3)
107new ChatMessage(ChatRole.System, "You are a helpful contoso assistant"), 108new ChatMessage(ChatRole.User, data.input), 111var assistantMessage = new ChatMessage(ChatRole.Assistant, data.output);
MEAI\Llama3_1.cs (1)
47var chatMessage = new ChatMessage(ChatRole.User, task);
MEAI\Phi3.cs (1)
37var chatMessage = new ChatMessage(ChatRole.User, task);
230 references to ChatMessage
Aspire.Azure.AI.OpenAI.Tests (1)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (1)
220static Task<ChatCompletion> TestMiddleware(IList<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
Aspire.OpenAI.Tests (1)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (1)
221static Task<ChatCompletion> TestMiddleware(IList<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
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\ChatClientBuilder.cs (2)
132Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? completeFunc, 133Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? completeStreamingFunc)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (3)
46IList<ChatMessage> chatMessages, 113IList<ChatMessage> chatMessages, 153ChatMessage? promptAugmentation = null;
ChatCompletion\ChatCompletion{T}.cs (1)
119var choice = Choices.Count == 1 ? Choices[0] : null;
ChatCompletion\ConfigureOptionsChatClient.cs (2)
37public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 44IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
ChatCompletion\FunctionInvokingChatClient.cs (18)
190public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 199HashSet<ChatMessage>? messagesToRemove = null; 310IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 318HashSet<ChatMessage>? messagesToRemove = null; 379ChatMessage functionCallMessage = new(ChatRole.Assistant, [.. functionCallContents]); 432HashSet<ChatMessage>? messagesToRemove, 434IList<ChatMessage> messages) 444ChatMessage message = messages[m]; 474private async Task<(ContinueMode Mode, IList<ChatMessage> MessagesAdded)> ProcessFunctionCallsAsync( 475IList<ChatMessage> chatMessages, ChatOptions options, IReadOnlyList<FunctionCallContent> functionCallContents, int iteration, CancellationToken cancellationToken) 487IList<ChatMessage> added = AddResponseMessages(chatMessages, [result]); 512IList<ChatMessage> added = AddResponseMessages(chatMessages, results); 535IList<ChatMessage> chatMessages, ChatOptions options, FunctionCallContent functionCallContent, 591protected virtual IList<ChatMessage> AddResponseMessages(IList<ChatMessage> chat, ReadOnlySpan<FunctionInvocationResult> results) 601ChatMessage message = new(ChatRole.Tool, contents); 738IList<ChatMessage> chatMessages, 754public IList<ChatMessage> ChatMessages { get; set; }
ChatCompletion\LoggingChatClient.cs (2)
47IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 93IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
ChatCompletion\OpenTelemetryChatClient.cs (6)
122public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 153IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 435private void LogChatMessages(IEnumerable<ChatMessage> messages) 442foreach (ChatMessage message in messages) 510private AssistantEvent CreateAssistantEvent(ChatMessage message) 531private string? GetMessageContent(ChatMessage message)
Microsoft.Extensions.AI.Abstractions (26)
ChatCompletion\ChatCompletion.cs (7)
16private IList<ChatMessage> _choices; 21public ChatCompletion(IList<ChatMessage> choices) 28public ChatCompletion(ChatMessage message) 35public IList<ChatMessage> Choices 47public ChatMessage Message 54throw new InvalidOperationException($"The {nameof(ChatCompletion)} instance does not contain any {nameof(ChatMessage)} choices."); 133ChatMessage choice = Choices[choiceIndex];
ChatCompletion\ChatMessage.cs (4)
17/// <summary>Initializes a new instance of the <see cref="ChatMessage"/> class.</summary> 23/// <summary>Initializes a new instance of the <see cref="ChatMessage"/> class.</summary> 31/// <summary>Initializes a new instance of the <see cref="ChatMessage"/> class.</summary> 86/// If a <see cref="ChatMessage"/> is created to represent some underlying object from another object
ChatCompletion\DelegatingChatClient.cs (2)
54public virtual Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 60public virtual IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ChatCompletion\IChatClient.cs (2)
38IList<ChatMessage> chatMessages, 52IList<ChatMessage> chatMessages,
ChatCompletion\StreamingChatCompletionUpdate.cs (1)
16/// Conceptually, this combines the roles of <see cref="ChatCompletion"/> and <see cref="ChatMessage"/>
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) 168static void AddMessage(ChatCompletion completion, bool coalesceContent, KeyValuePair<int, ChatMessage> entry)
Utilities\AIJsonUtilities.Defaults.cs (1)
53[JsonSerializable(typeof(IList<ChatMessage>))]
Microsoft.Extensions.AI.Abstractions.Tests (29)
ChatCompletion\ChatClientExtensionsTests.cs (2)
59ChatMessage m = Assert.Single(chatMessages); 86ChatMessage m = Assert.Single(chatMessages);
ChatCompletion\ChatCompletionTests.cs (7)
16Assert.Throws<ArgumentNullException>("message", () => new ChatCompletion((ChatMessage)null!)); 17Assert.Throws<ArgumentNullException>("choices", () => new ChatCompletion((IList<ChatMessage>)null!)); 23ChatMessage message = new(); 33List<ChatMessage> messages = 57ChatMessage message = new(); 67ChatMessage first = new(); 120List<ChatMessage> newChoices = [new ChatMessage(), new ChatMessage()];
ChatCompletion\ChatMessageTests.cs (12)
17ChatMessage message = new(); 35ChatMessage message = new(ChatRole.Assistant, text); 75ChatMessage message = new(ChatRole.System, content); 109ChatMessage message = new() 125ChatMessage message = new(ChatRole.User, 150ChatMessage message = new(ChatRole.User, []); 164ChatMessage message = new(ChatRole.User, 199ChatMessage message = new(); 219ChatMessage message = new(); 240ChatMessage message = new(); 300var deserializedMessage = JsonSerializer.Deserialize<ChatMessage>(chatMessageJson, TestJsonSerializerContext.Default.Options)!;
ChatCompletion\DelegatingChatClientTests.cs (2)
33var expectedChatContents = new List<ChatMessage>(); 65var expectedChatContents = new List<ChatMessage>();
ChatCompletion\StreamingChatCompletionUpdateExtensionsTests.cs (2)
71ChatMessage message = completion.Choices[0]; 181ChatMessage message = completion.Message;
TestChatClient.cs (4)
22public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; } 24public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? CompleteStreamingAsyncCallback { get; set; } 31public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 34public IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.AzureAIInference (7)
AzureAIInferenceChatClient.cs (7)
83IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 93List<ChatMessage> returnMessages = []; 96ChatMessage message = new() 148IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 290private ChatCompletionsOptions ToAzureAIOptions(IList<ChatMessage> chatContents, ChatOptions? options) 410private IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IList<ChatMessage> inputs) 415foreach (ChatMessage input in inputs)
Microsoft.Extensions.AI.AzureAIInference.Tests (4)
AzureAIInferenceChatClientTests.cs (4)
149List<ChatMessage> chatMessages = multiContent ? 216List<ChatMessage> chatMessages = multiContent ? 504List<ChatMessage> messages = 649List<ChatMessage> messages =
Microsoft.Extensions.AI.Integration.Tests (15)
CallCountingChatClient.cs (2)
20IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 27IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ChatClientIntegrationTests.cs (5)
78IList<ChatMessage> chatHistory = 175List<ChatMessage> messages = 318var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 335var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 361var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000");
PromptBasedFunctionCallingChatClient.cs (3)
40public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 59foreach (var message in chatMessages) 152private static void AddOrUpdateToolPrompt(IList<ChatMessage> chatMessages, IList<AITool> tools)
ReducingChatClientTests.cs (1)
45List<ChatMessage> messages =
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
22public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; } 24public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? CompleteStreamingAsyncCallback { get; set; } 31public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 34public IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.Ollama (5)
OllamaChatClient.cs (5)
80public async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 111IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 230private static ChatMessage FromOllamaMessage(OllamaChatResponseMessage message) 278private OllamaChatRequest ToOllamaChatRequest(IList<ChatMessage> chatMessages, ChatOptions? options, bool stream) 368private IEnumerable<OllamaChatRequestMessage> ToOllamaChatRequestMessages(ChatMessage content)
Microsoft.Extensions.AI.Ollama.Tests (2)
OllamaChatClientIntegrationTests.cs (1)
93IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
OllamaChatClientTests.cs (1)
258List<ChatMessage> messages =
Microsoft.Extensions.AI.OpenAI (9)
OpenAIChatClient.cs (2)
102IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 117IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
OpenAIModelMapper.ChatCompletion.cs (1)
76ChatMessage returnMessage = new()
OpenAIModelMapper.ChatMessage.cs (5)
20IList<ChatMessage> messages = FromOpenAIChatMessages(_getMessagesAccessor(chatCompletionOptions)).ToList(); 30public static IEnumerable<ChatMessage> FromOpenAIChatMessages(IEnumerable<OpenAI.Chat.ChatMessage> inputs) 86ChatMessage message = new() 118public static IEnumerable<OpenAI.Chat.ChatMessage> ToOpenAIChatMessages(IEnumerable<ChatMessage> inputs, JsonSerializerOptions options) 123foreach (ChatMessage input in inputs)
OpenAISerializationHelpers.cs (1)
23/// Deserializes a chat completion request in the OpenAI wire format into a pair of <see cref="ChatMessage"/> and <see cref="ChatOptions"/> values.
Microsoft.Extensions.AI.OpenAI.Tests (9)
OpenAIChatClientTests.cs (4)
421List<ChatMessage> messages = 528List<ChatMessage> messages = 625List<ChatMessage> messages = 985List<ChatMessage> messages =
OpenAISerializationTests.cs (5)
46ChatMessage message = Assert.Single(request.Messages); 79ChatMessage message = Assert.Single(request.Messages); 436ChatMessage message = new() 533ChatMessage message1 = new() 539ChatMessage message2 = new()
Microsoft.Extensions.AI.Tests (51)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (9)
56var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 119var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 138var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 157var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 195var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 229var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 257var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 303var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 331var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\ConfigureOptionsChatClientTests.cs (3)
37ChatCompletion expectedCompletion = new(Array.Empty<ChatMessage>()); 76var completion = await client.CompleteAsync(Array.Empty<ChatMessage>(), providedOptions, cts.Token); 80await using var e = client.CompleteStreamingAsync(Array.Empty<ChatMessage>(), providedOptions, cts.Token).GetAsyncEnumerator();
ChatCompletion\FunctionInvokingChatClientTests.cs (26)
55List<ChatMessage> plan = 86List<ChatMessage> plan = 138List<ChatMessage> plan = 181List<ChatMessage> plan = 217List<ChatMessage> plan = 229List<ChatMessage>? expected = keepFunctionCallingMessages ? null : 240void Validate(List<ChatMessage> finalChat) 269List<ChatMessage> plan = 308void Validate(List<ChatMessage> finalChat) 335List<ChatMessage> plan = 375List<ChatMessage> chat = [new ChatMessage(ChatRole.User, "hello")]; 394List<ChatMessage> plan = 450List<ChatMessage> plan = 512var messages = new List<ChatMessage> 556private static async Task<List<ChatMessage>> InvokeAndAssertAsync( 558List<ChatMessage> plan, 559List<ChatMessage>? expected = null, 568List<ChatMessage> chat = [plan[0]]; 596var expectedMessage = expected[i]; 597var chatMessage = chat[i]; 651private static async Task<List<ChatMessage>> InvokeAndAssertStreamingAsync( 653List<ChatMessage> plan, 654List<ChatMessage>? expected = null, 663List<ChatMessage> chat = [plan[0]]; 686var expectedMessage = expected[i]; 687var chatMessage = chat[i];
ChatCompletion\OpenTelemetryChatClientTests.cs (2)
63IList<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken) 108List<ChatMessage> chatMessages =
ChatCompletion\UseDelegateChatClientTests.cs (6)
36IList<ChatMessage> expectedMessages = []; 86IList<ChatMessage> expectedMessages = []; 128IList<ChatMessage> expectedMessages = []; 155IList<ChatMessage> chatMessages, ChatOptions? options, IChatClient innerClient, [EnumeratorCancellation] CancellationToken cancellationToken) 179IList<ChatMessage> expectedMessages = []; 226IList<ChatMessage> chatMessages, ChatOptions? options, IChatClient innerClient, [EnumeratorCancellation] CancellationToken cancellationToken)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
22public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; } 24public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? CompleteStreamingAsyncCallback { get; set; } 31public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 34public IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
14[JsonSerializable(typeof(IList<ChatMessage>))]
Microsoft.ML.GenAI.Core (7)
CausalLMPipelineChatClient.cs (3)
37public virtual Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 48var chatMessage = new ChatMessage(ChatRole.Assistant, output); 59IList<ChatMessage> chatMessages,
Trainer\CausalLMDataset.cs (2)
26public static CausalLMDataset Create(IEnumerable<IEnumerable<ChatMessage>> inputs, 27IEnumerable<ChatMessage> outputs,
Utility\IChatTemplateBuilder.cs (2)
31/// <param name="messages">the list of <see cref="ChatMessage"/> to be rendered</param> 35string BuildPrompt(IList<ChatMessage> messages, ChatOptions? options = null, bool appendAssistantTag = true);
Microsoft.ML.GenAI.Core.Tests (3)
CasualLMDatasetTest.cs (3)
82var inputs = new List<List<ChatMessage>> 84new List<ChatMessage> 91var outputs = new List<ChatMessage>
Microsoft.ML.GenAI.LLaMA (4)
Llama3_1ChatTemplateBuilder.cs (2)
91public string BuildPrompt(IList<ChatMessage> messages, ChatOptions? options = null, bool appendAssistantTag = true) 106foreach (var message in messages)
Llama3CausalLMChatClient.cs (2)
28IList<ChatMessage> chatMessages, 47IList<ChatMessage> chatMessages,
Microsoft.ML.GenAI.Phi (4)
Phi3\Phi3CausalLMChatClient.cs (2)
33IList<ChatMessage> chatMessages, 52IList<ChatMessage> chatMessages,
Phi3\Phi3ChatTemplateBuilder.cs (2)
92public string BuildPrompt(IList<ChatMessage> messages, ChatOptions? options = null, bool appendAssistantTag = true) 109foreach (var message in messages)
Microsoft.ML.GenAI.Samples (4)
Llama\SFT_Llama_3_2_1B.cs (2)
105var trainChatHistory = new List<ChatMessage> 111var assistantMessage = new ChatMessage(ChatRole.Assistant, data.output);
MEAI\Llama3_1.cs (1)
47var chatMessage = new ChatMessage(ChatRole.User, task);
MEAI\Phi3.cs (1)
37var chatMessage = new ChatMessage(ChatRole.User, task);