38 instantiations of ChatRole
Microsoft.Extensions.AI.Abstractions (5)
ChatCompletion\ChatRole.cs (5)
20public static ChatRole System { get; } = new("system"); 23public static ChatRole Assistant { get; } = new("assistant"); 26public static ChatRole User { get; } = new("user"); 29public static ChatRole Tool { get; } = new("tool"); 94new(reader.GetString()!);
Microsoft.Extensions.AI.Abstractions.Tests (29)
ChatCompletion\ChatCompletionTests.cs (1)
208ChatCompletion completion = new(new ChatMessage(new ChatRole("customRole"), "Text"))
ChatCompletion\ChatRoleTests.cs (28)
15Assert.Equal("abc", new ChatRole("abc").Value); 21Assert.Throws<ArgumentNullException>("value", () => new ChatRole(null!)); 22Assert.Throws<ArgumentException>("value", () => new ChatRole(" ")); 28Assert.True(new ChatRole("abc").Equals(new ChatRole("ABC"))); 29Assert.True(new ChatRole("abc").Equals((object)new ChatRole("ABC"))); 30Assert.True(new ChatRole("abc") == new ChatRole("ABC")); 31Assert.False(new ChatRole("abc") != new ChatRole("ABC")); 33Assert.False(new ChatRole("abc").Equals(new ChatRole("def"))); 34Assert.False(new ChatRole("abc").Equals((object)new ChatRole("def"))); 35Assert.False(new ChatRole("abc").Equals(null)); 36Assert.False(new ChatRole("abc").Equals("abc")); 37Assert.False(new ChatRole("abc") == new ChatRole("def")); 38Assert.True(new ChatRole("abc") != new ChatRole("def")); 40Assert.Equal(new ChatRole("abc").GetHashCode(), new ChatRole("abc").GetHashCode()); 41Assert.Equal(new ChatRole("abc").GetHashCode(), new ChatRole("ABC").GetHashCode()); 42Assert.NotEqual(new ChatRole("abc").GetHashCode(), new ChatRole("def").GetHashCode()); // not guaranteed 57ChatRole role = new("abc");
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
276new ChatRole(role.ToString());
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
254return new ChatMessage(new(message.Role), contents);
Microsoft.Extensions.AI.OpenAI (1)
OpenAIChatClient.cs (1)
381_ => new ChatRole(role.ToString()),
Microsoft.Extensions.AI.Tests (1)
ChatCompletion\DistributedCachingChatClientTest.cs (1)
43new(new ChatRole("fakeRole"), "This is some content")
315 references to ChatRole
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 (10)
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 (2)
363ChatMessage functionCallMessage = new(ChatRole.Assistant, [.. functionCallContents]); 585ChatMessage message = new(ChatRole.Tool, contents);
ChatCompletion\OpenTelemetryChatClient.cs (5)
414if (message.Role == ChatRole.Assistant) 419else if (message.Role == ChatRole.Tool) 435Log(new(1, message.Role == ChatRole.System ? OpenTelemetryConsts.GenAI.System.Message : OpenTelemetryConsts.GenAI.User.Message), 438Role = message.Role != ChatRole.System && message.Role != ChatRole.User && !string.IsNullOrWhiteSpace(message.Role.Value) ? message.Role.Value : null,
Microsoft.Extensions.AI.Abstractions (36)
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\ChatFinishReason.cs (1)
80/// <summary>Provides a <see cref="JsonConverter{ChatFinishReason}"/> for serializing <see cref="ChatRole"/> instances.</summary>
ChatCompletion\ChatMessage.cs (4)
26public ChatMessage(ChatRole role, string? content) 35ChatRole role, 50public ChatRole Role { get; set; } = ChatRole.User;
ChatCompletion\ChatRole.cs (24)
17public readonly struct ChatRole : IEquatable<ChatRole> 20public static ChatRole System { get; } = new("system"); 23public static ChatRole Assistant { get; } = new("assistant"); 26public static ChatRole User { get; } = new("user"); 29public static ChatRole Tool { get; } = new("tool"); 32/// Gets the value associated with this <see cref="ChatRole"/>. 40/// Initializes a new instance of the <see cref="ChatRole"/> struct with the provided value. 42/// <param name="value">The value to associate with this <see cref="ChatRole"/>.</param> 50/// Returns a value indicating whether two <see cref="ChatRole"/> instances are equivalent, as determined by a 53/// <param name="left">The first <see cref="ChatRole"/> instance to compare.</param> 54/// <param name="right">The second <see cref="ChatRole"/> instance to compare.</param> 56public static bool operator ==(ChatRole left, ChatRole right) 62/// Returns a value indicating whether two <see cref="ChatRole"/> instances are not equivalent, as determined by a 65/// <param name="left">The first <see cref="ChatRole"/> instance to compare. </param> 66/// <param name="right">The second <see cref="ChatRole"/> instance to compare. </param> 68public static bool operator !=(ChatRole left, ChatRole right) 75=> obj is ChatRole otherRole && Equals(otherRole); 78public bool Equals(ChatRole other) 88/// <summary>Provides a <see cref="JsonConverter{ChatRole}"/> for serializing <see cref="ChatRole"/> instances.</summary> 90public sealed class Converter : JsonConverter<ChatRole> 93public override ChatRole Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => 97public override void Write(Utf8JsonWriter writer, ChatRole value, JsonSerializerOptions options) =>
ChatCompletion\StreamingChatCompletionUpdate.cs (3)
27/// value must have the same value (e.g. <see cref="ChatRole.Assistant"/>. It should never be the case, for example, 28/// that one <see cref="StreamingChatCompletionUpdate"/> in a completion has a role of <see cref="ChatRole.Assistant"/> 56public ChatRole? Role { get; set; }
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (2)
109if (update.Role is ChatRole role && message.Role == default) 156entry.Value.Role = ChatRole.Assistant;
Microsoft.Extensions.AI.Abstractions.Tests (43)
ChatCompletion\ChatClientExtensionsTests.cs (2)
60Assert.Equal(ChatRole.User, m.Role); 87Assert.Equal(ChatRole.User, m.Role);
ChatCompletion\ChatCompletionTests.cs (11)
130new ChatMessage(ChatRole.Assistant, "Choice1"), 131new ChatMessage(ChatRole.Assistant, "Choice2"), 132new ChatMessage(ChatRole.Assistant, "Choice3"), 133new ChatMessage(ChatRole.Assistant, "Choice4"), 154Assert.Equal(ChatRole.Assistant, result.Choices[i].Role); 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."), 239new ChatMessage(ChatRole.Assistant, 249new ChatMessage(ChatRole.System,
ChatCompletion\ChatMessageTests.cs (10)
20Assert.Equal(ChatRole.User, message.Role); 35ChatMessage message = new(ChatRole.Assistant, text); 37Assert.Equal(ChatRole.Assistant, message.Role); 60Assert.Throws<ArgumentNullException>("contents", () => new ChatMessage(ChatRole.User, (IList<AIContent>)null!)); 75ChatMessage message = new(ChatRole.System, content); 77Assert.Equal(ChatRole.System, message.Role); 125ChatMessage message = new(ChatRole.User, 150ChatMessage message = new(ChatRole.User, []); 164ChatMessage message = new(ChatRole.User, 293var chatMessageJson = JsonSerializer.Serialize(new ChatMessage(ChatRole.User, contents: items)
ChatCompletion\ChatRoleTests.cs (6)
48Assert.Equal("assistant", ChatRole.Assistant.Value); 49Assert.Equal("system", ChatRole.System.Value); 50Assert.Equal("tool", ChatRole.Tool.Value); 51Assert.Equal("user", ChatRole.User.Value); 57ChatRole role = new("abc"); 61ChatRole? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatRole);
ChatCompletion\DelegatingChatClientTests.cs (2)
70new() { Role = ChatRole.User, Text = "Message 1" }, 71new() { Role = ChatRole.User, Text = "Message 2" }
ChatCompletion\StreamingChatCompletionUpdateExtensionsTests.cs (6)
44new() { ChoiceIndex = 0, Text = ", ", AuthorName = "Someone", Role = ChatRole.User, AdditionalProperties = new() { ["a"] = "b" } }, 45new() { ChoiceIndex = 1, Text = ", ", AuthorName = "Else", Role = ChatRole.System, AdditionalProperties = new() { ["g"] = "h" } }, 48new() { ChoiceIndex = 1, Text = "you!", Role = ChatRole.Tool, CreatedAt = new DateTimeOffset(3, 2, 3, 4, 5, 6, TimeSpan.Zero), AdditionalProperties = new() { ["e"] = "f", ["i"] = 42 } }, 72Assert.Equal(ChatRole.User, message.Role); 80Assert.Equal(ChatRole.System, message.Role); 89Assert.Equal(ChatRole.Assistant, message.Role);
ChatCompletion\StreamingChatCompletionUpdateTests.cs (6)
40update.Role = ChatRole.Assistant; 41Assert.Equal(ChatRole.Assistant, update.Role); 91Role = ChatRole.User, 120Role = ChatRole.User, 168Role = ChatRole.Assistant, 208Assert.Equal(ChatRole.Assistant, result.Role);
Microsoft.Extensions.AI.AzureAIInference (10)
AzureAIInferenceChatClient.cs (10)
151ChatRole? streamedRole = default; 271private static ChatRole ToChatRole(global::Azure.AI.Inference.ChatRole role) => 272role.Equals(global::Azure.AI.Inference.ChatRole.System) ? ChatRole.System : 273role.Equals(global::Azure.AI.Inference.ChatRole.User) ? ChatRole.User : 274role.Equals(global::Azure.AI.Inference.ChatRole.Assistant) ? ChatRole.Assistant : 275role.Equals(global::Azure.AI.Inference.ChatRole.Tool) ? ChatRole.Tool : 415if (input.Role == ChatRole.System) 419else if (input.Role == ChatRole.Tool) 442else if (input.Role == ChatRole.User) 446else if (input.Role == ChatRole.Assistant)
Microsoft.Extensions.AI.AzureAIInference.Tests (12)
AzureAIInferenceChatClientTests.cs (12)
150Assert.Equal(ChatRole.Assistant, response.Message.Role); 220Assert.Equal(ChatRole.Assistant, updates[i].Role); 309new(ChatRole.System, "You are a really nice friend."), 310new(ChatRole.User, "hello!"), 311new(ChatRole.Assistant, "hi, how are you?"), 312new(ChatRole.User, "i'm good. how are you?"), 328Assert.Equal(ChatRole.Assistant, response.Message.Role); 402new(ChatRole.Assistant, (string?)null), 403new(ChatRole.User, "hello!"), 412Assert.Equal(ChatRole.Assistant, response.Message.Role); 518Assert.Equal(ChatRole.Assistant, response.Message.Role); 619Assert.Equal(ChatRole.Assistant, updates[i].Role);
Microsoft.Extensions.AI.Integration.Tests (19)
ChatClientIntegrationTests.cs (11)
62new(ChatRole.User, "Pick a city, any city"), 63new(ChatRole.Assistant, "Seattle"), 64new(ChatRole.User, "And another one"), 65new(ChatRole.Assistant, "Jakarta"), 66new(ChatRole.User, "What continent are they each in?"), 81new(ChatRole.User, "Quote, word for word, Neil Armstrong's famous words.") 147new(ChatRole.User, 170new(ChatRole.User, "What is the current secret number?") 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)
66message.Role = ChatRole.User; 73message.Role = ChatRole.Assistant; 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.Tests (11)
OllamaChatClientTests.cs (11)
122Assert.Equal(ChatRole.Assistant, response.Message.Role); 189Assert.Equal(ChatRole.Assistant, updates[i].Role); 260new(ChatRole.User, "hello!"), 261new(ChatRole.Assistant, "hi, how are you?"), 262new(ChatRole.User, "i'm good. how are you?"), 284Assert.Equal(ChatRole.Assistant, response.Message.Role); 373Assert.Equal(ChatRole.Assistant, response.Message.Role); 459new(ChatRole.User, "How old is Alice?"), 460new(ChatRole.Assistant, [new FunctionCallContent("abcd1234", "GetPersonAge", new Dictionary<string, object?> { ["personName"] = "Alice" })]), 461new(ChatRole.Tool, [new FunctionResultContent("abcd1234", "GetPersonAge", 42)]), 471Assert.Equal(ChatRole.Assistant, response.Message.Role);
Microsoft.Extensions.AI.OpenAI (11)
OpenAIChatClient.cs (11)
205ChatRole? streamedRole = null; 374private static ChatRole ToChatRole(ChatMessageRole role) => 377ChatMessageRole.System => ChatRole.System, 378ChatMessageRole.User => ChatRole.User, 379ChatMessageRole.Assistant => ChatRole.Assistant, 380ChatMessageRole.Tool => ChatRole.Tool, 584if (input.Role == ChatRole.System || input.Role == ChatRole.User) 587yield return input.Role == ChatRole.System ? 591else if (input.Role == ChatRole.Tool) 614else if (input.Role == ChatRole.Assistant)
Microsoft.Extensions.AI.OpenAI.Tests (24)
OpenAIChatClientTests.cs (24)
193Assert.Equal(ChatRole.Assistant, response.Message.Role); 267Assert.Equal(ChatRole.Assistant, updates[i].Role); 355new(ChatRole.System, "You are a really nice friend."), 356new(ChatRole.User, "hello!"), 357new(ChatRole.Assistant, "hi, how are you?"), 358new(ChatRole.User, "i'm good. how are you?"), 374Assert.Equal(ChatRole.Assistant, response.Message.Role); 456new(ChatRole.System, [new TextContent("You are a really nice friend."), new TextContent("Really nice.")]), 457new(ChatRole.User, "hello!"), 466Assert.Equal(ChatRole.Assistant, response.Message.Role); 547new(ChatRole.System, "You are a really nice friend."), 548new(ChatRole.User, "hello!"), 549new(ChatRole.Assistant, (string?)null), 550new(ChatRole.User, "i'm good. how are you?"), 559Assert.Equal(ChatRole.Assistant, response.Message.Role); 666Assert.Equal(ChatRole.Assistant, response.Message.Role); 770Assert.Equal(ChatRole.Assistant, updates[i].Role); 887new(ChatRole.System, "You are a really nice friend."), 888new(ChatRole.User, "hello!"), 889new(ChatRole.Assistant, 895new (ChatRole.Tool, 900new(ChatRole.Assistant, "You are great."), 901new(ChatRole.User, "Thanks!"), 910Assert.Equal(ChatRole.Assistant, response.Message.Role);
Microsoft.Extensions.AI.Tests (112)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (21)
20var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult))]) 43Assert.Equal(ChatRole.User, message.Role); 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") }; 151var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, [new ImageContent("https://example.com")])]); 157var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 171var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult))]); 193var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 213var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult))]); 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") }; 279var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, jso))]); 289Assert.Equal(ChatRole.User, message.Role); 301var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 325return Task.FromResult(new ChatCompletion([new ChatMessage(ChatRole.Assistant, resultDuplicatedJson)])); 329var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\DistributedCachingChatClientTest.cs (7)
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")]); 113return new ChatCompletion([new(ChatRole.Assistant, "Hello")]); 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 (71)
57new ChatMessage(ChatRole.User, "hello"), 58new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 59new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Func1", result: "Result 1")]), 60new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 61new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", "Func2", result: "Result 2: 42")]), 62new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 63new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", "VoidReturn", result: "Success: Function completed.")]), 64new ChatMessage(ChatRole.Assistant, "world"), 88new ChatMessage(ChatRole.User, "hello"), 89new ChatMessage(ChatRole.Assistant, 95new ChatMessage(ChatRole.Tool, 101new ChatMessage(ChatRole.Assistant, 106new ChatMessage(ChatRole.Tool, 111new ChatMessage(ChatRole.Assistant, "world"), 140new ChatMessage(ChatRole.User, "hello"), 141new ChatMessage(ChatRole.Assistant, 146new ChatMessage(ChatRole.Tool, 151new ChatMessage(ChatRole.Assistant, "done"), 183new ChatMessage(ChatRole.User, "hello"), 184new ChatMessage(ChatRole.Assistant, 189new ChatMessage(ChatRole.Tool, 194new ChatMessage(ChatRole.Assistant, "done"), 219new ChatMessage(ChatRole.User, "hello"), 220new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 221new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Func1", result: "Result 1")]), 222new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 223new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", "Func2", result: "Result 2: 42")]), 224new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 225new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", "VoidReturn", result: "Success: Function completed.")]), 226new ChatMessage(ChatRole.Assistant, "world"), 231new ChatMessage(ChatRole.User, "hello"), 232new ChatMessage(ChatRole.Assistant, "world") 271new ChatMessage(ChatRole.User, "hello"), 272new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new FunctionCallContent("callId1", "Func1"), new TextContent("stuff")]), 273new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", "Func1", result: "Result 1")]), 274new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 275new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", "Func2", result: "Result 2: 42")]), 276new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } }), new TextContent("more")]), 277new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", "VoidReturn", result: "Success: Function completed.")]), 278new ChatMessage(ChatRole.Assistant, "world"), 286new ChatMessage(ChatRole.User, "hello"), 287new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new TextContent("stuff")]), 288new ChatMessage(ChatRole.Assistant, "more"), 289new ChatMessage(ChatRole.Assistant, "world"), 294new ChatMessage(ChatRole.User, "hello"), 295new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 296new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", "Func1", result: "Result 1")]), 297new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 298new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", "Func2", result: "Result 2: 42")]), 299new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 300new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", "VoidReturn", result: "Success: Function completed.")]), 301new ChatMessage(ChatRole.Assistant, "extrastuffmoreworld"), 304new ChatMessage(ChatRole.User, "hello"), 305new ChatMessage(ChatRole.Assistant, "extrastuffmoreworld"), 337new ChatMessage(ChatRole.User, "hello"), 338new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 339new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Func1", result: detailedErrors ? "Error: Function failed. Exception: Oh no!" : "Error: Function failed.")]), 340new ChatMessage(ChatRole.Assistant, "world"), 358new(ChatRole.Assistant, [new FunctionCallContent("callId1", func1.Metadata.Name)]), 359new(ChatRole.Assistant, [new FunctionCallContent("callId2", func2.Metadata.Name)]), 375List<ChatMessage> chat = [new ChatMessage(ChatRole.User, "hello")]; 396new ChatMessage(ChatRole.User, "hello"), 397new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["arg1"] = "value1" })]), 398new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Func1", result: "Result 1")]), 399new ChatMessage(ChatRole.Assistant, "world"), 452new ChatMessage(ChatRole.User, "hello"), 453new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["arg1"] = "value1" })]), 454new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Func1", result: "Result 1")]), 455new ChatMessage(ChatRole.Assistant, "world"), 520return new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])); 587return YieldAsync(new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])).ToStreamingChatCompletionUpdates());
ChatCompletion\LoggingChatClientTests.cs (2)
40return Task.FromResult(new ChatCompletion([new(ChatRole.Assistant, "blue whale")])); 50[new(ChatRole.User, "What's the biggest animal?")],
ChatCompletion\OpenTelemetryChatClientTests.cs (8)
42return new ChatCompletion([new ChatMessage(ChatRole.Assistant, "The blue whale, I think.")]) 67Role = ChatRole.Assistant, 100new(ChatRole.System, "You are a close friend."), 101new(ChatRole.User, "Hey!"), 102new(ChatRole.Assistant, [new FunctionCallContent("12345", "GetPersonName")]), 103new(ChatRole.Tool, [new FunctionResultContent("12345", "GetPersonName", "John")]), 104new(ChatRole.Assistant, "Hey John, what's up?"), 105new(ChatRole.User, "What's the biggest animal?")
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 (2)
CausalLMPipelineChatClient.cs (2)
48var chatMessage = new ChatMessage(ChatRole.Assistant, output); 74Role = ChatRole.Assistant,
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 (6)
Llama3_1ChatTemplateBuilder.cs (6)
93var availableRoles = new[] { ChatRole.System, ChatRole.User, ChatRole.Assistant }; 112_ when message.Role == ChatRole.System => $"<|start_header_id|>system<|end_header_id|>{Newline}{content.Trim()}<|eot_id|>{Newline}", 113_ when message.Role == ChatRole.User => $"<|start_header_id|>user<|end_header_id|>{Newline}{content.Trim()}<|eot_id|>{Newline}", 114_ when message.Role == ChatRole.Assistant => $"<|start_header_id|>assistant<|end_header_id|>{Newline}{content.Trim()}<|eot_id|>{Newline}",
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.Phi (6)
Phi3\Phi3ChatTemplateBuilder.cs (6)
94var availableRoles = new[] { ChatRole.System, ChatRole.User, ChatRole.Assistant }; 115_ when message.Role == ChatRole.System => $"<|system|>{Newline}{content}<|end|>{Newline}", 116_ when message.Role == ChatRole.User => $"<|user|>{Newline}{content}<|end|>{Newline}", 117_ when message.Role == ChatRole.Assistant => $"<|assistant|>{Newline}{content}<|end|>{Newline}",
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);