[fix] tokenizer problem 2

This commit is contained in:
kwaroran
2023-06-10 02:38:36 +09:00
parent 6fc60805e6
commit 08cd214bcb
3 changed files with 6 additions and 1 deletions

View File

@@ -144,6 +144,7 @@
try {
await sendChat()
} catch (error) {
console.error(error)
alertError(`${error}`)
}
rerolls.push(cloneDeep($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message))

View File

@@ -202,7 +202,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
let currentTokens = 0
for(const key in unformated){
currentTokens += await tokenizer.tokenizeChat(unformated[key])
const chats = unformated[key] as OpenAIChat[]
for(const chat of chats){
currentTokens += await tokenizer.tokenizeChat(chat)
}
}

View File

@@ -49,6 +49,7 @@ export class ChatTokenizer {
this.useName = useName
}
async tokenizeChat(data:OpenAIChat) {
console.log(data.content)
let encoded = (await encode(data.content)).length + this.chatAdditonalTokens
if(data.name && this.useName ==='name'){
encoded += (await encode(data.name)).length