Add autoContinueChat setting
This commit is contained in:
@@ -120,6 +120,7 @@ export const languageEnglish = {
|
||||
additionalParams: "Additional parameters that would be added to the request body. if you want to exclude some parameters, you can put `{{none}}` to the value. if you want to add a header instead of body, you can put `header::` in front of the key like `header::Authorization`. if you want value as json, you can put `json::` in front of the value like `json::{\"key\":\"value\"}`. otherwise, type of the value would be determined automatically.",
|
||||
antiClaudeOverload: "If Claude overload happens, RisuAI would try to prevent it by continuing with same prompt, making it less likely to happen. works only for streamed responses. this could not work for non-official api endpoints.",
|
||||
triggerScript: "Trigger Script is a custom script that runs when a condition is met. it can be used to modify the chat data, run a command, change variable, and etc. the type depends when it is triggered. it can also be run by buttons, which can be used with {{button::Display::TriggerName}}, or HTML buttons with `risu-trigger=\"<TriggerName>\"` attribute.",
|
||||
autoContinueChat: "If enabled, it will try to continue the chat if it doesn't ends with a punctuation. DONT USE THIS WITH LANGUAGES THAT DOESN'T USE PUNCTUATION.",
|
||||
},
|
||||
setup: {
|
||||
chooseProvider: "Choose AI Provider",
|
||||
@@ -572,5 +573,6 @@ export const languageEnglish = {
|
||||
importFromRealmDesc: "Choose over 1000 characters in RisuRealm",
|
||||
random: "Random",
|
||||
metaData: "Meta Data",
|
||||
autoContinueMinTokens: "Target Tokens Auto Continue",
|
||||
autoContinueMinTokens: "Target Tokens (Auto Continue)",
|
||||
autoContinueChat: "Anti-Incomplete Response (Auto Continue)",
|
||||
}
|
||||
@@ -73,6 +73,9 @@
|
||||
<div class="flex items-center mt-4">
|
||||
<Check bind:check={$DataBase.autofillRequestUrl} name={language.autoFillRequestURL}> <Help key="autoFillRequestURL"/></Check>
|
||||
</div>
|
||||
<div class="flex items-center mt-4">
|
||||
<Check bind:check={$DataBase.autoContinueChat} name={language.autoContinueChat}> <Help key="autoContinueChat"/></Check>
|
||||
</div>
|
||||
<div class="flex items-center mt-4">
|
||||
<Check bind:check={$DataBase.newOAIHandle} name={language.newOAIHandle}/>
|
||||
</div>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user