38 instantiations of ChatRole
Microsoft.Extensions.AI.Abstractions (5)
Microsoft.Extensions.AI.Abstractions.Tests (29)
Microsoft.Extensions.AI.AzureAIInference (1)
Microsoft.Extensions.AI.Ollama (1)
Microsoft.Extensions.AI.OpenAI (1)
Microsoft.Extensions.AI.Tests (1)
315 references to ChatRole
Aspire.Azure.AI.OpenAI.Tests (1)
Aspire.OpenAI.Tests (1)
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, $$"""
Microsoft.Extensions.AI.Abstractions (36)
Microsoft.Extensions.AI.Abstractions.Tests (43)
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\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);
Microsoft.Extensions.AI.AzureAIInference (10)
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");
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)
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\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\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?")
Microsoft.ML.GenAI.Core (2)
Microsoft.ML.GenAI.Core.Tests (3)
Microsoft.ML.GenAI.LLaMA (6)
Microsoft.ML.GenAI.LLaMA.Tests (3)
Microsoft.ML.GenAI.Phi (6)
Microsoft.ML.GenAI.Samples (5)