[fix] oobabooga prompt template and autosuggest (#226)

# PR Checklist
- [x] Did you check if it works normally in all models? *ignore this
when it dosen't uses models*
- [x] Did you check if it works normally in all of web, local and node
hosted versions? if it dosen't, did you blocked it in those versions?
- [x] Did you added a type def?

# Description
The changes in #225 didn't seem to be enough, so I made an additional
fix.
This commit is contained in:
kwaroran
2023-08-04 11:42:43 +09:00
committed by GitHub
8 changed files with 39 additions and 28 deletions

View File

@@ -400,7 +400,11 @@
{/if} {/if}
{#if $DataBase.useAutoSuggestions} {#if $DataBase.useAutoSuggestions}
<Suggestion messageInput={(msg)=>messageInput=msg} {send}/> <Suggestion messageInput={(msg)=>messageInput=(
$DataBase.subModel === "textgen_webui" && $DataBase.autoSuggestClean
? msg.replace(/ +\(.+?\) *$| - [^"'*]*?$/, '')
: msg
)} {send}/>
{/if} {/if}
{#each messageForm($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message, loadPages) as chat, i} {#each messageForm($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].message, loadPages) as chat, i}

View File

@@ -81,12 +81,10 @@
role: 'system', role: 'system',
content: replacePlaceholders($DataBase.autoSuggestPrompt, currentChar.name) content: replacePlaceholders($DataBase.autoSuggestPrompt, currentChar.name)
}, },
{ ...lastMessages.map(({ role, data }) => ({
role: 'user', role: role === "user" ? "user" as const : "assistant" as const,
content: lastMessages.map(({ role, data }) => `${ content: data,
role === 'char' ? currentChar.name : $DataBase.username })),
}: ${data}`).join("\n\n") + `\n\n${$DataBase.username}:`
},
] ]
} }

View File

@@ -306,6 +306,8 @@
<span class="text-textcolor">{language.autoSuggest} Prefix</span> <span class="text-textcolor">{language.autoSuggest} Prefix</span>
<TextInput marginBottom={true} bind:value={$DataBase.autoSuggestPrefix} /> <TextInput marginBottom={true} bind:value={$DataBase.autoSuggestPrefix} />
<Check bind:check={$DataBase.autoSuggestClean} name={`${language.autoSuggest} suffix removal`}/>
{:else if $DataBase.aiModel.startsWith('novelai')} {:else if $DataBase.aiModel.startsWith('novelai')}
<span class="text-textcolor">Top P</span> <span class="text-textcolor">Top P</span>
<SliderInput min={0} max={1} step={0.01} bind:value={$DataBase.NAIsettings.topP}/> <SliderInput min={0} max={1} step={0.01} bind:value={$DataBase.NAIsettings.topP}/>

View File

@@ -399,7 +399,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
let blockingUrl = db.textgenWebUIBlockingURL.replace(/\/api.*/, "/api/v1/generate") let blockingUrl = db.textgenWebUIBlockingURL.replace(/\/api.*/, "/api/v1/generate")
let bodyTemplate:any let bodyTemplate:any
const suggesting = model === "submodel" const suggesting = model === "submodel"
const proompt = stringlizeChatOba(formated, suggesting) const proompt = stringlizeChatOba(formated, currentChar.name, suggesting)
const stopStrings = getStopStrings(suggesting) const stopStrings = getStopStrings(suggesting)
console.log(proompt) console.log(proompt)
console.log(stopStrings) console.log(stopStrings)

View File

@@ -29,7 +29,7 @@ function appendWhitespace(prefix:string, seperator:string=" ") {
} }
return prefix return prefix
} }
export function stringlizeChatOba(formated:OpenAIChat[], suggesting:boolean=false){ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string='', suggesting:boolean=false){
const db = get(DataBase) const db = get(DataBase)
let resultString:string[] = [] let resultString:string[] = []
let { header, systemPrefix, userPrefix, assistantPrefix, seperator } = db.ooba.formating; let { header, systemPrefix, userPrefix, assistantPrefix, seperator } = db.ooba.formating;
@@ -45,21 +45,24 @@ export function stringlizeChatOba(formated:OpenAIChat[], suggesting:boolean=fals
continue continue
} }
let prefix = "" let prefix = ""
let name = ""
if(form.role === 'user'){ if(form.role === 'user'){
prefix = appendWhitespace(userPrefix, seperator) prefix = appendWhitespace(suggesting ? assistantPrefix : userPrefix, seperator)
name = `${db.username}: `
} }
else if(form.role === 'assistant'){ else if(form.role === 'assistant'){
prefix = appendWhitespace(assistantPrefix, seperator) prefix = appendWhitespace(suggesting ? userPrefix : assistantPrefix, seperator)
name = `${characterName}: `
} }
else if(form.role === 'system'){ else if(form.role === 'system'){
prefix = appendWhitespace(systemPrefix, seperator) prefix = appendWhitespace(systemPrefix, seperator)
} }
resultString.push(prefix + form.content) resultString.push(prefix + name + form.content)
} }
if (suggesting){ if (suggesting){
resultString.push(appendWhitespace(assistantPrefix, seperator) + "\n" + db.autoSuggestPrefix) resultString.push(appendWhitespace(assistantPrefix, seperator) + `${db.username}:\n` + db.autoSuggestPrefix)
} else { } else {
resultString.push(assistantPrefix) resultString.push(assistantPrefix + `${characterName}:`)
} }
return resultString.join(seperator) return resultString.join(seperator)
} }
@@ -81,6 +84,9 @@ export function getStopStrings(suggesting:boolean=false){
"<|end", "<|end",
"<|im_end", "<|im_end",
userPrefix, userPrefix,
"\nYou ",
`*${username}'`,
`*${username} `,
`\n${username} `, `\n${username} `,
`${username}:`, `${username}:`,
] ]
@@ -90,6 +96,10 @@ export function getStopStrings(suggesting:boolean=false){
if(suggesting){ if(suggesting){
stopStrings.push("\n\n") stopStrings.push("\n\n")
} }
if(!suggesting){
stopStrings.push("*You ")
stopStrings.push(" You ")
}
for (const user of userStrings){ for (const user of userStrings){
for (const u of [ for (const u of [
user.toLowerCase(), user.toLowerCase(),

View File

@@ -49,8 +49,9 @@ export async function setRecommended(model: string, ask:'ask'|'force') {
pr.mainPrompt = pr.bias = pr.globalNote = undefined pr.mainPrompt = pr.bias = pr.globalNote = undefined
pr.jailbreak = "" pr.jailbreak = ""
if(!db.autoSuggestPrompt || db.autoSuggestPrompt === defaultAutoSuggestPrompt){ if(!db.autoSuggestPrompt || db.autoSuggestPrompt === defaultAutoSuggestPrompt){
pr.autoSuggestPrompt = defaultAutoSuggestPromptOoba; pr.autoSuggestPrompt = defaultAutoSuggestPromptOoba
pr.autoSuggestPrefix = defaultAutoSuggestPrefixOoba; pr.autoSuggestPrefix = defaultAutoSuggestPrefixOoba
pr.autoSuggestClean = true
} }
switch(sel){ switch(sel){
case 0:{ //Vicuna, WizardLM, Airoboros case 0:{ //Vicuna, WizardLM, Airoboros

View File

@@ -271,7 +271,10 @@ export function setDatabase(data:Database){
data.autoSuggestPrompt = defaultAutoSuggestPrompt data.autoSuggestPrompt = defaultAutoSuggestPrompt
} }
if(checkNullish(data.autoSuggestPrefix)){ if(checkNullish(data.autoSuggestPrefix)){
data.autoSuggestPrompt = "" data.autoSuggestPrefix = ""
}
if(checkNullish(data.autoSuggestClean)){
data.autoSuggestClean = true
} }
if(checkNullish(data.imageCompression)){ if(checkNullish(data.imageCompression)){
data.imageCompression = true data.imageCompression = true
@@ -460,6 +463,7 @@ export interface botPreset{
NAISettings?: NAISettings NAISettings?: NAISettings
autoSuggestPrompt?: string autoSuggestPrompt?: string
autoSuggestPrefix?: string autoSuggestPrefix?: string
autoSuggestClean?: boolean
} }
export interface Database{ export interface Database{
@@ -571,6 +575,7 @@ export interface Database{
useAutoSuggestions:boolean useAutoSuggestions:boolean
autoSuggestPrompt:string autoSuggestPrompt:string
autoSuggestPrefix:string autoSuggestPrefix:string
autoSuggestClean:boolean
claudeAPIKey:string, claudeAPIKey:string,
useChatCopy:boolean, useChatCopy:boolean,
novellistAPI:string, novellistAPI:string,
@@ -885,6 +890,7 @@ export function setPreset(db:Database, newPres: botPreset){
db.NAIsettings = newPres.NAISettings ?? db.NAIsettings db.NAIsettings = newPres.NAISettings ?? db.NAIsettings
db.autoSuggestPrompt = newPres.autoSuggestPrompt ?? db.autoSuggestPrompt db.autoSuggestPrompt = newPres.autoSuggestPrompt ?? db.autoSuggestPrompt
db.autoSuggestPrefix = newPres.autoSuggestPrefix ?? db.autoSuggestPrefix db.autoSuggestPrefix = newPres.autoSuggestPrefix ?? db.autoSuggestPrefix
db.autoSuggestClean = newPres.autoSuggestClean ?? db.autoSuggestClean
return db return db
} }

View File

@@ -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. 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: 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 '-'.`
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 defaultAutoSuggestPrefixOoba = `- "` export const defaultAutoSuggestPrefixOoba = `- "`