[feat] prompt template memory

This commit is contained in:
kwaroran
2023-09-09 08:57:29 +09:00
parent a122e1cc5d
commit 5a0547c688
4 changed files with 32 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ export const languageEnglish = {
"description": "Character Description",
'personaPrompt':'Persona Prompt',
'plain': "Plain Prompt",
'memory': "Supa/HypaMemory"
},
errors:{
toomuchtoken: 'Error: The minimum required token is greater than the Max Context Size.',

View File

@@ -40,6 +40,8 @@
<OptionInput value="description">{language.formating.description}</OptionInput>
<OptionInput value="authornote">{language.formating.authorNote}</OptionInput>
<OptionInput value="lorebook">{language.formating.lorebook}</OptionInput>
<OptionInput value="memory">{language.formating.memory}</OptionInput>
</SelectInput>
{#if proompt.type === 'plain' || proompt.type === 'jailbreak'}
@@ -81,10 +83,10 @@
<span>{language.defaultPrompt}</span>
<TextInput bind:value={proompt.defaultText} />
{/if}
{#if proompt.type === 'persona' || proompt.type === 'description' || proompt.type === 'authornote'}
{#if proompt.type === 'persona' || proompt.type === 'description' || proompt.type === 'authornote' || proompt.type === 'memory'}
{#if !proompt.innerFormat}
<CheckInput name={language.customInnerFormat} check={false} className="mt-2" onChange={() => {
if(proompt.type === 'persona' || proompt.type === 'description' || proompt.type === 'authornote'){
if(proompt.type === 'persona' || proompt.type === 'description' || proompt.type === 'authornote' || proompt.type === 'memory'){
proompt.innerFormat = "{{slot}}"
}
}} />
@@ -92,7 +94,7 @@
<span>{language.innerFormat}</span>
<TextAreaInput bind:value={proompt.innerFormat}/>
<CheckInput name={language.customInnerFormat} check={true} className="mt-2" onChange={() => {
if(proompt.type === 'persona' || proompt.type === 'description' || proompt.type === 'authornote'){
if(proompt.type === 'persona' || proompt.type === 'description' || proompt.type === 'authornote' || proompt.type === 'memory'){
proompt.innerFormat = null
}
}} />

View File

@@ -263,6 +263,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
//await tokenize currernt
let currentTokens = db.maxResponse
let supaMemoryCardUsed = false
//for unexpected error
currentTokens += 50
@@ -377,6 +378,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
await tokenizeChatArray(chats)
break
}
case 'memory':{
supaMemoryCardUsed = true
break
}
}
}
}
@@ -388,7 +393,6 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
}
}
}
const examples = exampleMessage(currentChar, db.username)
@@ -487,6 +491,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
return [risuChatParser(v[0].replaceAll("\\n","\n"), {chara: currentChar}),v[1]]
})
let memories:OpenAIChat[] = []
@@ -499,7 +504,16 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
if(v.memo !== 'supaMemory' && v.memo !== 'hypaMemory'){
v.removable = true
}
else if(supaMemoryCardUsed){
memories.push(v)
return {
role: 'system',
content: '',
} as const
}
return v
}).filter((v) => {
return v.content !== ''
})
@@ -669,6 +683,16 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
pushPrompts(chats)
break
}
case 'memory':{
let pmt = cloneDeep(memories)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
}
}
pushPrompts(pmt)
}
}
}
}

View File

@@ -8,7 +8,7 @@ export interface ProomptPlain {
}
export interface ProomptTyped {
type: 'persona'|'description'|'lorebook'|'postEverything'
type: 'persona'|'description'|'lorebook'|'postEverything'|'memory'
innerFormat?: string
}