mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-09 07:30:43 +08:00
feat: new token count function
This commit is contained in:
@@ -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>()(
|
||||
|
Reference in New Issue
Block a user