From dc9694e1705868cd46281a249b21d00974860577 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Tue, 10 Oct 2023 06:47:28 +0700 Subject: [PATCH] UI Page MemoryPrompt Masks [Chat Commands] (#47) * UI Page MemoryPrompt Masks [Chat Commands] [+] feat(command): add support for 'updatemasks' command in ChatCommands interface [+] feat(chat.tsx): implement 'updatemasks' command logic in _Chat component [+] feat(cn.ts): add translation for 'updatemasks' command [+] feat(en.ts): add translation for 'updatemasks' command [+] feat(id.ts): add translation for 'updatemasks' command * Feat UI Page MemoryPrompt Masks [Chat Commands] [+] feat(chat.tsx): add toast notification for successful update of masks in chat component [+] feat(cn.ts): add UI locale for successful update of masks [+] feat(en.ts): add UI locale for successful update of masks [+] feat(id.ts): add UI locale for successful update of masks --- app/command.ts | 1 + app/components/chat.tsx | 30 ++++++++++++++++++++++++++++++ app/locales/cn.ts | 5 +++++ app/locales/en.ts | 5 +++++ app/locales/id.ts | 5 +++++ 5 files changed, 46 insertions(+) diff --git a/app/command.ts b/app/command.ts index a8005ecf852..16665c6b14d 100644 --- a/app/command.ts +++ b/app/command.ts @@ -42,6 +42,7 @@ interface ChatCommands { save?: Command; load?: Command; copymemoryai?: Command; + updatemasks?: Command; } export const ChatCommandPrefix = ":"; diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 31449b8001f..1fc7d4c31e6 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -694,6 +694,36 @@ function _Chat() { showToast(Locale.Copy.Failed); } }, + updatemasks: () => { + chatStore.updateCurrentSession((session) => { + const memoryPrompt = session.memoryPrompt; + const currentDate = new Date().toISOString(); // Get the current date and time as a string + const existingContext = session.mask.context; + let currentContext = existingContext[0]; // Get the current context message + + if (!currentContext || currentContext.role !== "system") { + // If the current context message doesn't exist or doesn't have the role "system" + currentContext = { + role: "system", + content: memoryPrompt, + date: currentDate, + id: "", // Generate or set the ID for the new message + // Add any other properties you want to set for the context messages + }; + existingContext.unshift(currentContext); // Add the new message at the beginning of the context array + showToast(Locale.Chat.Commands.UI.MasksSuccess); + } else { + // If the current context message already exists and has the role "system" + currentContext.content = memoryPrompt; // Update the content + currentContext.date = currentDate; // Update the date + // You can update other properties of the current context message here + } + + // Set any other properties you want to update in the session + session.mask.context = existingContext; + showToast(Locale.Chat.Commands.UI.MasksSuccess); + }); + }, }); // only search prompts when user input is short diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 6fd30988de6..026039d69d7 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -71,6 +71,11 @@ const cn = { save: "保存当前会话聊天", load: "加载会话聊天", copymemoryai: "复制一个记忆会话的提示AI", + updatemasks: "更新一个用于掩码的记忆会话提示", + UI: { + MasksSuccess: "成功更新了掩码会话", + MasksFail: "无法更新掩码会话", + }, }, InputActions: { Stop: "停止响应", diff --git a/app/locales/en.ts b/app/locales/en.ts index 4f9581c98d6..19256821c99 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -73,6 +73,11 @@ const en: LocaleType = { save: "Save a current session chat", load: "Load a session chat", copymemoryai: "Copy a session of memory prompt ai", + updatemasks: "Update a session of memory prompt for a mask", + UI: { + MasksSuccess: "Successfully updated session of masks", + MasksFail: "Failed to update session of masks", + }, }, InputActions: { Stop: "Stop", diff --git a/app/locales/id.ts b/app/locales/id.ts index e98187a67c1..d2b146bb78f 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -60,6 +60,11 @@ const id: PartialLocaleType = { save: "Simpan Percakapan Sesi Saat Ini", load: "Muat Percakapan Sesi", copymemoryai: "Salin sesi memori prompt AI", + updatemasks: "Perbarui sesi memori prompt untuk sebuah topeng", + UI: { + MasksSuccess: "Berhasil memperbarui sesi topeng", + MasksFail: "Gagal memperbarui sesi topeng", + }, }, InputActions: { Stop: "Berhenti",