From 0a2fd4a4c2d1fadc29cabb8594807b1161b56567 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 18 Apr 2024 22:25:22 +0900 Subject: [PATCH] Add autoContinueChat setting --- src/lang/en.ts | 4 ++- src/lib/Setting/Pages/AdvancedSettings.svelte | 3 +++ src/ts/process/index.ts | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/lang/en.ts b/src/lang/en.ts index 7c8ff5f4..ea8b4df4 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -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=\"\"` 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)", } \ No newline at end of file diff --git a/src/lib/Setting/Pages/AdvancedSettings.svelte b/src/lib/Setting/Pages/AdvancedSettings.svelte index b752dbda..541cd2a1 100644 --- a/src/lib/Setting/Pages/AdvancedSettings.svelte +++ b/src/lib/Setting/Pages/AdvancedSettings.svelte @@ -73,6 +73,9 @@
+
+ +
diff --git a/src/ts/process/index.ts b/src/ts/process/index.ts index 65fed00a..37bc03c8 100644 --- a/src/ts/process/index.ts +++ b/src/ts/process/index.ts @@ -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,