fix: token speed should not be calculated based on state updates #4159
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.
Describe Your Changes
This PR addresses an issue where message rendering could impact token speed, which is not intended. The token speed calculation should not be affected by component rendering, but rather based on the received tokens.
Ensure that rendering of complicated message contents doesn’t reduce token speed (currently it does).
Token speed is now calculated on message receive, assuming each event yields one token.
The formula for calculating token speed is given by:
Where:
Screenshot demonstrate a case where convo is very long, but the token speed is not reduced (it's reduced to ~3 before where it should be ~8x)
Changes made
New State Management:
tokenSpeedAtom
inChatMessage.atom.ts
to store token processing speed details using Jotai.ModelHandler.tsx:
tokenSpeedAtom
.ModelHandler
component. This involves usingsetTokenSpeed
to track the speed at which tokens are processed for each message.useSendChatMessage.ts:
queuedMessageAtom
and replace its function by settingtokenSpeedAtom
toundefined
when a new message is sent, resetting the state for new calculations.index.tsx (SimpleTextMessage Component):
useAtomValue
to get the current token speed fromtokenSpeedAtom
.tokenSpeed
is above zero, using the new data structure.Types:
token.d.ts
defining theTokenSpeed
type, which includes fields formessage
,tokenSpeed
,tokenCount
, andlastTimestamp
, used to manage token speed calculations.Overall, the feature updates the application with functionality to calculate, store, and display the speed at which tokens are processed for chat messages.