From 838eaf81c810a9e2390ea344b14a75a71e774c8b Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Wed, 2 Aug 2023 21:14:24 +0900 Subject: [PATCH 1/7] [fix] prompt template and autosuggest --- src/lib/ChatScreens/Suggestion.svelte | 10 ++++------ src/ts/process/request.ts | 2 +- src/ts/process/stringlize.ts | 11 ++++++++--- src/ts/storage/defaultPrompts.ts | 12 +----------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/lib/ChatScreens/Suggestion.svelte b/src/lib/ChatScreens/Suggestion.svelte index fab8ffdf..153a20b1 100644 --- a/src/lib/ChatScreens/Suggestion.svelte +++ b/src/lib/ChatScreens/Suggestion.svelte @@ -77,16 +77,14 @@ if($DataBase.subModel === "textgen_webui"){ promptbody = [ + ...lastMessages.map(({ role, data }) => ({ + role: role === "user" ? "user" as const : "assistant" as const, + content: data, + })), { role: 'system', content: replacePlaceholders($DataBase.autoSuggestPrompt, currentChar.name) }, - { - role: 'user', - content: lastMessages.map(({ role, data }) => `${ - role === 'char' ? currentChar.name : $DataBase.username - }: ${data}`).join("\n\n") + `\n\n${$DataBase.username}:` - }, ] } diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index f1fb3ea0..ab8a01aa 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -383,7 +383,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' let blockingUrl = db.textgenWebUIBlockingURL.replace(/\/api.*/, "/api/v1/generate") let bodyTemplate:any const suggesting = model === "submodel" - const proompt = stringlizeChatOba(formated, suggesting) + const proompt = stringlizeChatOba(formated, currentChar.name, suggesting) const stopStrings = getStopStrings(suggesting) console.log(proompt) console.log(stopStrings) diff --git a/src/ts/process/stringlize.ts b/src/ts/process/stringlize.ts index 44919e5e..d65fe79c 100644 --- a/src/ts/process/stringlize.ts +++ b/src/ts/process/stringlize.ts @@ -29,7 +29,7 @@ function appendWhitespace(prefix:string, seperator:string=" ") { } return prefix } -export function stringlizeChatOba(formated:OpenAIChat[], suggesting:boolean=false){ +export function stringlizeChatOba(formated:OpenAIChat[], characterName:string='', suggesting:boolean=false){ const db = get(DataBase) let resultString:string[] = [] let { header, systemPrefix, userPrefix, assistantPrefix, seperator } = db.ooba.formating; @@ -45,21 +45,24 @@ export function stringlizeChatOba(formated:OpenAIChat[], suggesting:boolean=fals continue } let prefix = "" + let name = "" if(form.role === 'user'){ prefix = appendWhitespace(userPrefix, seperator) + name = `${db.username}: ` } else if(form.role === 'assistant'){ prefix = appendWhitespace(assistantPrefix, seperator) + name = `${characterName}: ` } else if(form.role === 'system'){ prefix = appendWhitespace(systemPrefix, seperator) } - resultString.push(prefix + form.content) + resultString.push(prefix + name + form.content) } if (suggesting){ resultString.push(appendWhitespace(assistantPrefix, seperator) + "\n" + db.autoSuggestPrefix) } else { - resultString.push(assistantPrefix) + resultString.push(assistantPrefix + `${characterName}:`) } return resultString.join(seperator) } @@ -81,6 +84,8 @@ export function getStopStrings(suggesting:boolean=false){ "<|end", "<|im_end", userPrefix, + `*${username}'`, + `*${username} `, `\n${username} `, `${username}:`, ] diff --git a/src/ts/storage/defaultPrompts.ts b/src/ts/storage/defaultPrompts.ts index 9cd1da01..0ddf8281 100644 --- a/src/ts/storage/defaultPrompts.ts +++ b/src/ts/storage/defaultPrompts.ts @@ -28,15 +28,5 @@ Out Examples: Let's read these guidelines step by step three times to be sure we have accurately adhered to the rules. ` -export const defaultAutoSuggestPromptOoba = `Write {{user}}'s next responses that meet the following criteria: - -1. The purpose, intention, personality, and tendency must be consistent with the previous conversations. -2. It must contain {{user}}'s response only, NOT {{char}}'s. -3. The responses should be as diverse as feasible while remaining consistent. -4. It could be what {{char}} expects or does NOT expect. -5. It should be interesting and creative while NOT being obvious or boring. -6. It must make the future development and situation more detailed. - -Write 5 possible {{user}}'s next responses in distinct categories. -Write only one {{user}}'s response per line; each line must start with a hyphen '-'.` +export const defaultAutoSuggestPromptOoba = `The responses should be interesting and consistent, rather than dull and repetitive. It should be consistent with the context and as unique as possible. The responses could be what {{char}} expects or does not expect. Write 5 possibilities of {{user}}'s following response per line, each reflecting a different alignment. Each line must be only one independent {{user}}'s response, which starts with a hyphen '-'.` export const defaultAutoSuggestPrefixOoba = `- "` From 61fb8a0b1537548160141c2c08cac0c017990007 Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Thu, 3 Aug 2023 09:09:04 +0900 Subject: [PATCH 2/7] [fix] ooba stop strings --- src/ts/process/stringlize.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ts/process/stringlize.ts b/src/ts/process/stringlize.ts index d65fe79c..2420fc81 100644 --- a/src/ts/process/stringlize.ts +++ b/src/ts/process/stringlize.ts @@ -84,6 +84,9 @@ export function getStopStrings(suggesting:boolean=false){ "<|end", "<|im_end", userPrefix, + `*You '`, + `\nYou '`, + ` You '`, `*${username}'`, `*${username} `, `\n${username} `, From d6f4dc48fb65b16e78b66f1308a9eefa7e264fa7 Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:17:51 +0900 Subject: [PATCH 3/7] [fix] ooba autosuggest --- src/lib/ChatScreens/Suggestion.svelte | 8 ++++---- src/ts/process/stringlize.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/ChatScreens/Suggestion.svelte b/src/lib/ChatScreens/Suggestion.svelte index d5124146..d8c660fc 100644 --- a/src/lib/ChatScreens/Suggestion.svelte +++ b/src/lib/ChatScreens/Suggestion.svelte @@ -77,14 +77,14 @@ if($DataBase.subModel === "textgen_webui"){ promptbody = [ - ...lastMessages.map(({ role, data }) => ({ - role: role === "user" ? "user" as const : "assistant" as const, - content: data, - })), { role: 'system', content: replacePlaceholders($DataBase.autoSuggestPrompt, currentChar.name) }, + ...lastMessages.map(({ role, data }) => ({ + role: role === "user" ? "user" as const : "assistant" as const, + content: data, + })), ] } diff --git a/src/ts/process/stringlize.ts b/src/ts/process/stringlize.ts index 2420fc81..16aee013 100644 --- a/src/ts/process/stringlize.ts +++ b/src/ts/process/stringlize.ts @@ -47,11 +47,11 @@ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string='' let prefix = "" let name = "" if(form.role === 'user'){ - prefix = appendWhitespace(userPrefix, seperator) + prefix = appendWhitespace(suggesting ? assistantPrefix : userPrefix, seperator) name = `${db.username}: ` } else if(form.role === 'assistant'){ - prefix = appendWhitespace(assistantPrefix, seperator) + prefix = appendWhitespace(suggesting ? userPrefix : assistantPrefix, seperator) name = `${characterName}: ` } else if(form.role === 'system'){ @@ -60,7 +60,7 @@ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string='' resultString.push(prefix + name + form.content) } if (suggesting){ - resultString.push(appendWhitespace(assistantPrefix, seperator) + "\n" + db.autoSuggestPrefix) + resultString.push(appendWhitespace(assistantPrefix, seperator) + `${db.username}:\n` + db.autoSuggestPrefix) } else { resultString.push(assistantPrefix + `${characterName}:`) } From 28ae0aa9920699b07b66231859fbf7695203bf7e Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:58:38 +0900 Subject: [PATCH 4/7] [feat] clean autosuggest --- src/lib/ChatScreens/DefaultChatScreen.svelte | 2 +- src/lib/Setting/Pages/BotSettings.svelte | 2 ++ src/ts/process/templates/getRecomended.ts | 5 +++-- src/ts/storage/database.ts | 8 +++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/ChatScreens/DefaultChatScreen.svelte b/src/lib/ChatScreens/DefaultChatScreen.svelte index 27b102ae..1b88b33e 100644 --- a/src/lib/ChatScreens/DefaultChatScreen.svelte +++ b/src/lib/ChatScreens/DefaultChatScreen.svelte @@ -400,7 +400,7 @@ {/if} {#if $DataBase.useAutoSuggestions} - messageInput=msg} {send}/> + messageInput=msg.replace(/ +\(.+?\) *$| - [^"'*]*?$/, '')} {send}/> {/if} {#each messageForm($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message, loadPages) as chat, i} diff --git a/src/lib/Setting/Pages/BotSettings.svelte b/src/lib/Setting/Pages/BotSettings.svelte index 598f414b..bb991c29 100644 --- a/src/lib/Setting/Pages/BotSettings.svelte +++ b/src/lib/Setting/Pages/BotSettings.svelte @@ -306,6 +306,8 @@ {language.autoSuggest} Prefix + + {:else if $DataBase.aiModel.startsWith('novelai')} Top P diff --git a/src/ts/process/templates/getRecomended.ts b/src/ts/process/templates/getRecomended.ts index 29919962..5206f683 100644 --- a/src/ts/process/templates/getRecomended.ts +++ b/src/ts/process/templates/getRecomended.ts @@ -49,8 +49,9 @@ export async function setRecommended(model: string, ask:'ask'|'force') { pr.mainPrompt = pr.bias = pr.globalNote = undefined pr.jailbreak = "" if(!db.autoSuggestPrompt || db.autoSuggestPrompt === defaultAutoSuggestPrompt){ - pr.autoSuggestPrompt = defaultAutoSuggestPromptOoba; - pr.autoSuggestPrefix = defaultAutoSuggestPrefixOoba; + pr.autoSuggestPrompt = defaultAutoSuggestPromptOoba + pr.autoSuggestPrefix = defaultAutoSuggestPrefixOoba + pr.autoSuggestClean = true } switch(sel){ case 0:{ //Vicuna, WizardLM, Airoboros diff --git a/src/ts/storage/database.ts b/src/ts/storage/database.ts index 6fe83d6d..d9881967 100644 --- a/src/ts/storage/database.ts +++ b/src/ts/storage/database.ts @@ -271,7 +271,10 @@ export function setDatabase(data:Database){ data.autoSuggestPrompt = defaultAutoSuggestPrompt } if(checkNullish(data.autoSuggestPrefix)){ - data.autoSuggestPrompt = "" + data.autoSuggestPrefix = "" + } + if(checkNullish(data.autoSuggestClean)){ + data.autoSuggestClean = true } if(checkNullish(data.imageCompression)){ data.imageCompression = true @@ -460,6 +463,7 @@ export interface botPreset{ NAISettings?: NAISettings autoSuggestPrompt?: string autoSuggestPrefix?: string + autoSuggestClean?: boolean } export interface Database{ @@ -571,6 +575,7 @@ export interface Database{ useAutoSuggestions:boolean autoSuggestPrompt:string autoSuggestPrefix:string + autoSuggestClean:boolean claudeAPIKey:string, useChatCopy:boolean, novellistAPI:string, @@ -885,6 +890,7 @@ export function setPreset(db:Database, newPres: botPreset){ db.NAIsettings = newPres.NAISettings ?? db.NAIsettings db.autoSuggestPrompt = newPres.autoSuggestPrompt ?? db.autoSuggestPrompt db.autoSuggestPrefix = newPres.autoSuggestPrefix ?? db.autoSuggestPrefix + db.autoSuggestClean = newPres.autoSuggestClean ?? db.autoSuggestClean return db } From 4ca304d26dbcd0ec8da49177f440d24967c01fa9 Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:02:16 +0900 Subject: [PATCH 5/7] [fix] clean autosuggest --- src/lib/ChatScreens/DefaultChatScreen.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/ChatScreens/DefaultChatScreen.svelte b/src/lib/ChatScreens/DefaultChatScreen.svelte index 1b88b33e..59e1ab26 100644 --- a/src/lib/ChatScreens/DefaultChatScreen.svelte +++ b/src/lib/ChatScreens/DefaultChatScreen.svelte @@ -400,7 +400,11 @@ {/if} {#if $DataBase.useAutoSuggestions} - messageInput=msg.replace(/ +\(.+?\) *$| - [^"'*]*?$/, '')} {send}/> + messageInput=( + $DataBase.subModel === "textgen_webui" && $DataBase.autoSuggestClean + ? msg.replace(/ +\(.+?\) *$| - [^"'*]*?$/, '') + : msg + )} {send}/> {/if} {#each messageForm($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message, loadPages) as chat, i} From 2308e478abcb267790c3fe770e5dcfc6a0979d16 Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:19:56 +0900 Subject: [PATCH 6/7] [fix] autosuggest stop strings --- src/ts/process/stringlize.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ts/process/stringlize.ts b/src/ts/process/stringlize.ts index 16aee013..b8de559c 100644 --- a/src/ts/process/stringlize.ts +++ b/src/ts/process/stringlize.ts @@ -84,9 +84,7 @@ export function getStopStrings(suggesting:boolean=false){ "<|end", "<|im_end", userPrefix, - `*You '`, - `\nYou '`, - ` You '`, + "\nYou ", `*${username}'`, `*${username} `, `\n${username} `, @@ -98,6 +96,10 @@ export function getStopStrings(suggesting:boolean=false){ if(suggesting){ stopStrings.push("\n\n") } + if(!suggesting){ + stopStrings.push("*You ") + stopStrings.push(" You ") + } for (const user of userStrings){ for (const u of [ user.toLowerCase(), From d0094096bfcb91f58c85980c65183b34089209f5 Mon Sep 17 00:00:00 2001 From: aegkmq <140575296+aegkmq@users.noreply.github.com> Date: Thu, 3 Aug 2023 18:09:34 +0900 Subject: [PATCH 7/7] [fix] typo --- src/lib/Setting/Pages/BotSettings.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Setting/Pages/BotSettings.svelte b/src/lib/Setting/Pages/BotSettings.svelte index bb991c29..aeb5fb56 100644 --- a/src/lib/Setting/Pages/BotSettings.svelte +++ b/src/lib/Setting/Pages/BotSettings.svelte @@ -307,7 +307,7 @@ {language.autoSuggest} Prefix - + {:else if $DataBase.aiModel.startsWith('novelai')} Top P