|
@@ -11,6 +11,7 @@ import { StoreKey } from "../constant";
|
|
|
import { api, RequestMessage } from "../client/api";
|
|
|
import { ChatControllerPool } from "../client/controller";
|
|
|
import { prettyObject } from "../utils/format";
|
|
|
+import { estimateTokenLength } from "../utils/token";
|
|
|
|
|
|
export type ChatMessage = RequestMessage & {
|
|
|
date: string;
|
|
@@ -102,7 +103,7 @@ interface ChatStore {
|
|
|
}
|
|
|
|
|
|
function countMessages(msgs: ChatMessage[]) {
|
|
|
- return msgs.reduce((pre, cur) => pre + cur.content.length, 0);
|
|
|
+ return msgs.reduce((pre, cur) => pre + estimateTokenLength(cur.content), 0);
|
|
|
}
|
|
|
|
|
|
export const useChatStore = create<ChatStore>()(
|