113 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)
585ChatMessage 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)
94ChatMessage message = new()
Microsoft.Extensions.AI.Integration.Tests (9)
ChatClientIntegrationTests.cs (3)
308var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 325var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 351var 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)
254return new ChatMessage(new(message.Role), contents);
Microsoft.Extensions.AI.OpenAI (1)
OpenAIChatClient.cs (1)
120ChatMessage returnMessage = new()
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\DistributedCachingChatClientTest.cs (6)
85var result1 = await outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 90var result2 = await outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 97await outer.CompleteAsync([new ChatMessage(ChatRole.User, "some modified input")]); 122var result1 = outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 123var result2 = outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]); 134var result3 = outer.CompleteAsync([new ChatMessage(ChatRole.User, "some input")]);
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"),
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);
218 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) 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; }
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) 405private void LogChatMessages(IEnumerable<ChatMessage> messages) 412foreach (ChatMessage message in messages) 480private AssistantEvent CreateAssistantEvent(ChatMessage message) 501private 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) 152static 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)
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)
AzureAIInferenceChatClient.cs (7)
81IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 91List<ChatMessage> returnMessages = []; 94ChatMessage message = new() 146IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 288private ChatCompletionsOptions ToAzureAIOptions(IList<ChatMessage> chatContents, ChatOptions? options) 408private IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IEnumerable<ChatMessage> inputs) 413foreach (ChatMessage input in inputs)
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
307List<ChatMessage> messages = 400List<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)
79IList<ChatMessage> chatHistory = 168List<ChatMessage> messages = 308var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 325var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 351var 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)
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)
OllamaChatClient.cs (5)
79public 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) 257private OllamaChatRequest ToOllamaChatRequest(IList<ChatMessage> chatMessages, ChatOptions? options, bool stream) 347private IEnumerable<OllamaChatRequestMessage> ToOllamaChatRequestMessages(ChatMessage content)
Microsoft.Extensions.AI.Ollama.Tests (2)
OllamaChatClientIntegrationTests.cs (1)
99IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
OllamaChatClientTests.cs (1)
258List<ChatMessage> messages =
Microsoft.Extensions.AI.OpenAI (5)
OpenAIChatClient.cs (5)
109IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 120ChatMessage returnMessage = new() 200IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 577private IEnumerable<OpenAI.Chat.ChatMessage> ToOpenAIChatMessages(IEnumerable<ChatMessage> inputs) 582foreach (ChatMessage input in inputs)
Microsoft.Extensions.AI.OpenAI.Tests (4)
OpenAIChatClientTests.cs (4)
353List<ChatMessage> messages = 454List<ChatMessage> messages = 545List<ChatMessage> messages = 885List<ChatMessage> messages =
Microsoft.Extensions.AI.Tests (50)
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") }; 193var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 227var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 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\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 (25)
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 = 497private static async Task<List<ChatMessage>> InvokeAndAssertAsync( 499List<ChatMessage> plan, 500List<ChatMessage>? expected = null, 509List<ChatMessage> chat = [plan[0]]; 534var expectedMessage = expected[i]; 535var chatMessage = chat[i]; 566private static async Task<List<ChatMessage>> InvokeAndAssertStreamingAsync( 568List<ChatMessage> plan, 569List<ChatMessage>? expected = null, 578List<ChatMessage> chat = [plan[0]]; 601var expectedMessage = expected[i]; 602var chatMessage = chat[i];
ChatCompletion\OpenTelemetryChatClientTests.cs (2)
58IList<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken) 98List<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)
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)
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);