calculate token and forget some message

This commit is contained in:
2023-03-28 21:12:34 +08:00
parent 26a66d112b
commit 7c34379ecb
3 changed files with 19 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import { ChatStore } from "./app";
import { calculate_token_length } from "./chatgpt";
interface Props {
messageIndex: number;
@@ -24,6 +25,10 @@ export default function Message(props: Props) {
) {
chatStore.history.splice(messageIndex, 1);
chatStore.postBeginIndex = Math.max(chatStore.postBeginIndex - 1, 0);
chatStore.totalTokens = Math.max(
0,
chatStore.totalTokens - calculate_token_length(chat.content)
);
setChatStore({ ...chatStore });
}
}}