fix total token in stream mode

This commit is contained in:
2023-04-04 00:39:58 +08:00
parent 8c049c9ee9
commit 8f1a327ea0

View File

@@ -107,6 +107,14 @@ export default function ChatBOX(props: {
// manually copy status from client to chatStore
chatStore.maxTokens = client.max_tokens;
chatStore.tokenMargin = client.tokens_margin;
// manually estimate token
client.total_tokens = 0;
for (const msg of chatStore.history
.filter(({ hide }) => !hide)
.slice(chatStore.postBeginIndex)) {
client.total_tokens += msg.token;
}
chatStore.totalTokens = client.total_tokens;
setChatStore({ ...chatStore });
setGeneratingMessage("");
setShowGenerating(false);