Add autoContinueChat setting

This commit is contained in:
kwaroran
2024-04-18 22:25:22 +09:00
parent f47f2e95a5
commit 0a2fd4a4c2
3 changed files with 32 additions and 1 deletions

View File

@@ -1132,8 +1132,34 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
}
}
let needsAutoContinue = false
const resultTokens = await tokenize(result) + (arg.usedContinueTokens || 0)
if(db.autoContinueMinTokens > 0 && resultTokens < db.autoContinueMinTokens){
needsAutoContinue = true
}
if(db.autoContinueChat){
//if result doesn't end with punctuation or special characters, auto continue
const lastChar = result.trim().at(-1)
const punctuation = [
'.', '!', '?', '。', '', '', '…', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '|', '\\', ':', ';', '"', "'", '<', '>', ',', '.', '/', '~', '`', ' ',
'¡', '¿', '‽', '⁉'
]
if(lastChar && !(punctuation.indexOf(lastChar) !== -1
//spacing modifier letters
|| (lastChar.charCodeAt(0) >= 0x02B0 && lastChar.charCodeAt(0) <= 0x02FF)
//combining diacritical marks
|| (lastChar.charCodeAt(0) >= 0x0300 && lastChar.charCodeAt(0) <= 0x036F)
//hebrew punctuation
|| (lastChar.charCodeAt(0) >= 0x0590 && lastChar.charCodeAt(0) <= 0x05CF)
//CJK symbols and punctuation
|| (lastChar.charCodeAt(0) >= 0x3000 && lastChar.charCodeAt(0) <= 0x303F)
)){
needsAutoContinue = true
}
}
if(needsAutoContinue){
doingChat.set(false)
return await sendChat(chatProcessIndex, {
chatAdditonalTokens: arg.chatAdditonalTokens,