Repository navigation
Fixes #7479 - #7976
Open
sabaka-chabaka wants to merge 1 commit into
Open
Fixes #7479#7976sabaka-chabaka wants to merge 1 commit into
sabaka-chabaka wants to merge 1 commit into
Conversation
…tClient When streaming, the update produced for a completed function_call output item had a null MessageId, because lastMessageId is only populated for MessageResponseItem. As a result, ToChatResponse() produced a ChatMessage with FunctionCallContent but no MessageId, unlike the chat completions client and unlike the Responses client when the model returns only text. Use the function call item's Id as the MessageId for that update. Because function calls now carry their own item id, a streamed response that interleaves a function call, its function_call_output, and a subsequent assistant message is coalesced into two ChatMessages (one for the function call + result, keyed by the function call id, and one for the text message) instead of one. Update StreamingResponseWithFunctionCallOutput_YieldsFunctionResultContent accordingly and add StreamingResponseWithFunctionCall_PreservesMessageId. Fixes dotnet#7479
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7479
Problem
With
OpenAIResponsesChatClientin streaming mode, theChatResponseUpdatecarrying a
FunctionCallContenthadMessageId == null.ToChatResponse()then produced a
ChatMessagewithout aMessageId, which differs from thechat completions-based
IChatClientand from the Responses client when nofunction call is involved.
Cause
lastMessageIdis only set when anoutput_item.addedupdate is aMessageResponseItem. For aFunctionCallResponseItemit is never set, sothe update created in the
output_item.donehandler had no id.Fix
Pass the function call item's id when creating that update:
Behavior change worth calling out
A stream of
function_call→function_call_output→messagenowcoalesces into two
ChatMessages rather than one:MessageId = fc_...:FunctionCallContent+FunctionResultContent(the result update has no id, so it joins the preceding message)
MessageId = msg_...: the textPreviously the function call update had no id, so everything was merged
into a single message. I think the new shape is more faithful to the
service's item boundaries, but flagging it for reviewers.
Tests
StreamingResponseWithFunctionCall_PreservesMessageId.StreamingResponseWithFunctionCallOutput_YieldsFunctionResultContentto expect two messages with ids
fc_001/msg_001.OpenAIResponseClientTests: 130/130 on net10.0.Not covered
The workaround in the issue also assigns ids to reasoning updates
(
StreamingResponseReasoningSummaryTextDeltaUpdate,ReasoningResponseItemdone). This PR only addresses the function callcase described in the title; reasoning updates are unchanged.
Microsoft Reviewers: Open in CodeFlow