From 5a0547c6887ceee07aeda40f74169a1c1f483be9 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sat, 9 Sep 2023 08:57:29 +0900 Subject: [PATCH] [feat] prompt template memory --- src/lang/en.ts | 1 + src/lib/UI/ProomptItem.svelte | 8 +++++--- src/ts/process/index.ts | 26 +++++++++++++++++++++++++- src/ts/process/proompt.ts | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/lang/en.ts b/src/lang/en.ts index fa48ccc5..63f9ae80 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -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.', diff --git a/src/lib/UI/ProomptItem.svelte b/src/lib/UI/ProomptItem.svelte index 6cb9d5fe..624c8205 100644 --- a/src/lib/UI/ProomptItem.svelte +++ b/src/lib/UI/ProomptItem.svelte @@ -40,6 +40,8 @@ {language.formating.description} {language.formating.authorNote} {language.formating.lorebook} + {language.formating.memory} + {#if proompt.type === 'plain' || proompt.type === 'jailbreak'} @@ -81,10 +83,10 @@ {language.defaultPrompt} {/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} { - 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 @@ {language.innerFormat} { - 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 } }} /> diff --git a/src/ts/process/index.ts b/src/ts/process/index.ts index 805442a6..e9b497b4 100644 --- a/src/ts/process/index.ts +++ b/src/ts/process/index.ts @@ -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