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)
347 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 (19)
AzureAIInferenceChatClientTests.cs (19)
150[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] :
151[new ChatMessage(ChatRole.User, "hello")];
163Assert.Equal(ChatRole.Assistant, response.Message.Role);
217[new ChatMessage(ChatRole.User, "hello".Select(c => (AIContent)new TextContent(c.ToString())).ToList())] :
218[new ChatMessage(ChatRole.User, "hello")];
239Assert.Equal(ChatRole.Assistant, updates[i].Role);
506new(ChatRole.System, "You are a really nice friend."),
507new(ChatRole.User, "hello!"),
508new(ChatRole.Assistant, "hi, how are you?"),
509new(ChatRole.User, "i'm good. how are you?"),
510new(ChatRole.Assistant, [new FunctionCallContent("abcd123", "GetMood")]),
511new(ChatRole.Tool, [new FunctionResultContent("abcd123", "GetMood", "happy")]),
527Assert.Equal(ChatRole.Assistant, response.Message.Role);
586Assert.NotNull(await client.CompleteAsync([new(ChatRole.User,
651new(ChatRole.Assistant, (string?)null),
652new(ChatRole.User, "hello!"),
661Assert.Equal(ChatRole.Assistant, response.Message.Role);
775Assert.Equal(ChatRole.Assistant, response.Message.Role);
871Assert.Equal(ChatRole.Assistant, updates[i].Role);
Microsoft.Extensions.AI.Integration.Tests (19)
ChatClientIntegrationTests.cs (11)
61new(ChatRole.User, "Pick a city, any city"),
62new(ChatRole.Assistant, "Seattle"),
63new(ChatRole.User, "And another one"),
64new(ChatRole.Assistant, "Jakarta"),
65new(ChatRole.User, "What continent are they each in?"),
80new(ChatRole.User, "Quote, word for word, Neil Armstrong's famous words.")
146new(ChatRole.User,
177new(ChatRole.User, "What is the current secret number?")
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");
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 (20)
Microsoft.Extensions.AI.OpenAI.Tests (39)
OpenAIChatClientTests.cs (24)
193Assert.Equal(ChatRole.Assistant, response.Message.Role);
273Assert.Equal(ChatRole.Assistant, updates[i].Role);
423new(ChatRole.System, "You are a really nice friend."),
424new(ChatRole.User, "hello!"),
425new(ChatRole.Assistant, "hi, how are you?"),
426new(ChatRole.User, "i'm good. how are you?"),
442Assert.Equal(ChatRole.Assistant, response.Message.Role);
530new(ChatRole.System, [new TextContent("You are a really nice friend."), new TextContent("Really nice.")]),
531new(ChatRole.User, "hello!"),
540Assert.Equal(ChatRole.Assistant, response.Message.Role);
627new(ChatRole.System, "You are a really nice friend."),
628new(ChatRole.User, "hello!"),
629new(ChatRole.Assistant, (string?)null),
630new(ChatRole.User, "i'm good. how are you?"),
639Assert.Equal(ChatRole.Assistant, response.Message.Role);
752Assert.Equal(ChatRole.Assistant, response.Message.Role);
864Assert.Equal(ChatRole.Assistant, updates[i].Role);
987new(ChatRole.System, "You are a really nice friend."),
988new(ChatRole.User, "hello!"),
989new(ChatRole.Assistant,
995new (ChatRole.Tool,
1000new(ChatRole.Assistant, "You are great."),
1001new(ChatRole.User, "Thanks!"),
1010Assert.Equal(ChatRole.Assistant, response.Message.Role);
OpenAISerializationTests.cs (15)
47Assert.Equal(ChatRole.User, message.Role);
80Assert.Equal(ChatRole.User, message.Role);
153Assert.Equal(ChatRole.System, msg.Role);
165Assert.Equal(ChatRole.User, msg.Role);
177Assert.Equal(ChatRole.Assistant, msg.Role);
189Assert.Equal(ChatRole.User, msg.Role);
247Assert.Equal(ChatRole.System, msg.Role);
271Assert.Equal(ChatRole.User, msg.Role);
407Assert.Equal(ChatRole.Assistant, msg.Role);
419Assert.Equal(ChatRole.Tool, msg.Role);
438Role = ChatRole.Assistant,
535Role = ChatRole.Assistant,
541Role = ChatRole.Assistant,
599Role = ChatRole.Assistant,
681Role = ChatRole.Assistant,
Microsoft.Extensions.AI.Tests (113)
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))]);
195var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
215var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult))]);
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") };
281var expectedCompletion = new ChatCompletion([new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, jso))]);
291Assert.Equal(ChatRole.User, message.Role);
303var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
327return Task.FromResult(new ChatCompletion([new ChatMessage(ChatRole.Assistant, resultDuplicatedJson)]));
331var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\FunctionInvokingChatClientTests.cs (72)
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"),
514new(ChatRole.User, "Hello"),
582return new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])) { Usage = usage };
672return 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.")])
72Role = ChatRole.Assistant,
110new(ChatRole.System, "You are a close friend."),
111new(ChatRole.User, "Hey!"),
112new(ChatRole.Assistant, [new FunctionCallContent("12345", "GetPersonName")]),
113new(ChatRole.Tool, [new FunctionResultContent("12345", "GetPersonName", "John")]),
114new(ChatRole.Assistant, "Hey John, what's up?"),
115new(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)