From 6eeb1a06995e4cc71f907e42b34f9d729bbd8b4c Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 15 Feb 2025 09:34:29 -0500 Subject: [PATCH] Tweak a comment in FunctionInvokingChatClient --- .../ChatCompletion/FunctionInvokingChatClient.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs index 2420c401ceb..6ad57a0c1d0 100644 --- a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs @@ -341,12 +341,14 @@ public override async IAsyncEnumerable GetStreamingResponseA functionCallContents.Clear(); await foreach (var update in base.GetStreamingResponseAsync(chatMessages, options, cancellationToken).ConfigureAwait(false)) { - // We're going to emit all StreamingChatMessage items upstream, even ones that represent - // function calls, because a given StreamingChatMessage can contain other content, too. - // And if we yield the function calls, and the consumer adds all the content into a message - // that's then added into history, they'll end up with function call contents that aren't - // directly paired with function result contents, which may cause issues for some models - // when the history is later sent again. + // We're going to emit all ChatResponseUpdates upstream, even ones that contain function call + // content, because a given ChatResponseUpdate can contain other content/metadata. But if we + // yield the function calls, and the consumer adds all the content into a message that's then + // added into history, they'll end up with function call contents that aren't directly paired + // with function result contents, which may cause issues for some models when the history is + // later sent again. We thus remove the FunctionCallContent instances from the updates before + // yielding them, tracking those FunctionCallContents separately so they can be processed and + // added to the chat history. // Find all the FCCs. We need to track these separately in order to be able to process them later. int preFccCount = functionCallContents.Count;