update token when setChatStore

This commit is contained in:
2023-07-20 11:34:15 +08:00
parent dba39c771f
commit 5f4b360b05

View File

@@ -164,6 +164,16 @@ export function App() {
chatStore.postBeginIndex = chatStore.postBeginIndex =
chatStore.postBeginIndex < 0 ? 0 : 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); _setChatStore(chatStore);
}; };
useEffect(() => { useEffect(() => {