diff --git a/src/ts/process/index.svelte.ts b/src/ts/process/index.svelte.ts index 5b10df9e..97f1e782 100644 --- a/src/ts/process/index.svelte.ts +++ b/src/ts/process/index.svelte.ts @@ -400,15 +400,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{ if(currentChat.note){ unformated.authorNote.push({ role: 'system', - content: risuChatParser(currentChat.note, {chara: currentChar}), - memo: 'authornote' + content: risuChatParser(currentChat.note, {chara: currentChar}) }) } else if(getAuthorNoteDefaultText() !== ''){ unformated.authorNote.push({ role: 'system', - content: risuChatParser(getAuthorNoteDefaultText(), {chara: currentChar}), - memo: 'authornote' + content: risuChatParser(getAuthorNoteDefaultText(), {chara: currentChar}) }) } @@ -438,8 +436,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ unformated.description.push({ role: 'system', - content: description, - memo: 'description', + content: description }) if(nowChatroom.type === 'group'){ @@ -460,8 +457,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ for(const lorebook of normalActives){ unformated.lorebook.push({ role: lorebook.role, - content: risuChatParser(lorebook.prompt, {chara: currentChar}), - memo: 'lore', + content: risuChatParser(lorebook.prompt, {chara: currentChar}) }) } @@ -485,8 +481,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ if(DBState.db.personaPrompt){ unformated.personaPrompt.push({ role: 'system', - content: risuChatParser(getPersonaPrompt(), {chara: currentChar}), - memo: 'persona', + content: risuChatParser(getPersonaPrompt(), {chara: currentChar}) }) } @@ -511,8 +506,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ for(const lorebook of postEverythingLorebooks){ unformated.postEverything.push({ role: lorebook.role, - content: risuChatParser(lorebook.prompt, {chara: currentChar}), - memo: 'postEverything', + content: risuChatParser(lorebook.prompt, {chara: currentChar}) }) } @@ -1100,10 +1094,15 @@ export async function sendChat(chatProcessIndex = -1,arg:{ } } - type MemoType = 'persona' | 'description' | 'authornote' | 'supaMemory'; - const promptBodyMap: Record = { persona: [], description: [], authornote: [], supaMemory: [] }; - function pushPromptInfoBody(memo: MemoType, fmt: string) { - promptBodyMap[memo].push(risuChatParser(fmt)); + let promptBodyformatedForChatStore: OpenAIChat[] = [] + function pushPromptInfoBody(role: "function" | "system" | "user" | "assistant", fmt: string, promptBody: OpenAIChat[]) { + if(!fmt.trim()){ + return + } + promptBody.push({ + role: role, + content: risuChatParser(fmt), + }) } if(promptTemplate){ @@ -1118,7 +1117,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content) if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ - pushPromptInfoBody(card.type, card.innerFormat) + pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1133,7 +1132,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content) if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ - pushPromptInfoBody(card.type, card.innerFormat) + pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1148,7 +1147,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '') if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ - pushPromptInfoBody(card.type, card.innerFormat) + pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1206,6 +1205,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{ content: content } + if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat && card.type2 !== 'globalNote'){ + pushPromptInfoBody(prompt.role, prompt.content, promptBodyformatedForChatStore) + } + pushPrompts([prompt]) break } @@ -1267,7 +1270,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content) if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ - pushPromptInfoBody('supaMemory', card.innerFormat) + pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1306,6 +1309,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{ return v }) + if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ + promptBodyformatedForChatStore = promptBodyformatedForChatStore.map((v) => { + v.content = v.content.trim() + return v + }) + } + if(currentChar.depth_prompt && currentChar.depth_prompt.prompt && currentChar.depth_prompt.prompt.length > 0){ //depth_prompt @@ -1318,6 +1328,11 @@ export async function sendChat(chatProcessIndex = -1,arg:{ formated = await runLuaEditTrigger(currentChar, 'editRequest', formated) + if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ + promptBodyformatedForChatStore = await runLuaEditTrigger(currentChar, 'editRequest', promptBodyformatedForChatStore) + promptInfo.promptText = promptBodyformatedForChatStore + } + //token rechecking let inputTokens = 0 @@ -1388,29 +1403,6 @@ export async function sendChat(chatProcessIndex = -1,arg:{ return true } - - function isPromptMemo(m: string): m is MemoType { - return ['persona', 'description', 'authornote', 'supaMemory'].includes(m); - } - if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ - const promptBodyInfo: OpenAIChat[] = formated.flatMap(format => { - if (isPromptMemo(format.memo)) { - return promptBodyMap[format.memo].map(content => ({ - role: format.role, - content, - })) - } - - if (format.memo == null) { - return [format] - } - - return [] - }) - - promptInfo.promptText = promptBodyInfo - } - let result = '' let emoChanged = false let resendChat = false