From 5f4b360b057ac6bee1f4edefed9c939516bc1167 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Thu, 20 Jul 2023 11:34:15 +0800 Subject: [PATCH] update token when setChatStore --- src/app.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app.tsx b/src/app.tsx index 471ba79..d11e175 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -164,6 +164,16 @@ export function App() { chatStore.postBeginIndex = chatStore.postBeginIndex < 0 ? 0 : chatStore.postBeginIndex; + // manually estimate token + chatStore.totalTokens = calculate_token_length( + chatStore.systemMessageContent + ); + for (const msg of chatStore.history + .filter(({ hide }) => !hide) + .slice(chatStore.postBeginIndex)) { + chatStore.totalTokens += msg.token; + } + _setChatStore(chatStore); }; useEffect(() => {