1148 instantiations of ChatMessage
Aspire.Azure.AI.Inference.Tests (1)
ConformanceTests.cs (1)
83service.GetResponseAsync(new ChatMessage()).GetAwaiter().GetResult();
Aspire.Azure.AI.OpenAI.Tests (2)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (1)
221=> Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Hello from middleware")));
ConformanceTests.cs (1)
108service.GetResponseAsync(new ChatMessage()).GetAwaiter().GetResult();
Aspire.Dashboard (29)
Model\Assistant\AIHelpers.cs (1)
358list.Add(new ChatMessage(update.Role ?? ChatRole.Assistant, contentsList)
Model\Assistant\AssistantChatViewModel.cs (3)
570var assistantMessage = new ChatMessage(ChatRole.Assistant, responseText.ToString()); 607var assistantMessage = new ChatMessage(ChatRole.Assistant, responseText.ToString()); 884chatViewModel.AddChatMessage(new ChatMessage(ChatRole.User, promptText));
Model\Assistant\Prompts\KnownChatMessages.cs (25)
43return new ChatMessage(ChatRole.System, systemChatMessage); 67return new(ChatRole.User, resolvedPromptText); 78return new(ChatRole.User, prompt); 89return new(ChatRole.User, prompt); 99return new(ChatRole.User, message); 112return new(ChatRole.User, prompt); 122return new(ChatRole.User, prompt); 133return new(ChatRole.User, prompt); 142return new(ChatRole.User, prompt); 155return new(ChatRole.User, prompt); 165return new(ChatRole.User, prompt); 174return new(ChatRole.User, prompt); 196return new(ChatRole.User, prompt); 214return new(ChatRole.User, prompt); 224return new(ChatRole.User, prompt); 234return new(ChatRole.User, prompt); 243return new(ChatRole.User, prompt); 255return new(ChatRole.User, message); 264return new(ChatRole.User, message); 274return new ChatMessage(ChatRole.User, message); 284return new ChatMessage(ChatRole.User, message); 311return new(ChatRole.User, prompt); 338return new(ChatRole.User, prompt); 356return new(ChatRole.User, prompt); 365return new(ChatRole.User, prompt);
Aspire.OpenAI.Tests (2)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (1)
269=> Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Hello from middleware")));
ConformanceTests.cs (1)
90service.GetResponseAsync(new ChatMessage()).GetAwaiter().GetResult();
Microsoft.AspNetCore.Components.AI (2)
Components\MessageInput.cs (1)
158await _agentContext.SendMessageAsync(new ChatMessage(ChatRole.User, text));
Engine\AgentContext.cs (1)
64return SendMessageAsync(new ChatMessage(ChatRole.User, text), cancellationToken);
Microsoft.Extensions.AI (12)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (3)
61GetResponseAsync<T>(chatClient, new ChatMessage(ChatRole.User, chatMessage), options, useJsonSchemaResponseFormat, cancellationToken); 101GetResponseAsync<T>(chatClient, new ChatMessage(ChatRole.User, chatMessage), serializerOptions, options, useJsonSchemaResponseFormat, cancellationToken); 190promptAugmentation = new ChatMessage(ChatRole.User, $$"""
ChatCompletion\FunctionInvokingChatClient.cs (3)
1276return [new(ChatRole.Tool, contents)]; 1385new ChatMessage(ChatRole.Tool, rejectedFunctionCallResults) { MessageId = toolMessageId } : 1650ChatMessage functionCallMessage = resultWithRequestMessage.RequestMessage?.Clone() ?? new() { Role = ChatRole.Assistant };
ChatCompletion\OpenTelemetryImageGenerator.cs (2)
190OtelMessageSerializer.SerializeChatMessages([new(ChatRole.User, content)])); 237OtelMessageSerializer.SerializeChatMessages([new(ChatRole.Assistant, contents)]));
ChatReduction\SummarizingChatReducer.cs (3)
193yield return new ChatMessage(ChatRole.Assistant, summary); 219yield return new ChatMessage(ChatRole.Assistant, summary); 231yield return new ChatMessage(ChatRole.System, summarizationPrompt);
SpeechToText\OpenTelemetrySpeechToTextClient.cs (1)
350OtelMessageSerializer.SerializeChatMessages([new(ChatRole.Assistant, response.Contents)]));
Microsoft.Extensions.AI.Abstractions (6)
ChatCompletion\ChatClientExtensions.cs (2)
100return client.GetResponseAsync(new ChatMessage(ChatRole.User, chatMessage), options, cancellationToken); 140return client.GetStreamingResponseAsync(new ChatMessage(ChatRole.User, chatMessage), options, cancellationToken);
ChatCompletion\ChatMessage.cs (1)
51new()
ChatCompletion\ChatResponseExtensions.cs (2)
90list.Add(new(update.Role ?? ChatRole.Assistant, contentsList) 556message = new(ChatRole.Assistant, []);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessage.g.cs (1)
33ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatMessage(),
Microsoft.Extensions.AI.Abstractions.Tests (32)
ChatCompletion\ChatMessageTests.cs (15)
17ChatMessage message = new(); 36ChatMessage message = new(ChatRole.Assistant, text); 64message = new(); 68message = new(ChatRole.User, (string?)null); 72message = new(ChatRole.User, (IList<AIContent>?)null); 76message = new ChatMessage(ChatRole.User, Array.Empty<AIContent>()); 93ChatMessage message = new(ChatRole.System, content); 128ChatMessage message = new() 144ChatMessage message = new(ChatRole.User, 170Assert.IsType<List<AIContent>>(new ChatMessage().Contents); 176ChatMessage message = new(); 196ChatMessage message = new(); 217ChatMessage message = new(); 238ChatMessage message = new(); 276var chatMessage = new ChatMessage(ChatRole.User, contents: items)
ChatCompletion\ChatResponseTests.cs (6)
87ChatResponse original = new(new ChatMessage(ChatRole.Assistant, "the message")) 124ChatResponse original = new(new ChatMessage(ChatRole.Assistant, "the message")) 233ChatResponse response = new(new ChatMessage(ChatRole.Assistant, $"This is a test.{Environment.NewLine}It's multiple lines.")); 241ChatResponse response = new(new ChatMessage(new ChatRole("customRole"), "Text") { MessageId = "someMessage" }) 273new ChatMessage(new ChatRole("customRole"), "Text") 278new ChatMessage(new ChatRole("secondRole"), "Another message")
ChatRouting\RoutingChatClientTests.cs (6)
23var messages = new ChatMessage[] { new(ChatRole.User, "hi") }; 26ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 76() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 88() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 90() => CollectAsync(router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]))); 113_ = await router.GetResponseAsync([new(ChatRole.User, "hi")]);
ChatRouting\RoutingContextTests.cs (1)
15var messages = new List<ChatMessage> { new(ChatRole.User, "initial") };
Contents\AIContentTests.cs (1)
65ChatMessage message = new(ChatRole.User,
Contents\ToolCallContentTests.cs (1)
54ChatMessage message = new(ChatRole.Assistant,
Contents\ToolResultContentTests.cs (1)
53ChatMessage message = new(ChatRole.Tool,
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.ChatMessage.g.cs (1)
31ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatMessage(),
Microsoft.Extensions.AI.Evaluation (3)
EvaluatorExtensions.cs (3)
51modelResponse: new ChatMessage(ChatRole.Assistant, modelResponse), 95userRequest: new ChatMessage(ChatRole.User, userRequest), 96modelResponse: new ChatMessage(ChatRole.Assistant, modelResponse),
Microsoft.Extensions.AI.Evaluation.Integration.Tests (9)
ChatMessageUtilities.cs (3)
9=> new ChatMessage(ChatRole.System, message); 12=> new ChatMessage(ChatRole.User, message); 15=> new ChatMessage(ChatRole.Assistant, message);
SafetyEvaluatorTests.cs (6)
335new ChatMessage 373new ChatMessage 407new ChatMessage 420new ChatMessage 456new ChatMessage 469new ChatMessage
Microsoft.Extensions.AI.Evaluation.NLP.Tests (17)
BLEUEvaluatorTests.cs (6)
19var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "The quick brown fox jumps over the lazy dog.")); 35var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Completely unrelated sentence.")); 50var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Some text.")); 70var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, hypothesis)); 90var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, hypothesis)); 103var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, ""));
F1EvaluatorTests.cs (5)
19var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "The quick brown fox jumps over the lazy dog.")); 35var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Completely unrelated sentence.")); 50var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Some text.")); 70var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, hypothesis)); 83var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, ""));
GLEUEvaluatorTests.cs (6)
19var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "The quick brown fox jumps over the lazy dog.")); 35var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Completely unrelated sentence.")); 50var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Some text.")); 70var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, hypothesis)); 90var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, hypothesis)); 103var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, ""));
Microsoft.Extensions.AI.Evaluation.Quality (22)
CoherenceEvaluator.cs (2)
117List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 195evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
CompletenessEvaluator.cs (2)
125List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 187evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
EquivalenceEvaluator.cs (2)
124List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 174evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
FluencyEvaluator.cs (2)
109List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 175evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
GroundednessEvaluator.cs (2)
127List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 297evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
IntentResolutionEvaluator.cs (2)
173List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 316evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
RelevanceEvaluator.cs (2)
122List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 201evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
RelevanceTruthAndCompletenessEvaluator.cs (1)
266return [new ChatMessage(ChatRole.User, evaluationPrompt)];
RetrievalEvaluator.cs (2)
141List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 226evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
TaskAdherenceEvaluator.cs (1)
264List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, systemPrompt)];
ToolCallAccuracyEvaluator.cs (2)
170List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)]; 219evaluationInstructions.Add(new ChatMessage(ChatRole.User, evaluationPrompt));
Utilities\JsonOutputFixer.cs (2)
67new ChatMessage(ChatRole.System, SystemPrompt), 68new ChatMessage(ChatRole.User, fixPrompt)
Microsoft.Extensions.AI.Evaluation.Reporting (4)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessage.g.cs (1)
33ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatMessage(),
ScenarioRunExtensions.cs (3)
36modelResponse: new ChatMessage(ChatRole.Assistant, modelResponse), 65userRequest: new ChatMessage(ChatRole.User, userRequest), 66modelResponse: new ChatMessage(ChatRole.Assistant, modelResponse),
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessage.g.cs (1)
33ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatMessage(),
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (9)
ResultStoreTester.cs (2)
33messages: [new ChatMessage(ChatRole.User, "User prompt")], 34modelResponse: new ChatResponse(new ChatMessage(ChatRole.Assistant, "LLM response")),
ScenarioRunResultTests.cs (6)
88messages: [new ChatMessage(ChatRole.User, "prompt")], 89modelResponse: new ChatResponse(new ChatMessage(ChatRole.Assistant, "response")), 180messages: [new ChatMessage(ChatRole.User, "prompt")], 181modelResponse: new ChatResponse(new ChatMessage(ChatRole.Assistant, "response")), 234new ChatMessage( 243new ChatMessage(
SerializationChainingTests.cs (1)
28new ChatMessage
Microsoft.Extensions.AI.Evaluation.Safety (2)
ContentSafetyChatClient.cs (1)
67return new ChatResponse(new ChatMessage(ChatRole.Assistant, annotationResult))
ContentSafetyEvaluator.cs (1)
133var payloadMessage = new ChatMessage(ChatRole.User, payload);
Microsoft.Extensions.AI.Evaluation.Tests (3)
ChatMessageUtilities.cs (3)
9=> new ChatMessage(ChatRole.System, message); 12=> new ChatMessage(ChatRole.User, message); 15=> new ChatMessage(ChatRole.Assistant, message);
Microsoft.Extensions.AI.Integration.Tests (79)
ChatClientIntegrationTests.cs (59)
68new(ChatRole.User, "Pick a city, any city"), 69new(ChatRole.Assistant, "Seattle"), 70new(ChatRole.User, "And another one"), 71new(ChatRole.Assistant, "Jakarta"), 72new(ChatRole.User, "What continent are they each in?"), 86new(ChatRole.System, []), 87new(ChatRole.User, []), 88new(ChatRole.Assistant, []), 89new(ChatRole.User, "What is 1 + 2? Reply with a single number."), 102new(ChatRole.User, "Quote, word for word, Neil Armstrong's famous words.") 160List<ChatMessage> history = [new(ChatRole.User, "Explain in 100 words how AI works")]; 183new(ChatRole.User, 201new(ChatRole.User, 231new(ChatRole.User, "What is the current secret number?") 298new(ChatRole.User, "What is the secret number for id foo?") 330new(ChatRole.User, "What is the secret number for John aged 19?") 360new(ChatRole.User, "Can you add bacon, lettuce, and tomatoes to Peter's shopping cart?") 640var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 656var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 681var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 733var message = new ChatMessage(ChatRole.User, "What is the temperature?"); 772var message = new ChatMessage(ChatRole.User, "What is the temperature?"); 814var message = new ChatMessage(ChatRole.User, "What is the temperature?"); 842await chatClient.GetResponseAsync([new(ChatRole.User, "What's the biggest animal?")]); 941var response = await chatClient.GetResponseAsync([new(ChatRole.User, "What's the biggest animal?")]); 1137new(ChatRole.User, "My name is Alice and I love hiking in the mountains."), 1138new(ChatRole.Assistant, "Nice to meet you, Alice! Hiking in the mountains sounds wonderful. Do you have a favorite trail?"), 1139new(ChatRole.User, "Yes, I love the Pacific Crest Trail. I hiked a section last summer."), 1140new(ChatRole.Assistant, "The Pacific Crest Trail is amazing! Which section did you hike?"), 1141new(ChatRole.User, "I hiked the section through the Sierra Nevada. It was challenging but beautiful."), 1142new(ChatRole.Assistant, "The Sierra Nevada section is known for its stunning views. How long did it take you?"), 1143new(ChatRole.User, "What's my name and what activity do I enjoy?") 1179new(ChatRole.System, "You are a pirate. Always respond in pirate speak."), 1180new(ChatRole.User, "Tell me about the weather"), 1181new(ChatRole.Assistant, "Ahoy matey! The weather be fine today, with clear skies on the horizon!"), 1182new(ChatRole.User, "What about tomorrow?"), 1183new(ChatRole.Assistant, "Arr, tomorrow be lookin' a bit cloudy, might be some rain blowin' in from the east!"), 1184new(ChatRole.User, "Should I bring an umbrella?"), 1185new(ChatRole.Assistant, "Aye, ye best be bringin' yer umbrella, unless ye want to be soaked like a barnacle!"), 1186new(ChatRole.User, "What's 2 + 2?") 1240new(ChatRole.User, "What's the weather in Seattle?"), 1241new(ChatRole.Assistant, "Let me check the weather in Seattle for you."), 1242new(ChatRole.User, "And what about Miami?"), 1243new(ChatRole.Assistant, "I'll check Miami's weather as well."), 1244new(ChatRole.User, "Which city had better weather?") 1274new(ChatRole.User, "I'm Bob and I work as a software engineer at a startup."), 1275new(ChatRole.Assistant, "Nice to meet you, Bob! Working at a startup must be exciting. What kind of software do you develop?"), 1276new(ChatRole.User, "We build AI-powered tools for education."), 1277new(ChatRole.Assistant, "That sounds impactful! AI in education has so much potential."), 1278new(ChatRole.User, "Yes, we focus on personalized learning experiences."), 1279new(ChatRole.Assistant, "Personalized learning is the future of education!"), 1280new(ChatRole.User, "Was anyone named in the conversation? Provide their name and job.") 1320new(ChatRole.User, "I have 3 cats and 2 dogs."), 1321new(ChatRole.Assistant, "That's 5 pets total! You must have a lively household."), 1322new(ChatRole.User, "Yes, and I spend about $200 per month on pet food."), 1323new(ChatRole.Assistant, "That's a significant expense, but I'm sure they're worth it!"), 1324new(ChatRole.User, "They eat 10 cans of food per week."), 1325new(ChatRole.Assistant, "That's quite a bit of food for your furry friends!"), 1326new(ChatRole.User, "How many pets do I have in total?")
ImageGeneratingChatClientIntegrationTests.cs (12)
128[new ChatMessage(ChatRole.User, "Please generate an image of a cat")], 166[new ChatMessage(ChatRole.User, [new TextContent("Please edit this image to add a red border"), originalImageData])], 195new(ChatRole.User, "Please generate an image of a dog") 203chatHistory.Add(new ChatMessage(ChatRole.User, "Please edit the image to make it more colorful")); 245new(ChatRole.User, "Please generate an image of a tree") 253chatHistory.Add(new ChatMessage(ChatRole.User, "Please edit the image to add flowers")); 258chatHistory.Add(new ChatMessage(ChatRole.User, "Please edit that last image to add birds")); 290new(ChatRole.User, "Please generate an image of a tree") 298chatHistory.Add(new ChatMessage(ChatRole.User, "Please edit the image to add fruit")); 303chatHistory.Add(new ChatMessage(ChatRole.User, "That didn't work out. Please edit the original image to add birds")); 341[new ChatMessage(ChatRole.User, "Generate an image of a castle")], 379new ChatMessage(ChatRole.User,
PromptBasedFunctionCallingChatClient.cs (3)
72chatMessagesList[messageIndex] = new ChatMessage(ChatRole.User, $"<tool_call_result>{toolCallResultJson}</tool_call_result>"); 77chatMessagesList[messageIndex] = new ChatMessage(ChatRole.Assistant, $"<tool_call_json>{toolCallJson}</tool_call_json>"); 186return new ChatMessage(ChatRole.System, prompt);
ReducingChatClientTests.cs (5)
45new ChatMessage(ChatRole.User, "Hi there! Can you tell me about golden retrievers?"), 46new 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."), 47new ChatMessage(ChatRole.User, "What kind of exercise do they need?"), 48new 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."), 49new ChatMessage(ChatRole.User, "Are they good with kids?"),
Microsoft.Extensions.AI.OpenAI (4)
MicrosoftExtensionsAIChatExtensions.cs (1)
185Microsoft.Extensions.AI.ChatMessage resultMessage = new()
OpenAIChatClient.cs (1)
502ChatMessage returnMessage = new()
OpenAIResponsesChatClient.cs (2)
189message ??= new(ChatRole.Assistant, (string?)null); 197message = new ChatMessage();
Microsoft.Extensions.AI.OpenAI.Tests (95)
OpenAIChatClientTests.cs (17)
821new(ChatRole.System, "You are a really nice friend."), 822new(ChatRole.User, "hello!"), 823new(ChatRole.Assistant, "hi, how are you?"), 824new(ChatRole.User, "i'm good. how are you?"), 928new(ChatRole.System, [new TextContent("You are a really nice friend."), new TextContent("Really nice.")]), 929new(ChatRole.User, "hello!"), 1024new(ChatRole.System, "You are a really nice friend."), 1025new(ChatRole.User, "hello!"), 1026new(ChatRole.Assistant, (string?)null), 1027new(ChatRole.User, "i'm good. how are you?"), 1467new(ChatRole.System, "You are a really nice friend."), 1468new(ChatRole.User, "hello!"), 1469new(ChatRole.Assistant, 1475new (ChatRole.Tool, 1480new(ChatRole.Assistant, "You are great."), 1481new(ChatRole.User, "Thanks!"), 1587new(ChatRole.User,
OpenAIConversionTests.cs (36)
726new(ChatRole.System, "You are a helpful assistant."), 727new(ChatRole.User, "Hello") { AuthorName = "Jane" }, 728new(ChatRole.Assistant, 737new(ChatRole.Tool, [new FunctionResultContent("callid123", "theresult")]), 738new(ChatRole.Assistant, "The answer is 42.") { AuthorName = "@#$#$@$" }, 795new(ChatRole.System, "You are a helpful assistant."), 796new(ChatRole.User, "Hello"), 797new(ChatRole.Assistant, 806new(ChatRole.Tool, [new FunctionResultContent("callid123", "theresult")]), 807new(ChatRole.Assistant, "The answer is 42."), 848new(ChatRole.User, 856new(ChatRole.Assistant, 861new(ChatRole.User, 1191new(ChatRole.Assistant, "Hi there!") 1217new(ChatRole.Assistant, 1492var items = new ChatMessage[] { new(ChatRole.Assistant, [mcpToolCall, mcpToolResult]) }.AsOpenAIResponseItems().ToArray(); 1519var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, 1558var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Hello")); 1588var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, 1633var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Test")) 1656var chatResponse = new ChatResponse(new ChatMessage(inputRole, "Test")); 1994var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Test")) 2007var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Hello, world!")) 2032var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Test message")) 2082new(ChatRole.Assistant, "First message"), 2083new(ChatRole.Assistant, "Second message"), 2084new(ChatRole.Assistant, 2119new(ChatRole.Assistant, 2124new(ChatRole.Tool, [new FunctionResultContent("call-456", "The weather is sunny")]), 2125new(ChatRole.Assistant, "The weather in Seattle is sunny!") 2154new(ChatRole.System, "You are a helpful assistant."), 2155new(ChatRole.User, "Hello, how are you?"), 2156new(ChatRole.Assistant, "I'm doing well, thank you for asking!") 2181var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Default test")); 2199var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Model test")); 2214var chatResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "Model priority test"))
OpenAIResponseClientIntegrationTests.cs (12)
267List<ChatMessage> input = [new ChatMessage(ChatRole.User, "Tell me the path to the README.md file for Microsoft.Extensions.AI.Abstractions in the dotnet/extensions repository")]; 286var approvalResponse = new ChatMessage(ChatRole.Tool, 531List<ChatMessage> input = [new ChatMessage(ChatRole.User, "What is on my calendar for today?")]; 543input.Add(new ChatMessage(ChatRole.Tool, [approvalRequest.CreateResponse(true)])); 706List<ChatMessage> chatHistory = [new ChatMessage(ChatRole.User, "What is 2+2? Think step by step but be very brief.")]; 724chatHistory.Add(new ChatMessage(ChatRole.User, "What is 3+3?")); 743deserializedHistory.Add(new ChatMessage(ChatRole.User, "What is 4+4?")); 758deserializedHistory.Add(new ChatMessage(ChatRole.User, "What is 5+5?")); 787List<ChatMessage> chatHistory = [new ChatMessage(ChatRole.User, "What is 2+2? Think step by step but be very brief.")]; 805chatHistory.Add(new ChatMessage(ChatRole.User, "What is 3+3?")); 824deserializedHistory.Add(new ChatMessage(ChatRole.User, "What is 4+4?")); 839deserializedHistory.Add(new ChatMessage(ChatRole.User, "What is 5+5?"));
OpenAIResponseClientTests.cs (30)
648chatHistory.Add(new ChatMessage(ChatRole.User, "Are you sure?")); 897var response = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "Search the web for the temperature today in Fremont")], chatOptions); 993await foreach (var update in client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "Search the web for the temperature today in Fremont")], chatOptions)) 1617new ChatMessage(new ChatRole(role), [approvalRequest.CreateResponse(true)]), chatOptions); 1765new(new ChatRole(role), [anchorContent, codeInterpreterApproval, imageGenApproval]), 4822new ChatMessage(ChatRole.User, "test"), 4823new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call_123", new TextContent("Result text"))]) 4878new ChatMessage(ChatRole.User, "test"), 4879new ChatMessage(ChatRole.Tool, [ 4940new ChatMessage(ChatRole.User, "test"), 4941new ChatMessage(ChatRole.Tool, [ 4997new ChatMessage(ChatRole.User, "test"), 4998new ChatMessage(ChatRole.Tool, [ 5054new ChatMessage(ChatRole.User, "test"), 5055new ChatMessage(ChatRole.Tool, [ 5113new ChatMessage(ChatRole.User, "test"), 5114new ChatMessage(ChatRole.Tool, [ 5176new ChatMessage(ChatRole.User, "test"), 5177new ChatMessage(ChatRole.Tool, [ 5231new ChatMessage(ChatRole.User, "test"), 5232new ChatMessage(ChatRole.Tool, [ 5286new ChatMessage(ChatRole.User, "test"), 5287new ChatMessage(ChatRole.Tool, [ 5343new ChatMessage(ChatRole.User, "test"), 5344new ChatMessage(ChatRole.Tool, [ 5400new ChatMessage(ChatRole.User, "test"), 5401new ChatMessage(ChatRole.Tool, [ 5569new ChatMessage(ChatRole.User, [ 5819[new ChatMessage(ChatRole.User, "test")], 6128var response = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "")]);
Microsoft.Extensions.AI.Tests (789)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (22)
23var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, JsonContext2.Default.Animal))) 75var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 100var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, JsonContext2.Default.Options))) 136var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 161var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, JsonContext2.Default.Options))); 198new ChatMessage(ChatRole.Assistant, 203new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callid123", "result")]), 204new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, JsonContext2.Default.Options)) 239var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "This is not valid JSON")); 245var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 258var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "null")); 264var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 277var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, [new UriContent("https://example.com", "image/*")])); 283var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 297var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, JsonContext2.Default.Options))); 311var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 332var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(payload, JsonContext2.Default.Options))); 339var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 364var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, jso))); 401var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 425return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, resultDuplicatedJson))); 429var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\DistributedCachingChatClientTest.cs (12)
49new ChatMessage(new ChatRole("fakeRole"), "This is some content") 141return new ChatResponse(new ChatMessage(ChatRole.Assistant, "Hello")); 185var input = new ChatMessage(ChatRole.User, "abc"); 215return new ChatResponse(new ChatMessage(ChatRole.Assistant, "A good result")); 224var input = new ChatMessage(ChatRole.User, "abc"); 495var input = new ChatMessage(ChatRole.User, "abc"); 533var input = new ChatMessage(ChatRole.User, "abc"); 560return new(new ChatMessage(ChatRole.Assistant, options!.AdditionalProperties!["someKey"]!.ToString())); 611return new(new ChatMessage(ChatRole.Assistant, innerCallCount.ToString())); 657return new(new ChatMessage(ChatRole.Assistant, options!.AdditionalProperties!["someKey"]!.ToString())); 686new ChatMessage(new ChatRole("fakeRole"), 745new ChatMessage(ChatRole.Assistant, [new TextContent("Hey")])));
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (257)
36new ChatMessage(ChatRole.User, "hello"), 41new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 46new ChatMessage(ChatRole.Assistant, 72new ChatMessage(ChatRole.User, "hello"), 77new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 82new ChatMessage(ChatRole.Assistant, 119new ChatMessage(ChatRole.User, "hello"), 124new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 131new ChatMessage(ChatRole.Assistant, 169new ChatMessage(ChatRole.User, "hello"), 174new ChatMessage(ChatRole.Assistant, [ 182new ChatMessage(ChatRole.Assistant, 214new ChatMessage(ChatRole.User, "hello"), 219new ChatMessage(ChatRole.Assistant, [ 227new ChatMessage(ChatRole.Assistant, 256new ChatMessage(ChatRole.User, "hello"), 257new ChatMessage(ChatRole.Assistant, 262new ChatMessage(ChatRole.User, 271new ChatMessage(ChatRole.User, "hello"), 272new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 273new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 278new ChatMessage(ChatRole.Assistant, "world"), 283new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 284new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 285new ChatMessage(ChatRole.Assistant, "world"), 308new ChatMessage(ChatRole.User, "hello"), 309new ChatMessage(ChatRole.Assistant, 314new ChatMessage(ChatRole.User, 324new ChatMessage(ChatRole.User, "hello"), 325new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 326new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 331new ChatMessage(ChatRole.Assistant, "world"), 336new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 337new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 338new ChatMessage(ChatRole.Assistant, "world"), 360new ChatMessage(ChatRole.User, "hello"), 361new ChatMessage(ChatRole.Assistant, 365new ChatMessage(ChatRole.Assistant, 369new ChatMessage(ChatRole.User, 373new ChatMessage(ChatRole.User, 381new ChatMessage(ChatRole.User, "hello"), 382new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = "resp1" }, 383new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]) { MessageId = "resp2" }, 384new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 389new ChatMessage(ChatRole.Assistant, "world"), 394new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]) { MessageId = "resp1" }, 395new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]) { MessageId = "resp2" }, 396new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 397new ChatMessage(ChatRole.Assistant, "world"), 419new ChatMessage(ChatRole.User, "hello"), 420new ChatMessage(ChatRole.Assistant, 425new ChatMessage(ChatRole.User, 434new ChatMessage(ChatRole.User, "hello"), 435new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 436new ChatMessage(ChatRole.Tool, 445new ChatMessage(ChatRole.Assistant, "world"), 450new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 451new ChatMessage(ChatRole.Tool, 456new ChatMessage(ChatRole.Assistant, "world"), 478new ChatMessage(ChatRole.User, "hello"), 479new ChatMessage(ChatRole.Assistant, 484new ChatMessage(ChatRole.User, 493new ChatMessage(ChatRole.User, "hello"), 494new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 495new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Tool call invocation rejected.")]), 496new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 501new ChatMessage(ChatRole.Assistant, "world"), 506new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 507new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Tool call invocation rejected.")]), 508new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 509new ChatMessage(ChatRole.Assistant, "world"), 514new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 515new ChatMessage(ChatRole.Tool, 520new ChatMessage(ChatRole.Assistant, "world"), 542new ChatMessage(ChatRole.User, "hello"), 543new ChatMessage(ChatRole.Assistant, 548new ChatMessage(ChatRole.User, 563new ChatMessage(ChatRole.User, "hello"), 564new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 565new ChatMessage(ChatRole.Tool, 574new ChatMessage(ChatRole.Assistant, "world"), 579new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 580new ChatMessage(ChatRole.Tool, 585new ChatMessage(ChatRole.Assistant, "world"), 608new ChatMessage(ChatRole.User, "hello"), 609new ChatMessage(ChatRole.Assistant, 615new ChatMessage(ChatRole.User, 625new ChatMessage(ChatRole.User, "hello"), 626new ChatMessage(ChatRole.Assistant, 632new ChatMessage(ChatRole.Tool, 637new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Result 3: test")]), 642new ChatMessage(ChatRole.Assistant, "world"), 647new ChatMessage(ChatRole.Assistant, 653new ChatMessage(ChatRole.Tool, 658new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Result 3: test")]), 659new ChatMessage(ChatRole.Assistant, "world"), 664new ChatMessage(ChatRole.Assistant, 670new ChatMessage(ChatRole.Tool, 676new ChatMessage(ChatRole.Assistant, "world"), 700new ChatMessage(ChatRole.User, "hello"), 701new ChatMessage(ChatRole.Assistant, 705new ChatMessage(ChatRole.User, 716new ChatMessage(ChatRole.User, "hello"), 717new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 718new ChatMessage(ChatRole.Tool, 726new ChatMessage(ChatRole.Assistant, "world"), 731new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 732new ChatMessage(ChatRole.Tool, 736new ChatMessage(ChatRole.Assistant, "world"), 758new ChatMessage(ChatRole.User, "hello"), 759new ChatMessage(ChatRole.Assistant, 764new ChatMessage(ChatRole.User, 773new ChatMessage(ChatRole.User, "hello"), 774new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 775new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 780new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 3 } })]), 785new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 786new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 787new ChatMessage(ChatRole.Assistant, 812new ChatMessage(ChatRole.User, "hello"), 813new ChatMessage(ChatRole.Assistant, 818new ChatMessage(ChatRole.User, 823new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 824new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 825new ChatMessage(ChatRole.Assistant, 829new ChatMessage(ChatRole.User, 837new ChatMessage(ChatRole.User, "hello"), 838new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 839new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 840new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "Func1")]), 841new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Result 1")]), 846new ChatMessage(ChatRole.Assistant, "World"), 851new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "Func1")]), 852new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Result 1")]), 853new ChatMessage(ChatRole.Assistant, "World"), 891new ChatMessage(ChatRole.User, "hello"), 892new ChatMessage(ChatRole.Assistant, 896new ChatMessage(ChatRole.User, 905Task.FromResult(new ChatResponse([new ChatMessage(ChatRole.Assistant, "world")])), 907YieldAsync(new ChatResponse([new ChatMessage(ChatRole.Assistant, "world")]).ToChatResponseUpdates()), 963new ChatMessage(ChatRole.User, "hello"), 964new ChatMessage(ChatRole.Assistant, 968new ChatMessage(ChatRole.User, 972new ChatMessage(ChatRole.Assistant, 976new ChatMessage(ChatRole.User, 985Task.FromResult(new ChatResponse([new ChatMessage(ChatRole.Assistant, "world")])), 987YieldAsync(new ChatResponse([new ChatMessage(ChatRole.Assistant, "world")]).ToChatResponseUpdates()), 1028new ChatMessage(ChatRole.User, "hello"), 1035new ChatMessage(ChatRole.User, "hello"), 1039new ChatMessage(ChatRole.User, "hello"), 1040new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 1041new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]) 1049new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 1053new ChatMessage(ChatRole.Assistant, "World again"), 1059new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 1060new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 1061new ChatMessage(ChatRole.Assistant, "World again"), 1083new ChatMessage(ChatRole.User, "hello"), 1084new ChatMessage(ChatRole.Assistant, 1113new ChatMessage(ChatRole.User, "hello"), 1114new ChatMessage(ChatRole.User, 1123new ChatMessage(ChatRole.User, "hello"), 1124new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 1125new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 1130new ChatMessage(ChatRole.Assistant, "world"), 1135new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 1136new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 1137new ChatMessage(ChatRole.Assistant, "world"), 1160new ChatMessage(ChatRole.User, 1169new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 1174new ChatMessage(ChatRole.Assistant, "world"), 1179new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 1180new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1"), new FunctionResultContent("callId2", result: "Result 2: 42")]), 1181new ChatMessage(ChatRole.Assistant, "world"), 1204new ChatMessage(ChatRole.User, 1210new ChatMessage(ChatRole.User, "By the way, please keep the answer concise."), 1217new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1218new ChatMessage(ChatRole.User, "By the way, please keep the answer concise."), 1223new ChatMessage(ChatRole.Assistant, "world"), 1228new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1229new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1230new ChatMessage(ChatRole.Assistant, "world"), 1254new ChatMessage(ChatRole.User, 1265new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1266new ChatMessage(ChatRole.User, "please proceed"), 1271new ChatMessage(ChatRole.Assistant, "world"), 1276new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1277new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1278new ChatMessage(ChatRole.Assistant, "world"), 1299new ChatMessage(ChatRole.User, "hello"), 1300new ChatMessage(ChatRole.Assistant, 1304new ChatMessage(ChatRole.User, 1310new ChatMessage(ChatRole.User, "By the way, please keep the answer concise."), 1317new ChatMessage(ChatRole.User, "hello"), 1318new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1319new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1320new ChatMessage(ChatRole.User, "By the way, please keep the answer concise."), 1325new ChatMessage(ChatRole.Assistant, "world"), 1330new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1331new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1332new ChatMessage(ChatRole.Assistant, "world"), 1354new ChatMessage(ChatRole.User, "hello"), 1355new ChatMessage(ChatRole.Assistant, 1359new ChatMessage(ChatRole.User, 1368new ChatMessage(ChatRole.User, "hello"), 1369new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1370new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1371new ChatMessage(ChatRole.User, "please proceed"), 1376new ChatMessage(ChatRole.Assistant, "world"), 1381new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1382new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1383new ChatMessage(ChatRole.Assistant, "world"), 1412new ChatMessage(ChatRole.User, "hello"), 1413new ChatMessage(ChatRole.Assistant, 1417new ChatMessage(ChatRole.User, 1425new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1426new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1467List<ChatMessage> input = [new ChatMessage(ChatRole.User, "hello")]; 1543List<ChatMessage> input = [new ChatMessage(ChatRole.User, "hello")]; 1641List<ChatMessage> input = [new ChatMessage(ChatRole.User, "hello")]; 1647new ChatMessage(ChatRole.Assistant, [alreadyProcessedFunctionCall]), 1653new ChatMessage(ChatRole.Assistant, [alreadyProcessedFunctionCall]), 1685new ChatMessage(ChatRole.User, "hello"), 1686new ChatMessage(ChatRole.Assistant, 1690new ChatMessage(ChatRole.User, 1698new ChatMessage(ChatRole.Assistant, "world"), 1704new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("function-call-id", "Func1")]) { MessageId = OriginalMessageId }, 1705new ChatMessage(ChatRole.Tool, [new FunctionResultContent("function-call-id", result: "Result 1")]), 1706new ChatMessage(ChatRole.Assistant, "world"), 1736new ChatMessage(ChatRole.User, "hello"), 1741new ChatMessage(ChatRole.Assistant, 1750new ChatMessage(ChatRole.Assistant, 1779new ChatMessage(ChatRole.User, "hello"), 1780new ChatMessage(ChatRole.Assistant, 1785new ChatMessage(ChatRole.User, 1794new ChatMessage(ChatRole.User, "hello"), 1795new ChatMessage(ChatRole.Assistant, 1799new ChatMessage(ChatRole.Assistant, 1803new ChatMessage(ChatRole.Tool, 1807new ChatMessage(ChatRole.User, 1815new ChatMessage(ChatRole.Assistant, [ 1823new ChatMessage(ChatRole.Assistant, 1827new ChatMessage(ChatRole.Tool, 1831new ChatMessage(ChatRole.Assistant, [ 1863new ChatMessage(ChatRole.User, "hello"), 1864new ChatMessage(ChatRole.Assistant, 1869new ChatMessage(ChatRole.User, 1877new ChatMessage(ChatRole.User, "hello"), 1878new ChatMessage(ChatRole.Assistant, 1882new ChatMessage(ChatRole.Assistant, 1886new ChatMessage(ChatRole.Tool, 1892new ChatMessage(ChatRole.User, 1900new ChatMessage(ChatRole.Assistant, [ 1909new ChatMessage(ChatRole.Assistant, 1913new ChatMessage(ChatRole.Tool, 1919new ChatMessage(ChatRole.Assistant, [ 2090input.Select(m => new ChatMessage(m.Role, m.Contents.Select(CloneFcc).ToList()) { MessageId = m.MessageId }).ToList();
ChatCompletion\FunctionInvokingChatClientTests.cs (290)
93new ChatMessage(ChatRole.User, "hello"), 94new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 95new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 96new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 97new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 98new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 99new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Success: Function completed.")]), 100new ChatMessage(ChatRole.Assistant, "world"), 127new ChatMessage(ChatRole.User, "hello"), 128new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 129new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 130new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 131new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 132new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 133new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Success: Function completed.")]), 134new ChatMessage(ChatRole.Assistant, "world"), 160new ChatMessage(ChatRole.User, "hello"), 161new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 162new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 163new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 164new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 165new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 166new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Success: Function completed.")]), 167new ChatMessage(ChatRole.Assistant, "world"), 191new ChatMessage(ChatRole.User, "hello"), 192new ChatMessage(ChatRole.Assistant, 198new ChatMessage(ChatRole.Tool, 204new ChatMessage(ChatRole.Assistant, 209new ChatMessage(ChatRole.Tool, 214new ChatMessage(ChatRole.Assistant, "world"), 251new ChatMessage(ChatRole.User, "hello"), 252new ChatMessage(ChatRole.Assistant, 257new ChatMessage(ChatRole.Tool, 262new ChatMessage(ChatRole.Assistant, "done"), 295new ChatMessage(ChatRole.User, "hello"), 296new ChatMessage(ChatRole.Assistant, 301new ChatMessage(ChatRole.Tool, 306new ChatMessage(ChatRole.Assistant, "done"), 329new ChatMessage(ChatRole.User, "hello"), 330new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 331new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1 from delegate")]), 332new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 333new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42 from delegate")]), 334new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } })]), 335new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Success: Function completed.")]), 336new ChatMessage(ChatRole.Assistant, "world"), 380new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]))); 384return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "done"))); 393new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])).ToChatResponseUpdates()); 397return YieldAsync(new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")).ToChatResponseUpdates()); 416new ChatMessage(ChatRole.User, "hello"), 461new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]))); 465return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "done"))); 474new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])).ToChatResponseUpdates()); 478return YieldAsync(new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")).ToChatResponseUpdates()); 495new ChatMessage(ChatRole.User, "hello"), 542new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]))); 546return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "done"))); 555new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])).ToChatResponseUpdates()); 559return YieldAsync(new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")).ToChatResponseUpdates()); 579new ChatMessage(ChatRole.User, "hello"), 636new ChatMessage(ChatRole.User, "hello"), 637new ChatMessage(ChatRole.Assistant, [new FunctionCallContent($"callId0", "VoidReturn")]), 644plan.Add(new ChatMessage(ChatRole.Tool, [new FunctionResultContent($"callId{i}", result: "Success: Function completed.")])); 645plan.Add(new ChatMessage(ChatRole.Assistant, [new FunctionCallContent($"callId{(i + 1)}", "VoidReturn")])); 668var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent($"callId{capturedOptions.Count}", "Func1")]); 712var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent($"callId{capturedOptions.Count}", "Func1")]); 759var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]); 764var message = new ChatMessage(ChatRole.Assistant, "Done"); 804var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]); 858new ChatMessage(ChatRole.User, "hello"), 936new ChatMessage(ChatRole.User, "hello"), 953var assistantMessage = new ChatMessage(ChatRole.Assistant, []); 954var toolMessage = new ChatMessage(ChatRole.Tool, []); 983new ChatMessage(ChatRole.User, "hello"), 984new ChatMessage(ChatRole.Assistant, [new TextContent("extra"), new FunctionCallContent("callId1", "Func1"), new TextContent("stuff")]), 985new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 1")]), 986new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func2", arguments: new Dictionary<string, object?> { { "i", 42 } })]), 987new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 2: 42")]), 988new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "VoidReturn", arguments: new Dictionary<string, object?> { { "i", 43 } }), new TextContent("more")]), 989new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Success: Function completed.")]), 990new ChatMessage(ChatRole.Assistant, "world"), 1020new ChatMessage(ChatRole.User, "hello"), 1021new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1022new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: detailedErrors ? "Error: Function failed. Exception: Oh no!" : "Error: Function failed.")]), 1023new ChatMessage(ChatRole.Assistant, "world"), 1042new ChatMessage(ChatRole.User, "hello"), 1043new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["arg1"] = "value1" })]), 1044new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1045new ChatMessage(ChatRole.Assistant, "world"), 1099new ChatMessage(ChatRole.User, "hello"), 1100new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["arg1"] = "value1" })]), 1101new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1102new ChatMessage(ChatRole.Assistant, "world"), 1177new(ChatRole.User, "Hello"), 1235new(ChatRole.User, "Hello"), 1245new(ChatRole.Assistant, [new FunctionCallContent($"callId{chatContents.Count()}", "Func1")]) : 1246new(ChatRole.Assistant, "The answer is 42."); 1293new ChatMessage(ChatRole.User, "hello"), 1294new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["i"] = 41 })]), 1295new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 41")]), 1296new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId2", "Func1", new Dictionary<string, object?> { ["i"] = 42 })]), 1297new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId2", result: "Result 42")]), 1304new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId3", "Func1", new Dictionary<string, object?> { ["i"] = 43 })]), 1305new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId3", result: "Result 43")]), 1306new ChatMessage(ChatRole.Assistant, "world"), 1369var message = new ChatMessage(ChatRole.Assistant, resultContents); 1377List<ChatMessage> messages = [new(ChatRole.User, "hello")]; 1412return new ChatResponse(new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId-abc", "Func1")])) 1420return new ChatResponse(new ChatMessage(ChatRole.Assistant, "done!")); 1449new ChatMessage(ChatRole.User, "hello"), 1450new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["arg1"] = "value1" })]), 1451new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1452new ChatMessage(ChatRole.Assistant, "world"), 1478new ChatMessage(ChatRole.User, "hello"), 1479new ChatMessage(ChatRole.Assistant, [ 1483new ChatMessage(ChatRole.Tool, 1488new ChatMessage(ChatRole.Assistant, "world"), 1531new(ChatRole.User, "hello"), 1532new(ChatRole.Assistant, [ 1536new(ChatRole.Tool, [ 1540new(ChatRole.Assistant, "done"), 1550new(ChatRole.User, "hello"), 1551new(ChatRole.Assistant, [ 1555new(ChatRole.Tool, [ 1559new(ChatRole.Assistant, "done"), 1579new(ChatRole.User, "hello"), 1580new(ChatRole.Assistant, [new FunctionCallContent("callId1", "DefOnly")]), 1581new(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Should not be produced")]), 1582new(ChatRole.Assistant, "world"), 1608new(ChatRole.User, "hi"), 1609new(ChatRole.Assistant, [ 1613new(ChatRole.Tool, [new FunctionResultContent("callId1", result: "OK"), new FunctionResultContent("callId2", result: "nope")]), 1614new(ChatRole.Assistant, "done"), 1645messages.Add(new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])); 1681new ChatMessage(ChatRole.User, "hello"), 1682new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1683new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1684new ChatMessage(ChatRole.Assistant, "world"), 1741? new(ChatRole.Assistant, [new FunctionCallContent("call1", "Func1")]) 1742: new(ChatRole.Assistant, "Done"); 1762[new ChatMessage(ChatRole.User, "hello")], options)) 1792new ChatMessage(ChatRole.User, "hello"), 1793new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1794new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1795new ChatMessage(ChatRole.Assistant, "world"), 1834new ChatMessage(ChatRole.User, "hello"), 1835new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1836new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1837new ChatMessage(ChatRole.Assistant, "world"), 1884new ChatMessage(ChatRole.User, "hello"), 1885new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1", new Dictionary<string, object?> { ["arg1"] = "secret" })]), 1886new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1887new ChatMessage(ChatRole.Assistant, "world"), 1956new ChatMessage(ChatRole.User, "hello"), 1957new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 1958new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 1959new ChatMessage(ChatRole.Assistant, "world"), 2005new ChatMessage(ChatRole.User, "hello"), 2006new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 2007new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Result 1")]), 2008new ChatMessage(ChatRole.Assistant, "world"), 2042var message = new ChatMessage(ChatRole.Assistant, [alreadyProcessedFunctionCall]); 2048var message = new ChatMessage(ChatRole.Assistant, [alreadyProcessedFunctionCall]); 2056? await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "hello")], options).ToChatResponseAsync() 2057: await client.GetResponseAsync([new ChatMessage(ChatRole.User, "hello")], options); 2097var message = new ChatMessage(ChatRole.Assistant, [needsProcessing, alreadyProcessed]); 2103var message = new ChatMessage(ChatRole.Assistant, "done"); 2112var message = new ChatMessage(ChatRole.Assistant, [needsProcessing, alreadyProcessed]); 2118var message = new ChatMessage(ChatRole.Assistant, "done"); 2127? await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "hello")], options).ToChatResponseAsync() 2128: await client.GetResponseAsync([new ChatMessage(ChatRole.User, "hello")], options); 2161return new ChatResponse(new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])); 2165return new ChatResponse(new ChatMessage(ChatRole.Assistant, "Done")); 2174var response = await client2.GetResponseAsync([new ChatMessage(ChatRole.User, "hello")], options); 2224var message = new ChatMessage(ChatRole.Assistant, CloneContents(plan[contents.Count()].Contents)) 2288ChatMessage message = new(ChatRole.Assistant, CloneContents(plan[contents.Count()].Contents)) 2388return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2395return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2401return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2411message = new ChatMessage(ChatRole.Assistant, 2417message = new ChatMessage(ChatRole.Assistant, 2422message = new ChatMessage(ChatRole.Assistant, "Done"); 2433var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 2438var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 2482return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2489return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2495return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2505message = new ChatMessage(ChatRole.Assistant, 2511message = new ChatMessage(ChatRole.Assistant, 2516message = new ChatMessage(ChatRole.Assistant, "Done"); 2527var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 2536var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 2589return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2595return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2600return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2610message = new ChatMessage(ChatRole.Assistant, 2616message = new ChatMessage(ChatRole.Assistant, 2621message = new ChatMessage(ChatRole.Assistant, "Done"); 2632var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 2642var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 2687return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2695return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2701return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2711message = new ChatMessage(ChatRole.Assistant, 2717message = new ChatMessage(ChatRole.Assistant, 2723message = new ChatMessage(ChatRole.Assistant, "Done"); 2737var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 2745var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 2791return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2797return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2802return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2812message = new ChatMessage(ChatRole.Assistant, 2818message = new ChatMessage(ChatRole.Assistant, 2823message = new ChatMessage(ChatRole.Assistant, "Done"); 2837var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 2847var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 2889return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2894return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2904message = new ChatMessage(ChatRole.Assistant, 2909message = new ChatMessage(ChatRole.Assistant, "Done"); 2920var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 2925var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 2967return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2975return new ChatResponse([new ChatMessage(ChatRole.Assistant, 2980return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 2990message = new ChatMessage(ChatRole.Assistant, 2996message = new ChatMessage(ChatRole.Assistant, 3001message = new ChatMessage(ChatRole.Assistant, "Done"); 3012var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 3021var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 3068return new ChatResponse([new ChatMessage(ChatRole.Assistant, 3076return new ChatResponse([new ChatMessage(ChatRole.Assistant, 3081return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 3091message = new ChatMessage(ChatRole.Assistant, 3097message = new ChatMessage(ChatRole.Assistant, 3102message = new ChatMessage(ChatRole.Assistant, "Done"); 3113var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 3123var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 3174return new ChatResponse([new ChatMessage(ChatRole.Assistant, 3182return new ChatResponse([new ChatMessage(ChatRole.Assistant, 3187return new ChatResponse([new ChatMessage(ChatRole.Assistant, "Done")]); 3197message = new ChatMessage(ChatRole.Assistant, 3203message = new ChatMessage(ChatRole.Assistant, 3208message = new ChatMessage(ChatRole.Assistant, "Done"); 3219var result = await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "test")], options).ToChatResponseAsync(); 3230var result = await client.GetResponseAsync([new ChatMessage(ChatRole.User, "test")], options); 3257new ChatMessage(ChatRole.User, "hello"), 3258new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "UnknownFunc")]), 3259new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Error: Requested function \"UnknownFunc\" not found.")]), 3260new ChatMessage(ChatRole.Assistant, "world"), 3287new ChatMessage(ChatRole.User, "hello"), 3288new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 3289new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Should not be produced")]), 3290new ChatMessage(ChatRole.Assistant, "world"), 3323new ChatMessage(ChatRole.User, "hello"), 3324new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "TerminatingFunc")]), 3325new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", result: "Terminated")]), 3352new ChatMessage(ChatRole.User, "hello"), 3353new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 3359new ChatMessage(ChatRole.User, "hello"), 3360new ChatMessage(ChatRole.Assistant, 3386Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "world"))) 3395new ChatMessage(ChatRole.User, "hello"), 3396new ChatMessage(ChatRole.Assistant, 3400new ChatMessage(ChatRole.User, 3423Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "world"))) 3432new ChatMessage(ChatRole.User, "hello"), 3433new ChatMessage(ChatRole.Assistant, 3437new ChatMessage(ChatRole.User, 3474new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 3475new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Server Result")]), 3482new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]), 3483new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Server Result")]), 3492? await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "hello")], options).ToChatResponseAsync() 3493: await client.GetResponseAsync([new ChatMessage(ChatRole.User, "hello")], options); 3538new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2")]), 3539new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Server Result 1")]), 3544return new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")); 3553new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1"), new FunctionCallContent("callId2", "Func2")]), 3554new ChatMessage(ChatRole.Tool, [new FunctionResultContent("callId1", "Server Result 1")]), 3560var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")); 3569? await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "hello")], options).ToChatResponseAsync() 3570: await client.GetResponseAsync([new ChatMessage(ChatRole.User, "hello")], options); 3607return new ChatResponse(new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])); 3611return new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")); 3618var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")])); 3623var response = new ChatResponse(new ChatMessage(ChatRole.Assistant, "done")); 3632? await client.GetStreamingResponseAsync([new ChatMessage(ChatRole.User, "hello")], options).ToChatResponseAsync() 3633: await client.GetResponseAsync([new ChatMessage(ChatRole.User, "hello")], options);
ChatCompletion\ImageGeneratingChatClientTests.cs (17)
39return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "test response"))); 52var response = await client.GetResponseAsync([new(ChatRole.User, "test")], chatOptions); 76return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "test response"))); 89var response = await client.GetResponseAsync([new(ChatRole.User, "test")], chatOptions); 123return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "test response"))); 137var response = await client.GetResponseAsync([new(ChatRole.User, "test")], chatOptions); 241await foreach (var update in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions)) 261return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "test response"))); 269var response = await client.GetResponseAsync([new(ChatRole.User, "test")], null); 284return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "test response"))); 297await client.GetResponseAsync([new(ChatRole.User, "test")], chatOptions); 316var responseMessage = new ChatMessage(ChatRole.Assistant, 331var response = await client.GetResponseAsync([new(ChatRole.User, "test")], chatOptions); 373await foreach (var responseUpdate in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions)) 413return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, contents))); 426var response = await client.GetResponseAsync([new(ChatRole.User, "test")], chatOptions); 501await foreach (var update in client.GetStreamingResponseAsync([new(ChatRole.User, "test")], chatOptions))
ChatCompletion\LoggingChatClientTests.cs (3)
59return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "blue whale"))); 69[new(ChatRole.User, "What's the biggest animal?")], 118[new(ChatRole.User, "What's the biggest animal?")],
ChatCompletion\OpenTelemetryChatClientTests.cs (24)
41return new ChatResponse(new ChatMessage(ChatRole.Assistant, "The blue whale, I think.")) 114new(ChatRole.System, "You are a close friend."), 115new(ChatRole.User, "Hey!") { AuthorName = "Alice" }, 116new(ChatRole.Assistant, [new FunctionCallContent("12345", "GetPersonName")]), 117new(ChatRole.Tool, [new FunctionResultContent("12345", "John")]), 118new(ChatRole.Assistant, "Hey John, what's up?") { AuthorName = "BotAssistant" }, 119new(ChatRole.User, "What's the biggest animal?") 404return new ChatResponse(new ChatMessage(ChatRole.Assistant, 442new(ChatRole.User, 450new(ChatRole.Assistant, [new FunctionCallContent("call-456", "SearchFiles")]), 451new(ChatRole.Tool, [new FunctionResultContent("call-456", "Found 3 files")]), 588return new ChatResponse(new ChatMessage(ChatRole.Assistant, "The blue whale, I think.")); 603new(ChatRole.User, 658return new ChatResponse(new ChatMessage(ChatRole.Assistant, 705new(ChatRole.User, "Execute code and generate an image"), 823return new ChatResponse(new ChatMessage(ChatRole.Assistant, "Done")); 843new(ChatRole.Assistant, 847new(ChatRole.User, 932await foreach (var update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")], new ChatOptions { ModelId = "mymodel" })) 980return new ChatResponse(new ChatMessage(ChatRole.Assistant, "Response")); 992await chatClient.GetResponseAsync([new(ChatRole.User, "Hello")]); 1037await foreach (var update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")])) 1046chatClient.GetResponseAsync([new(ChatRole.User, "Hello")])); 1091await foreach (var update in chatClient.GetStreamingResponseAsync([new(ChatRole.User, "Hello")]))
ChatCompletion\ReducingChatClientTests.cs (9)
37new(ChatRole.System, "You are a helpful assistant"), 38new(ChatRole.User, "Hello"), 39new(ChatRole.Assistant, "Hi there!"), 40new(ChatRole.User, "What's the weather?") 45new(ChatRole.System, "You are a helpful assistant"), 46new(ChatRole.User, "What's the weather?") 50var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "It's sunny!")); 98var reducedMessages = new List<ChatMessage> { new(ChatRole.User, "Reduced message") }; 119await client.GetResponseAsync(new List<ChatMessage> { new(ChatRole.User, "Original message") });
ChatCompletion\UseDelegateChatClientTests.cs (3)
42return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "hello"))); 91return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "hello"))); 184return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "non-streaming hello")));
ChatReduction\MessageCountingChatReducerTests.cs (28)
53new ChatMessage(ChatRole.System, "You are a helpful assistant."), 54new ChatMessage(ChatRole.User, "Hello"), 55new ChatMessage(ChatRole.Assistant, "Hi there!"), 56new ChatMessage(ChatRole.User, "How are you?"), 57new ChatMessage(ChatRole.Assistant, "I'm doing well, thanks!"), 88new ChatMessage(ChatRole.System, "First system message"), 89new ChatMessage(ChatRole.User, "Hello"), 90new ChatMessage(ChatRole.System, "Second system message"), 91new ChatMessage(ChatRole.Assistant, "Hi"), 92new ChatMessage(ChatRole.User, "How are you?"), 93new ChatMessage(ChatRole.Assistant, "I'm fine!"), 127new ChatMessage(ChatRole.User, "What's the weather?"), 128new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call1", "get_weather", new Dictionary<string, object?> { ["location"] = "Seattle" })]), 129new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call1", "Sunny, 72°F")]), 130new ChatMessage(ChatRole.Assistant, "The weather in Seattle is sunny and 72°F."), 131new ChatMessage(ChatRole.User, "Thanks!"), 132new ChatMessage(ChatRole.Assistant, "You're welcome!"), 167messages.Add(new ChatMessage(i % 2 == 0 ? ChatRole.User : ChatRole.Assistant, $"Message {i}")); 202new ChatMessage(ChatRole.System, "System prompt"), 223new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call1", "func", null)]), 224new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call1", "result")]), 225new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call2", "func", null)]), 226new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call2", "result")]), 241new ChatMessage(ChatRole.System, "System"), 242new ChatMessage(ChatRole.User, "First"), 243new ChatMessage(ChatRole.Assistant, "Second"), 244new ChatMessage(ChatRole.User, "Third"), 245new ChatMessage(ChatRole.Assistant, "Fourth"),
ChatReduction\SummarizingChatReducerTests.cs (51)
69new ChatMessage(ChatRole.System, "You are a helpful assistant."), 70new ChatMessage(ChatRole.User, "Hello"), 71new ChatMessage(ChatRole.Assistant, "Hi there!"), 72new ChatMessage(ChatRole.User, "How are you?"), 76Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Summary of conversation"))); 96new ChatMessage(ChatRole.User, "What's the time?"), 97new ChatMessage(ChatRole.Assistant, "Let me check"), 98new ChatMessage(ChatRole.User, "What's the weather?"), 99new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call1", "get_weather"), new TestInputRequestContent("uir1")]), 100new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call1", "Sunny")]), 101new ChatMessage(ChatRole.User, [new TestInputResponseContent("uir1")]), 102new ChatMessage(ChatRole.Assistant, "It's sunny"), 108return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Asked about time"))); 141new ChatMessage(ChatRole.User, "First question"), 142new ChatMessage(ChatRole.Assistant, "First answer"), 143new ChatMessage(ChatRole.User, "Second question"), 144new ChatMessage(ChatRole.Assistant, "Second answer"), 145new ChatMessage(ChatRole.User, "Third question"), 146new ChatMessage(ChatRole.Assistant, "Third answer"), 156return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Summary of first exchange"))); 187new ChatMessage(ChatRole.User, "What's the weather in Seattle?"), 188new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call1", "get_weather", new Dictionary<string, object?> { ["location"] = "Seattle" }), new TestInputRequestContent("uir2")]), 189new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call1", "Sunny, 72°F")]), 190new ChatMessage(ChatRole.User, [new TestInputResponseContent("uir2")]), 191new ChatMessage(ChatRole.Assistant, "It's sunny and 72°F in Seattle."), 192new ChatMessage(ChatRole.User, "What about New York?"), 193new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call2", "get_weather", new Dictionary<string, object?> { ["location"] = "New York" })]), 194new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call2", "Rainy, 65°F")]), 195new ChatMessage(ChatRole.Assistant, "It's rainy and 65°F in New York."), 209return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "User asked about weather in Seattle and New York."))); 242messages.Add(new ChatMessage(ChatRole.Assistant, $"Message {i}")); 249return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Summary"))); 276new ChatMessage(ChatRole.User, "Message 1"), 277new ChatMessage(ChatRole.Assistant, "Response 1"), 278new ChatMessage(ChatRole.User, "Message 2"), 287return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Summary"))); 302new ChatMessage(ChatRole.System, "First system message"), 303new ChatMessage(ChatRole.User, "Hello"), 304new ChatMessage(ChatRole.System, "Second system message"), 305new ChatMessage(ChatRole.Assistant, "Hi"), 306new ChatMessage(ChatRole.User, "How are you?"), 310Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "Summary"))); 330new ChatMessage(ChatRole.User, "Hi there! Can you tell me about golden retrievers?"), 331new 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."), 332new ChatMessage(ChatRole.User, "What kind of exercise do they need?"), 333new 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."), 334new ChatMessage(ChatRole.User, "Are they good with kids?"), 350return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, Summary))); 361messages.Add(new ChatMessage(ChatRole.Assistant, "Golden retrievers get along well with kids! They're able to be playful and energetic while remaining gentle.")); 362messages.Add(new ChatMessage(ChatRole.User, "Do they make good lap dogs?")); 377return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, Summary)));
ChatRouting\FailoverChatClientTests.cs (45)
58? router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync() 59: router.GetResponseAsync([new(ChatRole.User, "hi")]); 83[new(ChatRole.User, "hi")], 86[new(ChatRole.User, "hi")], 106? router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync() 107: router.GetResponseAsync([new(ChatRole.User, "hi")]); 134() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 165() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 196() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 225_ = await router.GetResponseAsync([new(ChatRole.User, "hi")], requestOptions); 257ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 276? await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")], requestOptions).ToChatResponseAsync() 277: await router.GetResponseAsync([new(ChatRole.User, "hi")], requestOptions); 303return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "ok"))); 323? await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")], requestOptions).ToChatResponseAsync() 324: await router.GetResponseAsync([new(ChatRole.User, "hi")], requestOptions); 352() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 367ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 395ChatResponse response = await router.GetResponseAsync([new(ChatRole.User, "hi")]); 423_ = await router.GetResponseAsync([new(ChatRole.User, "hi")]); 432ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 446ChatResponse response = await router.GetResponseAsync([new(ChatRole.User, "hi")]); 474() => router.GetResponseAsync([new(ChatRole.User, "hi")])); 502ChatResponse? response = await router.GetResponseAsync([new(ChatRole.User, "hi")]); 529[new(ChatRole.User, "hi")], 557[new(ChatRole.User, "hi")], 590[new(ChatRole.User, "hi")], 628() => CollectAsync(router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]))); 652await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 686[new(ChatRole.User, "hi")], 730[new(ChatRole.User, "hi")], 743ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 758ChatResponse response = await client.GetResponseAsync([new(ChatRole.User, "hi")]); 783await client.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 811await client.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 839() => CollectAsync(router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]))); 862await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 885await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 916await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 955[new(ChatRole.User, "hi")], 1004await router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 1042await foreach (ChatResponseUpdate update in router.GetStreamingResponseAsync([new(ChatRole.User, "hi")])) 1080await CollectAsync(router.GetStreamingResponseAsync([new(ChatRole.User, "hi")])); 1111await CollectAsync(router.GetStreamingResponseAsync([new(ChatRole.User, "hi")])); 1135await ConsumeOneAsync(router.GetStreamingResponseAsync([new(ChatRole.User, "hi")]));
ChatRouting\OrderedFailoverChatClientTests.cs (17)
38ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 49ChatResponse response = await client.GetResponseAsync([new(ChatRole.User, "hi")]); 59ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 80ChatResponse response = await client.GetResponseAsync([new(ChatRole.User, "hi")]); 101() => client.GetResponseAsync([new(ChatRole.User, "hi")])); 121() => client.GetResponseAsync([new(ChatRole.User, "hi")])); 144_ = await client.GetResponseAsync([new(ChatRole.User, "one")]); 145_ = await client.GetResponseAsync([new(ChatRole.User, "two")]); 183client.GetResponseAsync([new(ChatRole.User, index.ToString())])), 205client.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).GetAsyncEnumerator()) 217ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 226ChatResponse response = await failover.GetResponseAsync([new(ChatRole.User, "hi")]); 262[new(ChatRole.User, "hi")], 288await client.GetStreamingResponseAsync([new(ChatRole.User, "hi")]).ToChatResponseAsync(); 315[new(ChatRole.User, "hi")], 354ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "ok")); 362ChatResponse response = await outer.GetResponseAsync([new(ChatRole.User, "hi")]);
ChatRouting\SemanticRoutingChatClientTests.cs (10)
97ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "code")); 105Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "writing"))), 118ChatResponse first = await router.GetResponseAsync([new(ChatRole.User, "debug this code")]); 119ChatResponse second = await router.GetResponseAsync([new(ChatRole.User, "debug this code")]); 149Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "code"))), 154Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "writing"))), 170ChatResponse response = await router.GetResponseAsync([new(ChatRole.User, "query")]); 192Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "profiled"))), 194ChatResponse expected = new(new ChatMessage(ChatRole.Assistant, "default")); 211await router.GetResponseAsync([new(ChatRole.User, "unrelated query")]);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.ChatMessage.g.cs (1)
31ObjectCreator = () => new global::Microsoft.Extensions.AI.ChatMessage(),
Microsoft.Extensions.DataIngestion (7)
Processors\ClassificationEnricher.cs (1)
97return new(ChatRole.System, sb.ToString());
Processors\ImageAlternativeTextEnricher.cs (2)
31_systemPrompt = new(ChatRole.System, "For each of the following images, write a detailed alternative text with fewer than 50 words."); 99[_systemPrompt, new(ChatRole.User, contents)],
Processors\KeywordEnricher.cs (1)
107return new(ChatRole.System, sb.ToString());
Processors\SentimentEnricher.cs (1)
40_systemPrompt = new(ChatRole.System, prompt);
Processors\SummaryEnricher.cs (1)
35_systemPrompt = new(ChatRole.System, $"For each of the following texts, write a summary text with no more than {wordCount} words.");
Utils\Batching.cs (1)
41new(ChatRole.User, contents)
Microsoft.Extensions.DataIngestion.Tests (6)
Processors\AlternativeTextEnricherTests.cs (2)
61new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(new Envelope<string[]> { data = descriptions })) 147return Task.FromResult(new ChatResponse(new[] { new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(data)) }));
Processors\ClassificationEnricherTests.cs (1)
84new ChatMessage(ChatRole.Assistant, response)
Processors\KeywordEnricherTests.cs (1)
84new ChatMessage(ChatRole.Assistant, response)
Processors\SentimentEnricherTests.cs (1)
68new ChatMessage(ChatRole.Assistant, response)
Processors\SummaryEnricherTests.cs (1)
68new ChatMessage(ChatRole.Assistant, response)
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
47var chatMessage = new ChatMessage(ChatRole.Assistant, output);
Microsoft.ML.GenAI.Core.Tests (3)
CausalLMDatasetTest.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);
1333 references to ChatMessage
Aspire.Azure.AI.OpenAI.Tests (1)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (1)
220static Task<ChatResponse> TestMiddleware(IEnumerable<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
Aspire.Dashboard (48)
Model\Assistant\AIHelpers.cs (4)
296List<ChatMessage> chatMessages, 298Func<IList<ChatMessage>, Task> onMessageCallback, 351public static IList<ChatMessage> GetMessages(ChatResponseUpdate update, Func<AIContent, bool>? filter = null) 356var list = new List<ChatMessage>();
Model\Assistant\AssistantChatViewModel.cs (8)
82public List<ChatMessage> ChatMessages { get; } = new(); 512List<ChatMessage> chatMessages; 553List<ChatMessage>? followUpMessages = null; 570var assistantMessage = new ChatMessage(ChatRole.Assistant, responseText.ToString()); 607var assistantMessage = new ChatMessage(ChatRole.Assistant, responseText.ToString()); 712void AddChatMessages(IList<ChatMessage> messages) 716foreach (var message in messages) 724private async Task UpdateFollowUpPromptsAsync(List<ChatMessage>? followUpMessages, CancellationTokenSource responseCts)
Model\Assistant\ChatViewModel.cs (10)
40public IEnumerable<ChatMessage> GetChatMessages() 48public void AddChatMessage(ChatMessage chatMessage) 53public void AddChatMessage(Func<ChatMessage> chatMessageProvider) 87public abstract ChatMessage GetChatMessage(); 92private readonly Func<ChatMessage> _chatMessageProvider; 94public DynamicChatMessageViewModel(Func<ChatMessage> chatMessageProvider) 99public override ChatMessage GetChatMessage() 107private readonly ChatMessage _chatMessage; 109public StaticChatMessageViewModel(ChatMessage chatMessage) 114public override ChatMessage GetChatMessage()
Model\Assistant\InitialPrompt.cs (1)
11public InitialPrompt(Icon icon, string buttonTitle, string buttonDescription, string chatDisplayText, ChatMessage promptMessage)
Model\Assistant\Prompts\KnownChatMessages.cs (25)
17public static ChatMessage CreateSystemMessage() 46public static ChatMessage CreateInitialMessage(string promptText, string applicationName, List<ResourceViewModel> resources, DashboardOptions dashboardOptions) 70public static ChatMessage CreateFollowUpMessage(int questionCount) 81public static ChatMessage CreateRecentActivityMessage() 92public static ChatMessage CreateResourceRecentActivityMessage(ResourceViewModel resource) 105public static ChatMessage CreateAnalyzeResourceMessage(ResourceViewModel resource) 115public static ChatMessage CreateSummarizeResourcesMessage() 125public static ChatMessage CreateUnhealthyResourcesMessage() 136public static ChatMessage CreateHelpMessage() 148public static ChatMessage CreateAllConsoleLogsMessage() 158public static ChatMessage CreateResourceConsoleLogsMessage(ResourceViewModel resource) 168public static ChatMessage CreateHelpMessage() 180public static ChatMessage CreateErrorStructuredLogsMessage(List<OtlpLogEntry> errorLogs, DashboardOptions options, Func<IOtlpResource, string> getResourceName) 199public static ChatMessage CreateAnalyzeLogEntryMessage(OtlpLogEntry logEntry, DashboardOptions options, Func<IOtlpResource, string> getResourceName) 217public static ChatMessage CreateResourceStructuredLogsMessage(OtlpResource resource) 227public static ChatMessage CreateAllStructuredLogsMessage() 237public static ChatMessage CreateHelpMessage() 249public static ChatMessage CreateAllTracesPerformanceMessage() 258public static ChatMessage CreateResourceTracesPerformanceMessage(string resourceName) 267public static ChatMessage CreateAllTracesMessage() 277public static ChatMessage CreateResourceTracesMessage(OtlpResource resource) 287public static ChatMessage CreateAnalyzeTraceMessage(OtlpTrace trace, List<OtlpLogEntry> traceLogEntries, IEnumerable<IOutgoingPeerResolver> outgoingPeerResolvers, DashboardOptions options, Func<IOtlpResource, string> getResourceName) 314public static ChatMessage CreateAnalyzeSpanMessage(OtlpSpan span, List<OtlpLogEntry> traceLogEntries, IEnumerable<IOutgoingPeerResolver> outgoingPeerResolvers, DashboardOptions options, Func<IOtlpResource, string> getResourceName) 341public static ChatMessage CreateErrorTracesMessage(List<OtlpTrace> errorTraces, IEnumerable<IOutgoingPeerResolver> outgoingPeerResolvers, DashboardOptions options, Func<IOtlpResource, string> getResourceName) 359public static ChatMessage CreateHelpMessage()
Aspire.OpenAI.Tests (1)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (1)
268private static Task<ChatResponse> TestMiddleware(IEnumerable<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
Microsoft.AspNetCore.Components.AI (6)
Engine\AgentContext.cs (3)
27private ChatMessage? _lastMessage; 73public async Task SendMessageAsync(ChatMessage message, CancellationToken cancellationToken = default) 187ChatMessage message,
Engine\UIAgent.cs (3)
34private readonly List<ChatMessage> _history = new(); 103ChatMessage message, 155foreach (var msg in response.Messages)
Microsoft.Extensions.AI (129)
ChatCompletion\AnonymousDelegatingChatClient.cs (11)
21private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? _getResponseFunc; 29private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? _getStreamingResponseFunc; 32private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task>, CancellationToken, Task>? _sharedFunc; 51Func<IEnumerable<ChatMessage>, ChatOptions?, Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task>, CancellationToken, Task> sharedFunc) 77Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc, 78Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc) 89IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 98IEnumerable<ChatMessage> messages, ChatOptions? options, CancellationToken cancellationToken) 128IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ChatCompletion\CachingChatClient.cs (6)
47IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 57IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 75IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 85IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 150protected abstract string GetCacheKey(IEnumerable<ChatMessage> messages, ChatOptions? options, params ReadOnlySpan<object?> additionalValues); 209protected virtual bool EnableCaching(IEnumerable<ChatMessage> messages, ChatOptions? options)
ChatCompletion\ChatClientBuilder.cs (4)
108public ChatClientBuilder Use(Func<IEnumerable<ChatMessage>, ChatOptions?, Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task>, CancellationToken, Task> sharedFunc) 143Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc, 144Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (5)
37IEnumerable<ChatMessage> messages, 76ChatMessage chatMessage, 117ChatMessage chatMessage, 139IEnumerable<ChatMessage> messages, 173ChatMessage? promptAugmentation = null;
ChatCompletion\ConfigureOptionsChatClient.cs (2)
38IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) => 43IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
ChatCompletion\DistributedCachingChatClient.cs (4)
24/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>, 26/// <see cref="ChatMessage.RawRepresentation"/> will be ignored, and <see cref="object"/> values in <see cref="ChatMessage.AdditionalProperties"/> 135protected override string GetCacheKey(IEnumerable<ChatMessage> messages, ChatOptions? options, params ReadOnlySpan<object?> additionalValues)
ChatCompletion\DistributedCachingChatClientBuilderExtensions.cs (3)
29/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>, 31/// <see cref="ChatMessage.RawRepresentation"/> will be ignored, and <see cref="object"/> values in <see cref="ChatMessage.AdditionalProperties"/>
ChatCompletion\FunctionInvocationContext.cs (2)
47public IList<ChatMessage> Messages 51} = Array.Empty<ChatMessage>();
ChatCompletion\FunctionInvokingChatClient.cs (53)
278IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 289List<ChatMessage> originalMessages = [.. messages]; 292List<ChatMessage>? augmentedHistory = null; // the actual history of messages sent on turns other than the first 294List<ChatMessage>? responseMessages = null; // tracked list of messages, across multiple turns, to be used for the final response 311(IList<ChatMessage>? invokedApprovedFunctionApprovalResponses, bool shouldTerminate, consecutiveErrorCount) = 438IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 450List<ChatMessage> originalMessages = [.. messages]; 453List<ChatMessage>? augmentedHistory = null; // the actual history of messages sent on turns other than the first 455List<ChatMessage>? responseMessages = null; // tracked list of messages, across multiple turns, to be used in fallback cases to reconstitute history 484foreach (var message in preDownstreamCallHistory) 495(IList<ChatMessage>? invokedApprovedFunctionApprovalResponses, bool shouldTerminate, consecutiveErrorCount) = 500foreach (var message in invokedApprovedFunctionApprovalResponses) 687foreach (var message in modeAndMessages.MessagesAdded) 707private static ChatResponseUpdate ConvertToolResultMessageToUpdate(ChatMessage message, string? conversationId, string? messageId) => 746IEnumerable<ChatMessage> originalMessages, 747ref IEnumerable<ChatMessage> messages, 748[NotNull] ref List<ChatMessage>? augmentedHistory, 750List<ChatMessage> allTurnsResponseMessages, 865private static bool HasAnyFunctionApproval(List<ChatMessage> messages) => 868private static bool MessageHasFunctionApproval(ChatMessage message) => 882private static bool MessageContainsOnlyFunctionApprovals(ChatMessage message) => 889IList<ChatMessage> messages, [NotNullWhen(true)] ref List<FunctionCallContent>? functionCalls) 924private static void MarkServerHandledFunctionCalls(IList<ChatMessage> messages) 1162private async Task<(bool ShouldTerminate, int NewConsecutiveErrorCount, IList<ChatMessage> MessagesAdded)> ProcessFunctionCallsAsync( 1163List<ChatMessage> messages, ChatOptions? options, 1203IList<ChatMessage> addedMessages = CreateResponseMessages(results.ToArray()); 1224private void UpdateConsecutiveErrorCountOrThrow(IList<ChatMessage> added, ref int consecutiveErrorCount) 1256private void ThrowIfNoFunctionResultsAdded(IList<ChatMessage>? messages) 1267protected virtual IList<ChatMessage> CreateResponseMessages( 1334private (List<ChatMessage>? preDownstreamCallHistory, List<ApprovalResultWithRequestMessage>? approvals, int approvedResultInsertIndex) ProcessFunctionApprovalResponses( 1335List<ChatMessage> originalMessages, bool hasConversationId, string? toolMessageId, string? functionCallContentFallbackMessageId) 1378ICollection<ChatMessage>? allPreDownstreamCallMessages = ConvertToFunctionCallContentMessages( 1384ChatMessage? rejectedPreDownstreamCallResultsMessage = rejectedFunctionCallResults is not null ? 1391List<ChatMessage>? preDownstreamCallHistory = null; 1426List<ChatMessage> messages) 1428Dictionary<string, (ChatMessage Message, ToolApprovalRequestContent RequestContent)>? allApprovalRequestsMessages = null; 1442var message = messages[i]; 1482var newMessage = message.Clone(); 1529ChatMessage? requestMessage = null; 1576private static ICollection<ChatMessage>? ConvertToFunctionCallContentMessages( 1581ChatMessage? currentMessage = null; 1582Dictionary<string, ChatMessage>? messagesById = null; 1630if (messagesById?.Values is ICollection<ChatMessage> cm) 1645/// Takes the <see cref="FunctionCallContent"/> from the <paramref name="resultWithRequestMessage"/> and wraps it in a <see cref="ChatMessage"/> 1648private static ChatMessage ConvertToFunctionCallContentMessage(ApprovalResultWithRequestMessage resultWithRequestMessage, string? fallbackMessageId) 1650ChatMessage functionCallMessage = resultWithRequestMessage.RequestMessage?.Clone() ?? new() { Role = ChatRole.Assistant }; 1737private IList<ChatMessage> ReplaceFunctionCallsWithApprovalRequests( 1738IList<ChatMessage> messages, 1785var message = lastMessageIndex != messageIndex ? outputMessages[messageIndex].Clone() : outputMessages[messageIndex]; 1808/// wrapped in <see cref="ChatMessage"/> objects. 1810private async Task<(IList<ChatMessage>? FunctionResultContentMessages, bool ShouldTerminate, int ConsecutiveErrorCount)> InvokeApprovedFunctionApprovalResponsesAsync( 1812List<ChatMessage> originalMessages, 1918public ChatMessage? RequestMessage { get; init; }
ChatCompletion\ImageGeneratingChatClient.cs (8)
72IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 86foreach (var message in response.Messages) 96IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 164public IEnumerable<ChatMessage> ProcessChatMessages(IEnumerable<ChatMessage> messages) 166List<ChatMessage>? newMessages = null; 168foreach (var message in messages) 229var newMessage = message.Clone();
ChatCompletion\LoggingChatClient.cs (2)
55IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 101IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
ChatCompletion\OpenTelemetryChatClient.cs (3)
136IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 167IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 522private void AddInputMessagesTags(IEnumerable<ChatMessage> messages, ChatOptions? options, Activity? activity)
ChatCompletion\ReducingChatClient.cs (2)
33IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 42IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
ChatReduction\MessageCountingChatReducer.cs (7)
40public Task<IEnumerable<ChatMessage>> ReduceAsync(IEnumerable<ChatMessage> messages, CancellationToken cancellationToken) 46private IEnumerable<ChatMessage> GetReducedMessages(IEnumerable<ChatMessage> messages) 48ChatMessage? systemMessage = null; 49Queue<ChatMessage> reducedMessages = new(capacity: _targetCount); 51foreach (var message in messages)
ChatReduction\SummarizingChatReducer.cs (13)
74public async Task<IEnumerable<ChatMessage>> ReduceAsync(IEnumerable<ChatMessage> messages, CancellationToken cancellationToken) 93private readonly struct SummarizedConversation(string? summary, ChatMessage? systemMessage, IList<ChatMessage> unsummarizedMessages) 96public static SummarizedConversation FromChatMessages(IEnumerable<ChatMessage> messages) 99ChatMessage? systemMessage = null; 100var unsummarizedMessages = new List<ChatMessage>(); 102foreach (var message in messages) 135var lastSummarizedMessage = unsummarizedMessages[indexOfFirstMessageToKeep - 1]; 184public IEnumerable<ChatMessage> ToChatMessages() 196foreach (var message in unsummarizedMessages) 215private IEnumerable<ChatMessage> ToSummarizerChatMessages(int indexOfFirstMessageToKeep, string summarizationPrompt) 224var message = unsummarizedMessages[i];
ChatRouting\FailoverChatClient.cs (2)
98IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 166IEnumerable<ChatMessage> messages, ChatOptions? options = null,
Common\OtelMessageSerializer.cs (2)
39IEnumerable<ChatMessage> messages, ChatFinishReason? chatFinishReason = null, JsonSerializerOptions? customContentSerializerOptions = null) 50foreach (ChatMessage message in messages)
Microsoft.Extensions.AI.Abstractions (133)
ChatCompletion\ChatClientExtensions.cs (2)
113ChatMessage chatMessage, 153ChatMessage chatMessage,
ChatCompletion\ChatMessage.cs (7)
20/// <summary>Initializes a new instance of the <see cref="ChatMessage"/> class.</summary> 27/// <summary>Initializes a new instance of the <see cref="ChatMessage"/> class.</summary> 35/// <summary>Initializes a new instance of the <see cref="ChatMessage"/> class.</summary> 44/// <summary>Clones the <see cref="ChatMessage"/> to a new <see cref="ChatMessage"/> instance.</summary> 50public ChatMessage Clone() => 95/// If a <see cref="ChatMessage"/> is created to represent some underlying object from another object
ChatCompletion\ChatOptions.cs (1)
215/// like the enumerable of <see cref="ChatMessage"/>s. Therefore, it is <b>strongly recommended</b> to not return shared instances
ChatCompletion\ChatResponse.cs (8)
23private IList<ChatMessage>? _messages; 33public ChatResponse(ChatMessage message) 42public ChatResponse(IList<ChatMessage>? messages) 49public IList<ChatMessage> Messages 51get => _messages ??= new List<ChatMessage>(1); 57/// This property concatenates the <see cref="ChatMessage.Text"/> of all <see cref="ChatMessage"/> 144ChatMessage message = _messages![i];
ChatCompletion\ChatResponseExtensions.cs (17)
30public static void AddMessages(this IList<ChatMessage> list, ChatResponse response) 35if (list is List<ChatMessage> listConcrete) 41foreach (var message in response.Messages) 48/// <summary>Converts the <paramref name="updates"/> into <see cref="ChatMessage"/> instances and adds them to <paramref name="list"/>.</summary> 54/// As part of combining <paramref name="updates"/> into a series of <see cref="ChatMessage"/> instances, the 59public static void AddMessages(this IList<ChatMessage> list, IEnumerable<ChatResponseUpdate> updates) 72/// <summary>Converts the <paramref name="update"/> into a <see cref="ChatMessage"/> instance and adds it to <paramref name="list"/>.</summary> 80/// no <see cref="ChatMessage"/> will be added to the <paramref name="list"/>. 82public static void AddMessages(this IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool>? filter = null) 100/// <summary>Converts the <paramref name="updates"/> into <see cref="ChatMessage"/> instances and adds them to <paramref name="list"/>.</summary> 108/// As part of combining <paramref name="updates"/> into a series of <see cref="ChatMessage"/> instances, tne 114this IList<ChatMessage> list, IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken = default) 122IList<ChatMessage> list, IAsyncEnumerable<ChatResponseUpdate> updates, CancellationToken cancellationToken) => 132/// <see cref="ChatMessage"/> instances. This includes using <see cref="ChatResponseUpdate.MessageId"/> to determine 160/// <see cref="ChatMessage"/> instances. This includes using <see cref="ChatResponseUpdate.MessageId"/> to determine 545var lastMessage = response.Messages[response.Messages.Count - 1]; 553ChatMessage message;
ChatCompletion\ChatResponseUpdate.cs (2)
19/// <see cref="ChatResponse"/> and <see cref="ChatMessage"/> in streaming output. 133/// groups <see cref="ChatResponseUpdate"/> instances into <see cref="ChatMessage"/> instances.
ChatCompletion\DelegatingChatClient.cs (2)
44IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) => 49IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) =>
ChatCompletion\IChatClient.cs (2)
43IEnumerable<ChatMessage> messages, 55IEnumerable<ChatMessage> messages,
ChatReduction\IChatReducer.cs (2)
19Task<IEnumerable<ChatMessage>> ReduceAsync(IEnumerable<ChatMessage> messages, CancellationToken cancellationToken);
ChatRouting\RoutingChatClient.cs (2)
65IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 81IEnumerable<ChatMessage> messages, ChatOptions? options = null,
ChatRouting\RoutingContext.cs (2)
30IEnumerable<ChatMessage> messages, 43public IEnumerable<ChatMessage> Messages { get; }
Contents\AIContentExtensions.cs (3)
62/// <summary>Concatenates the <see cref="ChatMessage.Text"/> of all <see cref="ChatMessage"/> instances in the list.</summary> 64public static string ConcatText(this IList<ChatMessage> messages)
Functions\AIFunctionFactory.cs (2)
1258if (typeof(IEnumerable<ChatMessage>).IsAssignableFrom(type)) 1260return typeof(IEnumerable<ChatMessage>);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessage.g.cs (38)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>? _ChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> ChatMessage 24get => _ChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatMessage)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> Create_ChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatMessage>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatMessage> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatMessage>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 60Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName, 61Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName = value!, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 78DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 80Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt, 81Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt = value!, 88AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 100Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role, 101Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role = value!, 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole), global::System.Array.Empty<global::System.Type>(), null), 118DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 128AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 139DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 141Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents, 142Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents = value!, 149AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 160DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 162Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId, 163Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId = value!, 170AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 180DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 190AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 200DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 202Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties, 203Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties = value!, 210AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessageArray.g.cs (10)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage[]>? _ChatMessageArray; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage[]> ChatMessageArray 24get => _ChatMessageArray ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage[]>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatMessage[])); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage[]> Create_ChatMessageArray(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatMessage[]>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage[]> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::Microsoft.Extensions.AI.ChatMessage[]> 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateArrayInfo<global::Microsoft.Extensions.AI.ChatMessage>(options, info); 47private void ChatMessageArraySerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Microsoft.Extensions.AI.ChatMessage[]? value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatResponse.g.cs (3)
53var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponse).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 71properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info0);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (4)
96if (type == typeof(global::Microsoft.Extensions.AI.ChatMessage)) 100if (type == typeof(global::Microsoft.Extensions.AI.ChatMessage[])) 396if (type == typeof(global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>)) 416if (type == typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>))
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.IEnumerableChatMessage.g.cs (12)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>>? _IEnumerableChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>> IEnumerableChatMessage 24get => _IEnumerableChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>> Create_IEnumerableChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>> 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIEnumerableInfo<global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>, global::Microsoft.Extensions.AI.ChatMessage>(options, info); 47private void IEnumerableChatMessageSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IEnumerable<global::Microsoft.Extensions.AI.ChatMessage>? value) 57foreach (global::Microsoft.Extensions.AI.ChatMessage element in value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.IListChatMessage.g.cs (11)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>? _IListChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> IListChatMessage 24get => _IListChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> Create_IListChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIListInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>, global::Microsoft.Extensions.AI.ChatMessage>(options, info); 47private void IListChatMessageSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>? value)
Utilities\AIJsonUtilities.Defaults.cs (3)
98[JsonSerializable(typeof(IEnumerable<ChatMessage>))] 99[JsonSerializable(typeof(IList<ChatMessage>))] 100[JsonSerializable(typeof(ChatMessage[]))]
Microsoft.Extensions.AI.Abstractions.Tests (120)
AssertExtensions.cs (4)
18public static void EqualMessageLists(List<ChatMessage> expectedMessages, List<ChatMessage> actualMessages) 23var expectedMessage = expectedMessages[i]; 24var chatMessage = actualMessages[i];
ChatCompletion\ChatClientExtensionsTests.cs (4)
82_ = ChatClientExtensions.GetResponseAsync(new TestChatClient(), (ChatMessage)null!); 96_ = ChatClientExtensions.GetStreamingResponseAsync(new TestChatClient(), (ChatMessage)null!); 111ChatMessage m = Assert.Single(messages); 138ChatMessage m = Assert.Single(messages);
ChatCompletion\ChatMessageTests.cs (15)
17ChatMessage message = new(); 36ChatMessage message = new(ChatRole.Assistant, text); 62ChatMessage message; 93ChatMessage message = new(ChatRole.System, content); 128ChatMessage message = new() 144ChatMessage message = new(ChatRole.User, 176ChatMessage message = new(); 196ChatMessage message = new(); 217ChatMessage message = new(); 238ChatMessage message = new(); 276var chatMessage = new ChatMessage(ChatRole.User, contents: items) 284var deserializedMessage = JsonSerializer.Deserialize<ChatMessage>(chatMessageJson, TestJsonSerializerContext.Default.Options)!; 374ChatMessage? result = JsonSerializer.Deserialize<ChatMessage>(Json, AIJsonUtilities.DefaultOptions);
ChatCompletion\ChatResponseTests.cs (3)
23response = new((IList<ChatMessage>?)null); 27Assert.Throws<ArgumentNullException>("message", () => new ChatResponse((ChatMessage)null!)); 37List<ChatMessage> messages = [];
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (20)
54ChatMessage message = response.Messages.Single(); 265ChatMessage message = Assert.Single(response.Messages); 368ChatMessage message = Assert.Single(response.Messages); 475var msg1 = response.Messages[0]; 483var msg2 = response.Messages[1]; 491var msg3 = response.Messages[2]; 519var message = Assert.Single(response.Messages); 570ChatMessage message1 = response.Messages[0]; 578ChatMessage message2 = response.Messages[1]; 586ChatMessage message3 = response.Messages[2]; 594ChatMessage message4 = response.Messages[3]; 669ChatMessage message = response.Messages.Single(); 708ChatMessage message = Assert.Single(response.Messages); 738ChatMessage message = Assert.Single(response.Messages); 783ChatMessage message = Assert.Single(response.Messages); 950ChatMessage message = Assert.Single(response.Messages); 998ChatMessage message = Assert.Single(response.Messages); 1041ChatMessage message = Assert.Single(response.Messages); 1072ChatMessage message = Assert.Single(response.Messages); 1092ChatMessage message = Assert.Single(response.Messages);
ChatCompletion\DelegatingChatClientTests.cs (2)
24var expectedChatContents = new List<ChatMessage>(); 56var expectedChatContents = new List<ChatMessage>();
ChatRouting\RoutingChatClientTests.cs (3)
23var messages = new ChatMessage[] { new(ChatRole.User, "hi") }; 163IEnumerable<ChatMessage> messages, ChatOptions? options = null, 168IEnumerable<ChatMessage> messages, ChatOptions? options = null,
ChatRouting\RoutingContextTests.cs (1)
15var messages = new List<ChatMessage> { new(ChatRole.User, "initial") };
Contents\AIContentTests.cs (3)
65ChatMessage message = new(ChatRole.User, 101ChatMessage? deserialized = JsonSerializer.Deserialize<ChatMessage>(serialized, options);
Contents\ToolCallContentTests.cs (3)
54ChatMessage message = new(ChatRole.Assistant, 73ChatMessage? deserialized2 = JsonSerializer.Deserialize<ChatMessage>(serializedMessage, options);
Contents\ToolResultContentTests.cs (3)
53ChatMessage message = new(ChatRole.Tool, 72ChatMessage? deserialized2 = JsonSerializer.Deserialize<ChatMessage>(serializedMessage, options);
Generated\361d1da7f942c932\TestJsonSerializerContext.ChatResponse.g.cs (3)
51var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponse).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 69properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info0);
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (2)
86if (type == typeof(global::Microsoft.Extensions.AI.ChatMessage)) 426if (type == typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>))
Generated\361d1da7f942c932\TestJsonSerializerContext.IListChatMessage.g.cs (11)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>? _IListChatMessage; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> IListChatMessage 22get => _IListChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> Create_IListChatMessage(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> jsonTypeInfo)) 29var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 35jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIListInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>, global::Microsoft.Extensions.AI.ChatMessage>(options, info); 45private void IListChatMessageSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>? value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.ChatMessage.g.cs (38)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>? _ChatMessage; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> ChatMessage 22get => _ChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatMessage)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> Create_ChatMessage(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatMessage>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatMessage> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatMessage>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 58Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName, 59Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName = value!, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 76DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 78Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt, 79Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt = value!, 86AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 96DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 98Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role, 99Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role = value!, 106AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole), global::System.Array.Empty<global::System.Type>(), null), 116DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 126AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 137DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 139Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents, 140Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents = value!, 147AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 159DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 161Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId, 162Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId = value!, 169AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 179DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 189AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 199DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 201Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties, 202Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties = value!, 209AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null),
TestChatClient.cs (4)
20public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>>? GetResponseAsyncCallback { get; set; } 22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 29public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Utilities\AIJsonUtilitiesTests.cs (1)
1260Assert.Throws<ArgumentException>("contentType", () => options.AddAIContentType(typeof(ChatMessage), "discriminator"));
Microsoft.Extensions.AI.Evaluation (49)
ChatMessageExtensions.cs (38)
13/// Extension methods for <see cref="ChatMessage"/>. 19/// single <see cref="ChatMessage"/> representing the last <paramref name="userRequest"/> in this conversation. 22/// A collection of <see cref="ChatMessage"/>s representing an LLM chat conversation history. 25/// Returns the last <see cref="ChatMessage"/> in the supplied collection of <paramref name="messages"/> if this 26/// last <see cref="ChatMessage"/> has <see cref="ChatMessage.Role"/> set to <see cref="ChatRole.User"/>; 30/// <see langword="true"/> if the last <see cref="ChatMessage"/> in the supplied collection of 31/// <paramref name="messages"/> has <see cref="ChatMessage.Role"/> set to <see cref="ChatRole.User"/>; 35this IEnumerable<ChatMessage> messages, 36[NotNullWhen(true)] out ChatMessage? userRequest) 39messages.LastOrDefault() is ChatMessage lastMessage && lastMessage.Role == ChatRole.User 48/// single <see cref="ChatMessage"/> representing the last <paramref name="userRequest"/> in this conversation and 52/// A collection of <see cref="ChatMessage"/>s representing an LLM chat conversation history. 55/// Returns the last <see cref="ChatMessage"/> in the supplied collection of <paramref name="messages"/> if this 56/// last <see cref="ChatMessage"/> has <see cref="ChatMessage.Role"/> set to <see cref="ChatRole.User"/>; 60/// Returns the remaining <see cref="ChatMessage"/>s in the conversation history excluding 64/// <see langword="true"/> if the last <see cref="ChatMessage"/> in the supplied collection of 65/// <paramref name="messages"/> has <see cref="ChatMessage.Role"/> set to <see cref="ChatRole.User"/>; 69this IEnumerable<ChatMessage> messages, 70[NotNullWhen(true)] out ChatMessage? userRequest, 71out IReadOnlyList<ChatMessage> remainingMessages) 73List<ChatMessage> conversationHistory = [.. messages]; 77conversationHistory[lastMessageIndex] is ChatMessage lastMessage && 99/// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s 100/// (present within the <see cref="ChatMessage.Contents"/> of the <paramref name="message"/>) that are not 105/// The returned string is prefixed with the <see cref="ChatMessage.Role"/> and 106/// <see cref="ChatMessage.AuthorName"/> (if available). The returned string also always has a new line character 110/// <param name="message">The <see cref="ChatMessage"/> that is to be rendered.</param> 112public static string RenderText(this ChatMessage message) 138/// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s 139/// (present within the <see cref="ChatMessage.Contents"/> of the <paramref name="messages"/>) that are not 145/// The rendered <paramref name="messages"/> are each prefixed with the <see cref="ChatMessage.Role"/> and 146/// <see cref="ChatMessage.AuthorName"/> (if available) in the returned string. The rendered 147/// <see cref="ChatMessage"/>s are also always separated by new line characters in the returned string. 150/// <param name="messages">The <see cref="ChatMessage"/>s that are to be rendered.</param> 152public static string RenderText(this IEnumerable<ChatMessage> messages) 157foreach (ChatMessage message in messages)
ChatResponseExtensions.cs (3)
21/// (present within the <see cref="ChatMessage.Contents"/> of the <see cref="ChatResponse.Messages"/>) that are not 27/// The rendered <see cref="ChatResponse.Messages"/> are each prefixed with the <see cref="ChatMessage.Role"/> and 28/// <see cref="ChatMessage.AuthorName"/> (if available) in the returned string. The rendered
CompositeEvaluator.cs (2)
101IEnumerable<ChatMessage> messages, 126IEnumerable<ChatMessage> messages,
EvaluationContext.cs (1)
23/// <see cref="IEvaluator.EvaluateAsync(IEnumerable{ChatMessage}, ChatResponse, ChatConfiguration?, IEnumerable{EvaluationContext}?, CancellationToken)"/>.
EvaluatorExtensions.cs (4)
131ChatMessage modelResponse, 219ChatMessage userRequest, 220ChatMessage modelResponse, 264ChatMessage userRequest,
IEvaluator.cs (1)
58IEnumerable<ChatMessage> messages,
Microsoft.Extensions.AI.Evaluation.Integration.Tests (41)
AgentQualityEvaluatorTests.cs (8)
92(IEnumerable<ChatMessage> messages, ChatResponse response) = 115(IEnumerable<ChatMessage> messages, ChatResponse response) = 148(IEnumerable<ChatMessage> messages, ChatResponse response) = 172(IEnumerable<ChatMessage> messages, ChatResponse response) = 203private static async Task<(IEnumerable<ChatMessage> messages, ChatResponse response)> 206List<ChatMessage> messages = 216private static async Task<(IEnumerable<ChatMessage> messages, ChatResponse response)> 219List<ChatMessage> messages =
ChatMessageUtilities.cs (3)
8internal static ChatMessage ToSystemMessage(this string message) 11internal static ChatMessage ToUserMessage(this string message) 14internal static ChatMessage ToAssistantMessage(this string message)
QualityEvaluatorTests.cs (4)
87var messages = new List<ChatMessage>(); 128var messages = new List<ChatMessage>(); 166var messages = new List<ChatMessage>(); 201var messages = new List<ChatMessage>();
ResultsTests.cs (1)
19private static readonly ChatMessage _testResponse = "Test response".ToAssistantMessage();
SafetyEvaluatorTests.cs (24)
183var messages = new List<ChatMessage>(); 261var messages = new List<ChatMessage>(); 334var question = 343ChatMessage answer = "The image depicts a logo for Microsoft Corporation.".ToAssistantMessage(); 370ChatMessage question = "Can you show me an image pertaining to DotNet?".ToUserMessage(); 372var answer = 406var question1 = 415ChatMessage answer1 = "The image depicts a logo for DotNet.".ToAssistantMessage(); 417ChatMessage question2 = "Can you show me an image pertaining to Microsoft Copilot?".ToUserMessage(); 419var answer2 = 428ChatMessage[] messages = [question1, answer1, question2]; 455var question1 = 464ChatMessage answer1 = "The image depicts a logo for Microsoft Corporation.".ToAssistantMessage(); 466ChatMessage question2 = "Can you show me an image pertaining to Microsoft Copilot?".ToUserMessage(); 468var answer2 = 477ChatMessage question3 = 482ChatMessage answer3 = 490ChatMessage[] messages = [question1, answer1, question2, answer2, question3]; 546ChatMessage context1 = 551ChatMessage completion1 = 556ChatMessage context2 = 561ChatMessage completion2 = 566ChatMessage[] messages = [context1, completion1, context2]; 589var messages = new List<ChatMessage>();
TestEvaluator.cs (1)
27IEnumerable<ChatMessage> messages,
Microsoft.Extensions.AI.Evaluation.NLP (3)
BLEUEvaluator.cs (1)
42IEnumerable<ChatMessage> messages,
F1Evaluator.cs (1)
42IEnumerable<ChatMessage> messages,
GLEUEvaluator.cs (1)
42IEnumerable<ChatMessage> messages,
Microsoft.Extensions.AI.Evaluation.Quality (64)
ChatMessageExtensions.cs (3)
13internal static string RenderAsJson(this IEnumerable<ChatMessage> messages, JsonSerializerOptions? options = null) 19foreach (ChatMessage message in messages) 24AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ChatMessage)));
CoherenceEvaluator.cs (6)
68IEnumerable<ChatMessage> messages, 89_ = messages.TryGetUserRequest(out ChatMessage? userRequest); 91List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(userRequest, modelResponse); 105private static List<ChatMessage> GetEvaluationInstructions(ChatMessage? userRequest, ChatResponse modelResponse) 117List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
CompletenessEvaluator.cs (4)
65IEnumerable<ChatMessage> messages, 96List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(modelResponse, context); 111private static List<ChatMessage> GetEvaluationInstructions( 125List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
EquivalenceEvaluator.cs (6)
66IEnumerable<ChatMessage> messages, 97_ = messages.TryGetUserRequest(out ChatMessage? userRequest); 99List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(userRequest, modelResponse, context); 114private static List<ChatMessage> GetEvaluationInstructions( 115ChatMessage? userRequest, 124List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
FluencyEvaluator.cs (4)
62IEnumerable<ChatMessage> messages, 83List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(modelResponse); 97private static List<ChatMessage> GetEvaluationInstructions(ChatResponse modelResponse) 109List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
GroundednessEvaluator.cs (6)
63IEnumerable<ChatMessage> messages, 94_ = messages.TryGetUserRequest(out ChatMessage? userRequest); 96List<ChatMessage> evaluationInstructions = 112private static List<ChatMessage> GetEvaluationInstructions( 113ChatMessage? userRequest, 127List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
IntentResolutionEvaluator.cs (5)
76IEnumerable<ChatMessage> messages, 141List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(messages, modelResponse, context); 165private static List<ChatMessage> GetEvaluationInstructions( 166IEnumerable<ChatMessage> messages, 173List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
RelevanceEvaluator.cs (6)
66IEnumerable<ChatMessage> messages, 79if (!messages.TryGetUserRequest(out ChatMessage? userRequest) || string.IsNullOrWhiteSpace(userRequest.Text)) 96List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(userRequest, modelResponse); 110private static List<ChatMessage> GetEvaluationInstructions(ChatMessage userRequest, ChatResponse modelResponse) 122List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
RelevanceTruthAndCompletenessEvaluator.cs (7)
79IEnumerable<ChatMessage> messages, 98out ChatMessage? userRequest, 99out IReadOnlyList<ChatMessage> conversationHistory) || 117List<ChatMessage> evaluationInstructions = 137private static List<ChatMessage> GetEvaluationInstructions( 138ChatMessage userRequest, 140IEnumerable<ChatMessage> conversationHistory)
RetrievalEvaluator.cs (6)
72IEnumerable<ChatMessage> messages, 84if (!messages.TryGetUserRequest(out ChatMessage? userRequest) || string.IsNullOrWhiteSpace(userRequest.Text)) 112List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(userRequest, context); 127private static List<ChatMessage> GetEvaluationInstructions( 128ChatMessage userRequest, 141List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
TaskAdherenceEvaluator.cs (5)
75IEnumerable<ChatMessage> messages, 140List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(messages, modelResponse, context); 160private static List<ChatMessage> GetEvaluationInstructions( 161IEnumerable<ChatMessage> messages, 264List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, systemPrompt)];
ToolCallAccuracyEvaluator.cs (5)
77IEnumerable<ChatMessage> messages, 140List<ChatMessage> evaluationInstructions = GetEvaluationInstructions(messages, modelResponse, context); 155private static List<ChatMessage> GetEvaluationInstructions( 156IEnumerable<ChatMessage> messages, 170List<ChatMessage> evaluationInstructions = [new ChatMessage(ChatRole.System, SystemPrompt)];
Utilities\JsonOutputFixer.cs (1)
65var messages = new List<ChatMessage>
Microsoft.Extensions.AI.Evaluation.Reporting (73)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessage.g.cs (38)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>? _ChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> ChatMessage 24get => _ChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatMessage)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> Create_ChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatMessage>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatMessage> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatMessage>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 60Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName, 61Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName = value!, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 78DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 80Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt, 81Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt = value!, 88AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 100Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role, 101Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role = value!, 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole), global::System.Array.Empty<global::System.Type>(), null), 118DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 128AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 139DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 141Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents, 142Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents = value!, 149AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 161DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 163Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId, 164Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId = value!, 171AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 181DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 191AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 201DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 203Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties, 204Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties = value!, 211AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatResponse.g.cs (3)
53var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponse).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 71properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info0);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (2)
68if (type == typeof(global::Microsoft.Extensions.AI.ChatMessage)) 280if (type == typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>))
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.IListChatMessage.g.cs (11)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>? _IListChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> IListChatMessage 24get => _IListChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> Create_IListChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIListInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>, global::Microsoft.Extensions.AI.ChatMessage>(options, info); 47private void IListChatMessageSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>? value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ScenarioRunResult.g.cs (7)
34ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult((string)args[0], (string)args[1], (string)args[2], (global::System.DateTime)args[3], (global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)args[4], (global::Microsoft.Extensions.AI.ChatResponse)args[5], (global::Microsoft.Extensions.AI.Evaluation.EvaluationResult)args[6], (global::Microsoft.Extensions.AI.Evaluation.Reporting.ChatDetails)args[7], (global::System.Collections.Generic.IList<string>)args[8], (int?)args[9]), 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string), typeof(string), typeof(global::System.DateTime), typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), typeof(global::Microsoft.Extensions.AI.ChatResponse), typeof(global::Microsoft.Extensions.AI.Evaluation.EvaluationResult), typeof(global::Microsoft.Extensions.AI.Evaluation.Reporting.ChatDetails), typeof(global::System.Collections.Generic.IList<string>), typeof(int?)}, modifiers: null), 139var info4 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 154AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 157properties[4] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info4); 296global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage> __value_Messages = ((global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult)value).Messages; 381ParameterType = typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>),
ScenarioRun.cs (1)
144IEnumerable<ChatMessage> messages,
ScenarioRunExtensions.cs (4)
86ChatMessage modelResponse, 143ChatMessage userRequest, 144ChatMessage modelResponse, 173ChatMessage userRequest,
ScenarioRunResult.cs (5)
15/// <see cref="ScenarioRun.EvaluateAsync(IEnumerable{ChatMessage}, ChatResponse, IEnumerable{Microsoft.Extensions.AI.Evaluation.EvaluationContext}?, CancellationToken)"/> 51IList<ChatMessage> messages, 86IEnumerable<ChatMessage> messages, 128public IList<ChatMessage> Messages { get; set; } = messages; 141/// <see cref="ScenarioRun.EvaluateAsync(IEnumerable{ChatMessage}, ChatResponse, IEnumerable{Microsoft.Extensions.AI.Evaluation.EvaluationContext}?, CancellationToken)"/>
SimpleChatClient.cs (2)
26IEnumerable<ChatMessage> messages, 59IEnumerable<ChatMessage> messages,
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (61)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatMessage.g.cs (38)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>? _ChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> ChatMessage 24get => _ChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatMessage)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> Create_ChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatMessage>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> jsonTypeInfo)) 31var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatMessage> 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 41jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatMessage>(options, objectInfo); 58DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 60Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName, 61Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName = value!, 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 78DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 80Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt, 81Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt = value!, 88AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 98DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 100Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role, 101Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role = value!, 108AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole), global::System.Array.Empty<global::System.Type>(), null), 118DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 128AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 139DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 141Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents, 142Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents = value!, 149AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 161DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 163Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId, 164Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId = value!, 171AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 181DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 191AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 201DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 203Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties, 204Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties = value!, 211AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null),
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ChatResponse.g.cs (3)
53var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 68AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponse).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 71properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info0);
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.GetJsonTypeInfo.g.cs (2)
68if (type == typeof(global::Microsoft.Extensions.AI.ChatMessage)) 276if (type == typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>))
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.IListChatMessage.g.cs (11)
15private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>? _IListChatMessage; 21public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> IListChatMessage 24get => _IListChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)); 27private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> Create_IListChatMessage(global::System.Text.Json.JsonSerializerOptions options) 29if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> jsonTypeInfo)) 31var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 37jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIListInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>, global::Microsoft.Extensions.AI.ChatMessage>(options, info); 47private void IListChatMessageSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>? value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\JsonContext.ScenarioRunResult.g.cs (7)
34ObjectWithParameterizedConstructorCreator = static args => new global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult((string)args[0], (string)args[1], (string)args[2], (global::System.DateTime)args[3], (global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)args[4], (global::Microsoft.Extensions.AI.ChatResponse)args[5], (global::Microsoft.Extensions.AI.Evaluation.EvaluationResult)args[6], (global::Microsoft.Extensions.AI.Evaluation.Reporting.ChatDetails)args[7], (global::System.Collections.Generic.IList<string>)args[8], (int?)args[9]), 37ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult).GetConstructor(InstanceMemberBindingFlags, binder: null, new[] {typeof(string), typeof(string), typeof(string), typeof(global::System.DateTime), typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), typeof(global::Microsoft.Extensions.AI.ChatResponse), typeof(global::Microsoft.Extensions.AI.Evaluation.EvaluationResult), typeof(global::Microsoft.Extensions.AI.Evaluation.Reporting.ChatDetails), typeof(global::System.Collections.Generic.IList<string>), typeof(int?)}, modifiers: null), 139var info4 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 154AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 157properties[4] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info4); 296global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage> __value_Messages = ((global::Microsoft.Extensions.AI.Evaluation.Reporting.ScenarioRunResult)value).Messages; 381ParameterType = typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>),
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (4)
ScenarioRunResultTests.cs (4)
409private class ChatMessageComparer : IEqualityComparer<ChatMessage> 413public bool Equals(ChatMessage? x, ChatMessage? y) 416public int GetHashCode(ChatMessage obj)
Microsoft.Extensions.AI.Evaluation.Safety (36)
ChatMessageExtensions.cs (2)
11internal static bool ContainsImageWithSupportedFormat(this ChatMessage message) 14internal static bool ContainsImageWithSupportedFormat(this IEnumerable<ChatMessage> conversation)
CodeVulnerabilityEvaluator.cs (1)
47IEnumerable<ChatMessage> messages,
ContentHarmEvaluator.cs (1)
49IEnumerable<ChatMessage> messages,
ContentSafetyChatClient.cs (3)
51IEnumerable<ChatMessage> messages, 84IEnumerable<ChatMessage> messages, 141private static void ValidateSingleMessage(IEnumerable<ChatMessage> messages)
ContentSafetyEvaluator.cs (4)
37IEnumerable<ChatMessage> messages, 83IEnumerable<ChatMessage> messages, 102IEnumerable<ChatMessage> conversation = [.. messages, .. modelResponse.Messages]; 133var payloadMessage = new ChatMessage(ChatRole.User, payload);
ContentSafetyServicePayloadUtilities.cs (22)
17IEnumerable<ChatMessage> conversation, 79IEnumerable<ChatMessage> conversation, 90List<Dictionary<string, ChatMessage>> turns; 110if (turn.TryGetValue("question", out ChatMessage? question)) 115if (turn.TryGetValue("answer", out ChatMessage? answer)) 165IEnumerable<ChatMessage> conversation, 182List<Dictionary<string, ChatMessage>> turns; 202if (turn.TryGetValue("question", out ChatMessage? question)) 207if (turn.TryGetValue("answer", out ChatMessage? answer)) 246IEnumerable<ChatMessage> conversation, 260List<Dictionary<string, ChatMessage>> turns; 274IEnumerable<JsonObject> GetMessages(Dictionary<string, ChatMessage> turn, int turnIndex) 278if (turn.TryGetValue("question", out ChatMessage? question)) 289if (turn.TryGetValue("answer", out ChatMessage? answer)) 314IEnumerable<JsonObject> GetContents(ChatMessage message) 384(List<Dictionary<string, ChatMessage>> turns, 388IEnumerable<ChatMessage> conversation, 395List<Dictionary<string, ChatMessage>> turns = []; 396Dictionary<string, ChatMessage> currentTurn = []; 416foreach (ChatMessage message in conversation) 450void ValidateContents(ChatMessage message) 478foreach (var message in turn.Values)
GroundednessProEvaluator.cs (1)
48IEnumerable<ChatMessage> messages,
ProtectedMaterialEvaluator.cs (1)
67IEnumerable<ChatMessage> messages,
UngroundedAttributesEvaluator.cs (1)
52IEnumerable<ChatMessage> messages,
Microsoft.Extensions.AI.Evaluation.Tests (3)
ChatMessageUtilities.cs (3)
8internal static ChatMessage ToSystemMessage(this string message) 11internal static ChatMessage ToUserMessage(this string message) 14internal static ChatMessage ToAssistantMessage(this string message)
Microsoft.Extensions.AI.Integration.Tests (44)
CallCountingChatClient.cs (2)
20IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 27IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ChatClientIntegrationTests.cs (21)
100IList<ChatMessage> chatHistory = 160List<ChatMessage> history = [new(ChatRole.User, "Explain in 100 words how AI works")]; 229List<ChatMessage> messages = 296List<ChatMessage> messages = 328List<ChatMessage> messages = 358List<ChatMessage> messages = 640var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 656var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 681var message = new ChatMessage(ChatRole.User, "Pick a random number, uniformly distributed between 1 and 1000000"); 733var message = new ChatMessage(ChatRole.User, "What is the temperature?"); 772var message = new ChatMessage(ChatRole.User, "What is the temperature?"); 814var message = new ChatMessage(ChatRole.User, "What is the temperature?"); 1135List<ChatMessage> messages = 1177List<ChatMessage> messages = 1238List<ChatMessage> messages = 1272List<ChatMessage> messages = 1318List<ChatMessage> messages = 1337var summaryMessage = chatClient.LastSummarizedConversation[0]; 1359public IReadOnlyList<ChatMessage>? LastSummarizedConversation { get; private set; } 1383public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 1386public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ImageGeneratingChatClientIntegrationTests.cs (6)
69protected async Task<ChatResponse> GetResponseAsync(bool useStreaming, IEnumerable<ChatMessage> messages, ChatOptions? options = null, IChatClient? chatClient = null) 193var chatHistory = new List<ChatMessage> 243var chatHistory = new List<ChatMessage> 288var chatHistory = new List<ChatMessage> 360var capturedMessages = new List<IEnumerable<ChatMessage>>(); 391var userMessage = processedMessages.First(m => m.Role == ChatRole.User);
parent\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
20public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>>? GetResponseAsyncCallback { get; set; } 22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 29public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
PromptBasedFunctionCallingChatClient.cs (6)
43IEnumerable<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 49List<ChatMessage> chatMessagesList = [CreateToolPrompt(options.Tools), .. chatMessages.Select(m => m.Clone())]; 66var message = chatMessagesList[messageIndex]; 89var message = result.Messages.First(); 138IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 167private static ChatMessage CreateToolPrompt(IList<AITool> tools)
ReducingChatClientTests.cs (5)
43List<ChatMessage> messages = 70public async Task<IEnumerable<ChatMessage>> ReduceAsync( 71IEnumerable<ChatMessage> messages, CancellationToken cancellationToken) 75List<ChatMessage> list = messages.ToList(); 95private int CountTokens(ChatMessage message)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (1)
OllamaSharpChatClientIntegrationTests.cs (1)
111IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.OpenAI (27)
MicrosoftExtensionsAIChatExtensions.cs (5)
45public static IEnumerable<ChatMessage> AsOpenAIChatMessages(this IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, ChatOptions? options = null) => 62var lastMessage = response.Messages.LastOrDefault(); 175/// <summary>Creates a sequence of <see cref="Microsoft.Extensions.AI.ChatMessage"/> instances from the specified input messages.</summary> 179public static IEnumerable<Microsoft.Extensions.AI.ChatMessage> AsChatMessages(this IEnumerable<ChatMessage> messages) 185Microsoft.Extensions.AI.ChatMessage resultMessage = new()
MicrosoftExtensionsAIResponsesExtensions.cs (4)
52public static IEnumerable<ResponseItem> AsOpenAIResponseItems(this IEnumerable<ChatMessage> messages, ChatOptions? options = null) => 55/// <summary>Creates a sequence of <see cref="ChatMessage"/> instances from the specified input items.</summary> 57/// <returns>A sequence of <see cref="ChatMessage"/> instances.</returns> 59public static IEnumerable<ChatMessage> AsChatMessages(this IEnumerable<ResponseItem> items) =>
OpenAIAssistantsChatClient.cs (4)
72IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) => 77IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) 342IEnumerable<ChatMessage> messages, ChatOptions? options, CancellationToken cancellationToken) 508foreach (var chatMessage in messages)
OpenAIChatClient.cs (5)
91IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 112IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 150internal static IEnumerable<OpenAI.Chat.ChatMessage> ToOpenAIChatMessages(IEnumerable<ChatMessage> inputs, ChatOptions? chatOptions) 160foreach (ChatMessage input in inputs) 502ChatMessage returnMessage = new()
OpenAIResponsesChatClient.cs (9)
102IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 168foreach (var message in response.Messages) 182internal static IEnumerable<ChatMessage> ToChatMessages(IEnumerable<ResponseItem> items, CreateResponseOptions? options = null) 184ChatMessage? message = null; 326IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 1282/// <summary>Convert a sequence of <see cref="ChatMessage"/>s to <see cref="ResponseItem"/>s.</summary> 1283internal static IEnumerable<ResponseItem> ToOpenAIResponseItems(IEnumerable<ChatMessage> inputs, ChatOptions? options) 1289foreach (ChatMessage input in inputs) 2038private static ResponsesClientContinuationToken? GetContinuationToken(IEnumerable<ChatMessage> messages, ChatOptions? options = null)
Microsoft.Extensions.AI.OpenAI.Tests (75)
OpenAIAssistantChatClientIntegrationTests.cs (1)
61ChatMessage message = Assert.Single(response.Messages);
OpenAIChatClientTests.cs (5)
819List<ChatMessage> messages = 926List<ChatMessage> messages = 1022List<ChatMessage> messages = 1465List<ChatMessage> messages = 1913var message = response.Messages.Single();
OpenAIConversionTests.cs (26)
722Assert.Throws<ArgumentNullException>("messages", () => ((IEnumerable<ChatMessage>)null!).AsOpenAIChatMessages()); 724List<ChatMessage> messages = 791Assert.Throws<ArgumentNullException>("messages", () => ((IEnumerable<ChatMessage>)null!).AsOpenAIResponseItems()); 793List<ChatMessage> messages = 846List<ChatMessage> messages = 904ChatMessage message = Assert.Single(response.Messages); 935ChatMessage message = Assert.Single(response.Messages); 1189List<ChatMessage> inputMessages = 1200var message = convertedMessages[0]; 1215List<ChatMessage> inputMessages = 1229var message = convertedMessages[0]; 1290ChatMessage[] messages = items.AsChatMessages().ToArray(); 1294ChatMessage message = messages[0]; 1428ChatMessage[] messages = items.AsChatMessages().ToArray(); 1431ChatMessage message = messages[0]; 1451ChatMessage[] messages = new ResponseItem[] { messageItem }.AsChatMessages().ToArray(); 1454ChatMessage message = messages[0]; 1471ChatMessage[] messages = new ResponseItem[] { messageItem }.AsChatMessages().ToArray(); 1474ChatMessage message = messages[0]; 1492var items = new ChatMessage[] { new(ChatRole.Assistant, [mcpToolCall, mcpToolResult]) }.AsOpenAIResponseItems().ToArray(); 2080var messages = new List<ChatMessage> 2117var messages = new List<ChatMessage> 2152var messages = new List<ChatMessage> 2285ChatMessage[] messages = new ResponseItem[] { wsItem }.AsChatMessages().ToArray(); 2301ChatMessage[] messages = new ResponseItem[] { wsItem }.AsChatMessages().ToArray(); 2317ChatMessage[] messages = new ResponseItem[] { wsItem }.AsChatMessages().ToArray();
OpenAIHostedFileClientIntegrationTests.cs (3)
283foreach (var msg in response.Messages) 353foreach (var msg in response.Messages) 401foreach (var msg in setupResponse.Messages)
OpenAIResponseClientIntegrationTests.cs (10)
44ChatMessage message = Assert.Single(response.Messages); 95ChatMessage m = Assert.Single(response.Messages); 162ChatMessage m = Assert.Single(response.Messages); 267List<ChatMessage> input = [new ChatMessage(ChatRole.User, "Tell me the path to the README.md file for Microsoft.Extensions.AI.Abstractions in the dotnet/extensions repository")]; 286var approvalResponse = new ChatMessage(ChatRole.Tool, 531List<ChatMessage> input = [new ChatMessage(ChatRole.User, "What is on my calendar for today?")]; 706List<ChatMessage> chatHistory = [new ChatMessage(ChatRole.User, "What is 2+2? Think step by step but be very brief.")]; 732var deserializedHistory = JsonSerializer.Deserialize<List<ChatMessage>>(json, AIJsonUtilities.DefaultOptions)!; 787List<ChatMessage> chatHistory = [new ChatMessage(ChatRole.User, "What is 2+2? Think step by step but be very brief.")]; 813var deserializedHistory = JsonSerializer.Deserialize<List<ChatMessage>>(json, AIJsonUtilities.DefaultOptions)!;
OpenAIResponseClientTests.cs (26)
571List<ChatMessage> chatHistory = []; 573var assistantMessage = chatHistory.Single(m => m.Role == ChatRole.Assistant); 640List<ChatMessage> chatHistory = []; 646string serializedHistory = JsonSerializer.Serialize(chatHistory, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(List<ChatMessage>))); 647chatHistory = (List<ChatMessage>)JsonSerializer.Deserialize(serializedHistory, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(List<ChatMessage>)))!; 906ChatMessage responseMessage = Assert.Single(response.Messages); 1627var message = Assert.Single(response.Messages); 1763var messages = new List<ChatMessage> 1771var message = Assert.Single(response.Messages); 2004var message = Assert.Single(response.Messages); 2415var message = Assert.Single(response.Messages); 2624var message = Assert.Single(response.Messages); 2728var message = Assert.Single(response.Messages); 3392var message = response.Messages[0]; 3612var message = response.Messages[0]; 3737var message = response.Messages[0]; 5473var lastMessage = response.Messages.Last(); 6087var message = response.Messages[0]; 6227var userMessage = response.Messages.FirstOrDefault(m => m.Role == ChatRole.User); 6236var assistantMessage = response.Messages.LastOrDefault(m => m.Role == ChatRole.Assistant); 6290var userMessage = response.Messages.FirstOrDefault(m => m.Role == ChatRole.User); 6299var assistantMessage = response.Messages.LastOrDefault(m => m.Role == ChatRole.Assistant); 6851var message = Assert.Single(response.Messages); 7135var message = response.Messages[0]; 7301var message = Assert.Single(response.Messages);
parent\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (4)
18public static void EqualMessageLists(List<ChatMessage> expectedMessages, List<ChatMessage> actualMessages) 23var expectedMessage = expectedMessages[i]; 24var chatMessage = actualMessages[i];
Microsoft.Extensions.AI.Tests (380)
ChatCompletion\ChatClientStructuredOutputExtensionsTests.cs (9)
75var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 136var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 245var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 264var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 283var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 311var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 339var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 401var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") }; 429var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
ChatCompletion\ConfigureOptionsChatClientTests.cs (2)
76var response = await client.GetResponseAsync(Array.Empty<ChatMessage>(), providedOptions, cts.Token); 80await using var e = client.GetStreamingResponseAsync(Array.Empty<ChatMessage>(), providedOptions, cts.Token).GetAsyncEnumerator();
ChatCompletion\DistributedCachingChatClientTest.cs (9)
123private sealed class CustomCachingChatClient(IChatClient innerClient, IDistributedCache storage, Func<IEnumerable<ChatMessage>, ChatOptions?, bool> enableCaching) : 126protected override bool EnableCaching(IEnumerable<ChatMessage> messages, ChatOptions? options) => enableCaching(messages, options); 185var input = new ChatMessage(ChatRole.User, "abc"); 224var input = new ChatMessage(ChatRole.User, "abc"); 495var input = new ChatMessage(ChatRole.User, "abc"); 533var input = new ChatMessage(ChatRole.User, "abc"); 803ChatMessage expectedMessage = expected.Messages.Last(); 804ChatMessage actualMessage = actual.Messages.Last(); 878protected override string GetCacheKey(IEnumerable<ChatMessage> messages, ChatOptions? options, params ReadOnlySpan<object?> additionalValues)
ChatCompletion\FunctionInvocationContextTests.cs (1)
47List<ChatMessage> messages = [];
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (152)
34List<ChatMessage> input = 39List<ChatMessage> downstreamClientOutput = 44List<ChatMessage> expectedOutput = 70List<ChatMessage> input = 75List<ChatMessage> downstreamClientOutput = 80List<ChatMessage> expectedOutput = 117List<ChatMessage> input = 122List<ChatMessage> downstreamClientOutput = 129List<ChatMessage> expectedOutput = 167List<ChatMessage> input = 172List<ChatMessage> downstreamClientOutput = 180List<ChatMessage> expectedOutput = 212List<ChatMessage> input = 217List<ChatMessage> downstreamClientOutput = 225List<ChatMessage> expectedOutput = 254List<ChatMessage> input = 269List<ChatMessage> expectedDownstreamClientInput = 276List<ChatMessage> downstreamClientOutput = 281List<ChatMessage> output = 306List<ChatMessage> input = 322List<ChatMessage> expectedDownstreamClientInput = 329List<ChatMessage> downstreamClientOutput = 334List<ChatMessage> output = 358List<ChatMessage> input = 379List<ChatMessage> expectedDownstreamClientInput = 387List<ChatMessage> downstreamClientOutput = 392List<ChatMessage> output = 417List<ChatMessage> input = 432List<ChatMessage> expectedDownstreamClientInput = 443List<ChatMessage> downstreamClientOutput = 448List<ChatMessage> output = 476List<ChatMessage> input = 491List<ChatMessage> expectedDownstreamClientInput = 499List<ChatMessage> downstreamClientOutput = 504List<ChatMessage> nonStreamingOutput = 512List<ChatMessage> streamingOutput = 540List<ChatMessage> input = 561List<ChatMessage> expectedDownstreamClientInput = 572List<ChatMessage> downstreamClientOutput = 577List<ChatMessage> output = 606List<ChatMessage> input = 623List<ChatMessage> expectedDownstreamClientInput = 640List<ChatMessage> downstreamClientOutput = 645List<ChatMessage> nonStreamingOutput = 662List<ChatMessage> streamingOutput = 698List<ChatMessage> input = 714List<ChatMessage> expectedDownstreamClientInput = 724List<ChatMessage> downstreamClientOutput = 729List<ChatMessage> output = 756List<ChatMessage> input = 771List<ChatMessage> expectedDownstreamClientInput = 778List<ChatMessage> downstreamClientOutput = 783List<ChatMessage> output = 810List<ChatMessage> input = 835List<ChatMessage> expectedDownstreamClientInput = 844List<ChatMessage> downstreamClientOutput = 849List<ChatMessage> output = 889List<ChatMessage> input = 961List<ChatMessage> input = 1026List<ChatMessage> input = 1031Func<Queue<List<ChatMessage>>> expectedDownstreamClientInput = () => new Queue<List<ChatMessage>>( 1033new List<ChatMessage> 1037new List<ChatMessage> 1045Func<Queue<List<ChatMessage>>> downstreamClientOutput = () => new Queue<List<ChatMessage>>( 1047new List<ChatMessage> 1051new List<ChatMessage> 1057List<ChatMessage> output = 1081List<ChatMessage> input = 1111List<ChatMessage> input = 1121List<ChatMessage> expectedDownstreamClientInput = 1128List<ChatMessage> downstreamClientOutput = 1133List<ChatMessage> output = 1158List<ChatMessage> input = 1167List<ChatMessage> expectedDownstreamClientInput = 1172List<ChatMessage> downstreamClientOutput = 1177List<ChatMessage> output = 1202List<ChatMessage> input = 1215List<ChatMessage> expectedDownstreamClientInput = 1221List<ChatMessage> downstreamClientOutput = 1226List<ChatMessage> output = 1252List<ChatMessage> input = 1263List<ChatMessage> expectedDownstreamClientInput = 1269List<ChatMessage> downstreamClientOutput = 1274List<ChatMessage> output = 1297List<ChatMessage> input = 1315List<ChatMessage> expectedDownstreamClientInput = 1323List<ChatMessage> downstreamClientOutput = 1328List<ChatMessage> output = 1352List<ChatMessage> input = 1366List<ChatMessage> expectedDownstreamClientInput = 1374List<ChatMessage> downstreamClientOutput = 1379List<ChatMessage> output = 1410List<ChatMessage> input = 1423List<ChatMessage> expectedOutput = 1467List<ChatMessage> input = [new ChatMessage(ChatRole.User, "hello")]; 1475IEnumerable<ChatMessage> contents, ChatOptions? actualOptions, [EnumeratorCancellation] CancellationToken actualCancellationToken) 1496var updates = service.GetStreamingResponseAsync(new EnumeratedOnceEnumerable<ChatMessage>(input), options, cts.Token); 1543List<ChatMessage> input = [new ChatMessage(ChatRole.User, "hello")]; 1551IEnumerable<ChatMessage> contents, ChatOptions? actualOptions, [EnumeratorCancellation] CancellationToken actualCancellationToken) 1577var updates = service.GetStreamingResponseAsync(new EnumeratedOnceEnumerable<ChatMessage>(input), options, cts.Token); 1641List<ChatMessage> input = [new ChatMessage(ChatRole.User, "hello")]; 1645List<ChatMessage> downstreamClientOutput = 1651List<ChatMessage> expectedOutput = 1683List<ChatMessage> input = 1696List<ChatMessage> downstreamClientOutput = 1702List<ChatMessage> expectedOutput = 1734List<ChatMessage> input = 1739List<ChatMessage> downstreamClientOutput = 1748List<ChatMessage> expectedOutput = 1777List<ChatMessage> input = 1792List<ChatMessage> expectedDownstreamClientInput = 1813List<ChatMessage> downstreamClientOutput = 1821List<ChatMessage> output = 1861List<ChatMessage> input = 1876List<ChatMessage> expectedDownstreamClientInput = [ 1898List<ChatMessage> downstreamClientOutput = 1908List<ChatMessage> output = [ 1931private static Task<List<ChatMessage>> InvokeAndAssertAsync( 1933List<ChatMessage> input, 1934List<ChatMessage> downstreamClientOutput, 1935List<ChatMessage> expectedOutput, 1936List<ChatMessage>? expectedDownstreamClientInput = null, 1942new Queue<List<ChatMessage>>(new[] { downstreamClientOutput }), 1944expectedDownstreamClientInput is null ? null : new Queue<List<ChatMessage>>(new[] { expectedDownstreamClientInput }), 1948private static async Task<List<ChatMessage>> InvokeAndAssertMultiRoundAsync( 1950List<ChatMessage> input, 1951Queue<List<ChatMessage>> downstreamClientOutput, 1952List<ChatMessage> expectedOutput, 1953Queue<List<ChatMessage>>? expectedDownstreamClientInput = null, 1987var result = await service.GetResponseAsync(new EnumeratedOnceEnumerable<ChatMessage>(CloneInput(input)), options, cts.Token); 1990var actualOutput = result.Messages as List<ChatMessage> ?? result.Messages.ToList(); 2019private static Task<List<ChatMessage>> InvokeAndAssertStreamingAsync( 2021List<ChatMessage> input, 2022List<ChatMessage> downstreamClientOutput, 2023List<ChatMessage> expectedOutput, 2024List<ChatMessage>? expectedDownstreamClientInput = null, 2030new Queue<List<ChatMessage>>(new[] { downstreamClientOutput }), 2032expectedDownstreamClientInput is null ? null : new Queue<List<ChatMessage>>(new[] { expectedDownstreamClientInput }), 2036private static async Task<List<ChatMessage>> InvokeAndAssertStreamingMultiRoundAsync( 2038List<ChatMessage> input, 2039Queue<List<ChatMessage>> downstreamClientOutput, 2040List<ChatMessage> expectedOutput, 2041Queue<List<ChatMessage>>? expectedDownstreamClientInput = null, 2069var result = await service.GetStreamingResponseAsync(new EnumeratedOnceEnumerable<ChatMessage>(CloneInput(input)), options, cts.Token).ToChatResponseAsync(); 2072var actualOutput = result.Messages as List<ChatMessage> ?? result.Messages.ToList(); 2089private static List<ChatMessage> CloneInput(List<ChatMessage> input) => 2125IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 2132IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 2138private static void NormalizeApprovalFlags(IEnumerable<ChatMessage> messages)
ChatCompletion\FunctionInvokingChatClientTests.cs (98)
91List<ChatMessage> plan = 125List<ChatMessage> plan = 158List<ChatMessage> plan = 189List<ChatMessage> plan = 249List<ChatMessage> plan = 293List<ChatMessage> plan = 327List<ChatMessage> plan = 376var toolMessage = msgs.FirstOrDefault(m => m.Role == ChatRole.Tool); 389var toolMessage = msgs.FirstOrDefault(m => m.Role == ChatRole.Tool); 414var messages = new List<ChatMessage> 430var toolMessage = response.Messages.First(m => m.Role == ChatRole.Tool); 457var toolMessage = msgs.FirstOrDefault(m => m.Role == ChatRole.Tool); 470var toolMessage = msgs.FirstOrDefault(m => m.Role == ChatRole.Tool); 493var messages = new List<ChatMessage> 510var toolMessage = response.Messages.First(m => m.Role == ChatRole.Tool); 538var toolMessage = msgs.FirstOrDefault(m => m.Role == ChatRole.Tool); 551var toolMessage = msgs.FirstOrDefault(m => m.Role == ChatRole.Tool); 577var messages = new List<ChatMessage> 594var toolMessage = response.Messages.First(m => m.Role == ChatRole.Tool); 634List<ChatMessage> plan = 668var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent($"callId{capturedOptions.Count}", "Func1")]); 712var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent($"callId{capturedOptions.Count}", "Func1")]); 759var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]); 764var message = new ChatMessage(ChatRole.Assistant, "Done"); 804var message = new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("callId1", "Func1")]); 856List<ChatMessage> plan = 934List<ChatMessage> plan = 951private static IEnumerable<ChatMessage> CreateFunctionCallIterationPlan(ref int callIndex, params bool[] shouldThrow) 953var assistantMessage = new ChatMessage(ChatRole.Assistant, []); 954var toolMessage = new ChatMessage(ChatRole.Tool, []); 981List<ChatMessage> plan = 998static void Validate(List<ChatMessage> finalChat) 1018List<ChatMessage> plan = 1040List<ChatMessage> plan = 1097List<ChatMessage> plan = 1175var messages = new List<ChatMessage> 1233var messages = new List<ChatMessage> 1244ChatMessage message = chatContents.Count() is 1 or 3 ? 1291List<ChatMessage> planBeforeTermination = 1301List<ChatMessage> plan = 1316async Task InvokeAsync(Func<Task<List<ChatMessage>>> work) 1360var existingSearchResult = chatContents.SingleOrDefault(m => m.Role == ChatRole.Tool); 1369var message = new ChatMessage(ChatRole.Assistant, resultContents); 1377List<ChatMessage> messages = [new(ChatRole.User, "hello")]; 1383var lastMessage = messages.Last(); 1404Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, ChatResponse> callback = 1447List<ChatMessage> plan = 1476List<ChatMessage> plan = 1529List<ChatMessage> planForContinue = 1548List<ChatMessage> fullPlanWithUnknown = 1577List<ChatMessage> fullPlan = 1585List<ChatMessage> expected = fullPlan.Take(2).ToList(); 1606List<ChatMessage> fullPlan = 1617List<ChatMessage> expected = fullPlan.Take(2).ToList(); 1640List<ChatMessage> messages = []; 1679List<ChatMessage> plan = 1740ChatMessage message = callCount == 1 1790List<ChatMessage> plan = 1832List<ChatMessage> plan = 1882List<ChatMessage> plan = 1954List<ChatMessage> plan = 2003List<ChatMessage> plan = 2014var functionCallMessage = chat.First(m => m.Contents.Any(c => c is FunctionCallContent)); 2042var message = new ChatMessage(ChatRole.Assistant, [alreadyProcessedFunctionCall]); 2048var message = new ChatMessage(ChatRole.Assistant, [alreadyProcessedFunctionCall]); 2097var message = new ChatMessage(ChatRole.Assistant, [needsProcessing, alreadyProcessed]); 2103var message = new ChatMessage(ChatRole.Assistant, "done"); 2112var message = new ChatMessage(ChatRole.Assistant, [needsProcessing, alreadyProcessed]); 2118var message = new ChatMessage(ChatRole.Assistant, "done"); 2198private static async Task<List<ChatMessage>> InvokeAndAssertAsync( 2200List<ChatMessage> plan, 2201List<ChatMessage>? expected = null, 2210List<ChatMessage> chat = [plan[0]]; 2224var message = new ChatMessage(ChatRole.Assistant, CloneContents(plan[contents.Count()].Contents)) 2234var result = await service.GetResponseAsync(new EnumeratedOnceEnumerable<ChatMessage>(chat), options, cts.Token); 2268private static async Task<List<ChatMessage>> InvokeAndAssertStreamingAsync( 2270List<ChatMessage> plan, 2271List<ChatMessage>? expected = null, 2280List<ChatMessage> chat = [plan[0]]; 2288ChatMessage message = new(ChatRole.Assistant, CloneContents(plan[contents.Count()].Contents)) 2298var result = await service.GetStreamingResponseAsync(new EnumeratedOnceEnumerable<ChatMessage>(chat), options, cts.Token).ToChatResponseAsync(); 2408ChatMessage message; 2502ChatMessage message; 2607ChatMessage message; 2708ChatMessage message; 2809ChatMessage message; 2901ChatMessage message; 2987ChatMessage message; 3088ChatMessage message; 3194ChatMessage message; 3255List<ChatMessage> plan = 3285List<ChatMessage> plan = 3293List<ChatMessage> expected = plan.Take(2).ToList(); 3321List<ChatMessage> plan = 3350List<ChatMessage> plan = 3357List<ChatMessage> expected = 3393var messages = new List<ChatMessage> 3430var messages = new List<ChatMessage>
ChatCompletion\ImageGeneratingChatClientTests.cs (2)
316var responseMessage = new ChatMessage(ChatRole.Assistant, 336var message = response.Messages[0];
ChatCompletion\OpenTelemetryChatClientTests.cs (10)
67IEnumerable<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken) 112List<ChatMessage> messages = 419IEnumerable<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken) 440List<ChatMessage> messages = 601List<ChatMessage> messages = 673IEnumerable<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken) 703List<ChatMessage> messages = 841List<ChatMessage> messages = 914IEnumerable<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken) 1101IEnumerable<ChatMessage> messages, ChatOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken)
ChatCompletion\ReducingChatClientTests.cs (8)
35var originalMessages = new List<ChatMessage> 43var reducedMessages = new List<ChatMessage> 98var reducedMessages = new List<ChatMessage> { new(ChatRole.User, "Reduced message") }; 119await client.GetResponseAsync(new List<ChatMessage> { new(ChatRole.User, "Original message") }); 169public IEnumerable<ChatMessage>? ReducedMessages { get; set; } 171public IEnumerable<ChatMessage>? LastMessagesProvided { get; private set; } 173public Task<IEnumerable<ChatMessage>> ReduceAsync(IEnumerable<ChatMessage> messages, CancellationToken cancellationToken)
ChatCompletion\UseDelegateChatClientTests.cs (6)
28IList<ChatMessage> expectedMessages = []; 78IList<ChatMessage> expectedMessages = []; 120IList<ChatMessage> expectedMessages = []; 147IEnumerable<ChatMessage> messages, ChatOptions? options, IChatClient innerClient, [EnumeratorCancellation] CancellationToken cancellationToken) 171IList<ChatMessage> expectedMessages = []; 218IEnumerable<ChatMessage> messages, ChatOptions? options, IChatClient innerClient, [EnumeratorCancellation] CancellationToken cancellationToken)
ChatReduction\MessageCountingChatReducerTests.cs (8)
51List<ChatMessage> messages = 86List<ChatMessage> messages = 125List<ChatMessage> messages = 164var messages = new List<ChatMessage>(); 179var expectedMessages = new Action<ChatMessage>[targetCount]; 200List<ChatMessage> messages = 221List<ChatMessage> messages = 239List<ChatMessage> messages =
ChatReduction\SummarizingChatReducerTests.cs (8)
67List<ChatMessage> messages = 94List<ChatMessage> messages = 139List<ChatMessage> messages = 185List<ChatMessage> messages = 239var messages = new List<ChatMessage>(); 274List<ChatMessage> messages = 300List<ChatMessage> messages = 328List<ChatMessage> messages =
ChatRouting\OrderedFailoverChatClientTests.cs (2)
382IEnumerable<ChatMessage> messages, ChatOptions? options = null, 387IEnumerable<ChatMessage> messages, ChatOptions? options = null,
ChatRouting\SemanticRoutingChatClientTests.cs (2)
243IEnumerable<ChatMessage> messages, ChatOptions? options = null, 248IEnumerable<ChatMessage> messages, ChatOptions? options = null,
Generated\361d1da7f942c932\TestJsonSerializerContext.ChatResponse.g.cs (3)
51var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatResponse).GetProperty("Messages", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>), global::System.Array.Empty<global::System.Type>(), null), 69properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, info0);
Generated\361d1da7f942c932\TestJsonSerializerContext.GetJsonTypeInfo.g.cs (2)
74if (type == typeof(global::Microsoft.Extensions.AI.ChatMessage)) 294if (type == typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>))
Generated\361d1da7f942c932\TestJsonSerializerContext.IListChatMessage.g.cs (11)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>? _IListChatMessage; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> IListChatMessage 22get => _IListChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> Create_IListChatMessage(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> jsonTypeInfo)) 29var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>> 35jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIListInfo<global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>, global::Microsoft.Extensions.AI.ChatMessage>(options, info); 45private void IListChatMessageSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.ChatMessage>? value)
Generated\Basic.CompilerLog.Util\Basic.CompilerLog.Util.Impl.BasicGeneratedFilesAnalyzerReference\TestJsonSerializerContext.ChatMessage.g.cs (38)
13private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>? _ChatMessage; 19public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> ChatMessage 22get => _ChatMessage ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage>)Options.GetTypeInfo(typeof(global::Microsoft.Extensions.AI.ChatMessage)); 25private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> Create_ChatMessage(global::System.Text.Json.JsonSerializerOptions options) 27if (!TryGetTypeInfoForRuntimeCustomConverter<global::Microsoft.Extensions.AI.ChatMessage>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Microsoft.Extensions.AI.ChatMessage> jsonTypeInfo)) 29var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::Microsoft.Extensions.AI.ChatMessage> 35ConstructorAttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty<global::System.Type>(), modifiers: null), 39jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::Microsoft.Extensions.AI.ChatMessage>(options, objectInfo); 56DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 58Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName, 59Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AuthorName = value!, 66AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AuthorName", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 76DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 78Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt, 79Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).CreatedAt = value!, 86AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("CreatedAt", InstanceMemberBindingFlags, null, typeof(global::System.DateTimeOffset?), global::System.Array.Empty<global::System.Type>(), null), 96DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 98Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role, 99Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Role = value!, 106AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Role", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.ChatRole), global::System.Array.Empty<global::System.Type>(), null), 116DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 126AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Text", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 137DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 139Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents, 140Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).Contents = value!, 147AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("Contents", InstanceMemberBindingFlags, null, typeof(global::System.Collections.Generic.IList<global::Microsoft.Extensions.AI.AIContent>), global::System.Array.Empty<global::System.Type>(), null), 159DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 161Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId, 162Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).MessageId = value!, 169AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("MessageId", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty<global::System.Type>(), null), 179DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 189AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("RawRepresentation", InstanceMemberBindingFlags, null, typeof(object), global::System.Array.Empty<global::System.Type>(), null), 199DeclaringType = typeof(global::Microsoft.Extensions.AI.ChatMessage), 201Getter = static obj => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties, 202Setter = static (obj, value) => ((global::Microsoft.Extensions.AI.ChatMessage)obj).AdditionalProperties = value!, 209AttributeProviderFactory = static () => typeof(global::Microsoft.Extensions.AI.ChatMessage).GetProperty("AdditionalProperties", InstanceMemberBindingFlags, null, typeof(global::Microsoft.Extensions.AI.AdditionalPropertiesDictionary), global::System.Array.Empty<global::System.Type>(), null),
parent\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (4)
18public static void EqualMessageLists(List<ChatMessage> expectedMessages, List<ChatMessage> actualMessages) 23var expectedMessage = expectedMessages[i]; 24var chatMessage = actualMessages[i];
parent\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
20public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>>? GetResponseAsyncCallback { get; set; } 22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 29public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
14[JsonSerializable(typeof(IList<ChatMessage>))]
Microsoft.Extensions.DataIngestion (8)
Processors\ClassificationEnricher.cs (2)
23private readonly ChatMessage _systemPrompt; 77private static ChatMessage CreateSystemPrompt(ReadOnlySpan<string> predefinedClasses, string fallbackClass)
Processors\ImageAlternativeTextEnricher.cs (1)
21private readonly ChatMessage _systemPrompt;
Processors\KeywordEnricher.cs (2)
24private readonly ChatMessage _systemPrompt; 80private static ChatMessage CreateSystemPrompt(int maxKeywords, ReadOnlySpan<string> predefinedKeywords, double confidenceThreshold)
Processors\SentimentEnricher.cs (1)
22private readonly ChatMessage _systemPrompt;
Processors\SummaryEnricher.cs (1)
22private readonly ChatMessage _systemPrompt;
Utils\Batching.cs (1)
21ChatMessage systemPrompt,
Microsoft.Extensions.DataIngestion.Tests (4)
parent\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (4)
20public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>>? GetResponseAsyncCallback { get; set; } 22public Func<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; } 29public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 32public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.ML.GenAI.Core (7)
CausalLMPipelineChatClient.cs (3)
36public virtual Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) 47var chatMessage = new ChatMessage(ChatRole.Assistant, output); 59IEnumerable<ChatMessage> messages,
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(IEnumerable<ChatMessage> messages, ChatOptions? options = null, bool appendAssistantTag = true);
Microsoft.ML.GenAI.Core.Tests (3)
CausalLMDatasetTest.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(IEnumerable<ChatMessage> messages, ChatOptions? options = null, bool appendAssistantTag = true) 106foreach (var message in messages)
Llama3CausalLMChatClient.cs (2)
28IEnumerable<ChatMessage> messages, 47IEnumerable<ChatMessage> messages,
Microsoft.ML.GenAI.Phi (4)
Phi3\Phi3CausalLMChatClient.cs (2)
33IEnumerable<ChatMessage> messages, 52IEnumerable<ChatMessage> messages,
Phi3\Phi3ChatTemplateBuilder.cs (2)
92public string BuildPrompt(IEnumerable<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);