-
Notifications
You must be signed in to change notification settings - Fork 4k
Python: Emit usage chunks via callback as they have empty content #12447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
@@ -450,9 +450,22 @@ async def invoke_stream( | |||
response.name = self.name | |||
response_builder.append(response.content) | |||
|
|||
# Divert usage-based responses to the intermediate message handler, if present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: is this what dotnet is doing? I wonder if this is needed as we are draining the messages below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We drain function calling related methods below because they exist in the chat history. Usage related chunks aren't contained in the chat history, so they need specific handling here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the usage chunks be part of the chat history at the chat completion service level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just emit via callback? Then if callers want to handle the usage, they are free too at their discretion. This will remove emitting empty content as we're now doing.
Motivation and Context
We recently made an update to emit streaming chunk usage for the ChatCompletionAgent, but that can now include further complications as responses with usage will have empty content. We should be emitting this information via the optional
on_intermediate_message
callback, so that the caller has content provided in the normal flow (anything un-related to the final message should be handled via the callback).Description
Fix the usage chunk flow and update the sample to show this behavior.
Contribution Checklist