Update conversation metadata with cost and token metrics #7745
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.
This PR updates the conversation metadata to include cost/token metrics from events.
Changes
Added new fields to
ConversationMetadata
class:accumulated_cost
: Tracks the total cost of the conversationprompt_tokens
: Tracks the number of prompt tokens usedcompletion_tokens
: Tracks the number of completion tokens usedtotal_tokens
: Tracks the total number of tokens usedRenamed
_update_timestamp_for_conversation
to_update_conversation_for_event
to better reflect its expanded purposeModified
_create_conversation_update_callback
to pass the event to the callback functionUpdated the function to extract and store metrics from the event when available
Added a migration script (
scripts/migrate_conversation_metadata.py
) to update existing conversation metadata files with the new fieldsTo run this PR locally, use the following command: