From c2b37f811bcfb41001dab787f11e493aba45b9a3 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Thu, 6 Apr 2023 02:37:12 +0800 Subject: [PATCH] feat: close #469 support reset session and do not send memory --- README.md | 1 - app/components/chat.module.scss | 8 ++++++++ app/components/chat.tsx | 30 ++++++++++++++++++++++++++++-- app/locales/cn.ts | 5 ++++- app/locales/en.ts | 6 +++++- app/locales/es.ts | 4 ++++ app/locales/it.ts | 4 ++++ app/locales/tw.ts | 3 +++ app/store/app.ts | 22 ++++++++++++++++++++-- app/styles/globals.scss | 4 ++++ 10 files changed, 80 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index edf7f1db..d47a3895 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ One-Click to deploy your own ChatGPT web UI. - 用户登录、账号管理、消息云同步 - ## Get Started > [简体中文 > 如何开始使用](./README_CN.md#开始使用) diff --git a/app/components/chat.module.scss b/app/components/chat.module.scss index 5216fb25..f57e6c10 100644 --- a/app/components/chat.module.scss +++ b/app/components/chat.module.scss @@ -63,6 +63,14 @@ font-size: 12px; font-weight: bold; margin-bottom: 10px; + display: flex; + justify-content: space-between; + align-items: center; + + .memory-prompt-action { + display: flex; + align-items: center; + } } .memory-prompt-content { diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 03f5de67..dc746e24 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -144,6 +144,16 @@ function PromptToast(props: { title={Locale.Context.Edit} onClose={() => props.setShowModal(false)} actions={[ + } + bordered + text={Locale.Memory.Reset} + onClick={() => + confirm(Locale.Memory.ResetConfirm) && + chatStore.resetSession() + } + />, } @@ -212,8 +222,24 @@ function PromptToast(props: {
- {Locale.Memory.Title} ({session.lastSummarizeIndex} of{" "} - {session.messages.length}) + + {Locale.Memory.Title} ({session.lastSummarizeIndex} of{" "} + {session.messages.length}) + + +
{session.memoryPrompt || Locale.Memory.EmptyContent} diff --git a/app/locales/cn.ts b/app/locales/cn.ts index e0adb6dc..64f04626 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -39,7 +39,10 @@ const cn = { Memory: { Title: "历史记忆", EmptyContent: "尚未记忆", - Copy: "全部复制", + Send: "发送记忆", + Copy: "复制记忆", + Reset: "重置对话", + ResetConfirm: "重置后将清空当前对话记录以及历史记忆,确认重置?", }, Home: { NewChat: "新的聊天", diff --git a/app/locales/en.ts b/app/locales/en.ts index af820150..add9e1c7 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -41,7 +41,11 @@ const en: LocaleType = { Memory: { Title: "Memory Prompt", EmptyContent: "Nothing yet.", - Copy: "Copy All", + Send: "Send Memory", + Copy: "Copy Memory", + Reset: "Reset Session", + ResetConfirm: + "Resetting will clear the current conversation history and historical memory. Are you sure you want to reset?", }, Home: { NewChat: "New Chat", diff --git a/app/locales/es.ts b/app/locales/es.ts index 5c73b608..b3af1f03 100644 --- a/app/locales/es.ts +++ b/app/locales/es.ts @@ -42,6 +42,10 @@ const es: LocaleType = { Title: "Historial de memoria", EmptyContent: "Aún no hay nada.", Copy: "Copiar todo", + Send: "Send Memory", + Reset: "Reset Session", + ResetConfirm: + "Resetting will clear the current conversation history and historical memory. Are you sure you want to reset?", }, Home: { NewChat: "Nuevo chat", diff --git a/app/locales/it.ts b/app/locales/it.ts index ce87796d..82afb818 100644 --- a/app/locales/it.ts +++ b/app/locales/it.ts @@ -42,6 +42,10 @@ const it: LocaleType = { Title: "Prompt di memoria", EmptyContent: "Vuoto.", Copy: "Copia tutto", + Send: "Send Memory", + Reset: "Reset Session", + ResetConfirm: + "Resetting will clear the current conversation history and historical memory. Are you sure you want to reset?", }, Home: { NewChat: "Nuova Chat", diff --git a/app/locales/tw.ts b/app/locales/tw.ts index eaab03fc..237f3fbe 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -41,6 +41,9 @@ const tw: LocaleType = { Title: "上下文記憶 Prompt", EmptyContent: "尚未記憶", Copy: "複製全部", + Send: "發送記憶", + Reset: "重置對話", + ResetConfirm: "重置後將清空當前對話記錄以及歷史記憶,確認重置?", }, Home: { NewChat: "新的對話", diff --git a/app/store/app.ts b/app/store/app.ts index d01e3cdd..9f1e8e88 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -149,6 +149,7 @@ export interface ChatStat { export interface ChatSession { id: number; topic: string; + sendMemory: boolean; memoryPrompt: string; context: Message[]; messages: Message[]; @@ -170,6 +171,7 @@ function createEmptySession(): ChatSession { return { id: Date.now(), topic: DEFAULT_TOPIC, + sendMemory: true, memoryPrompt: "", context: [], messages: [], @@ -202,6 +204,7 @@ interface ChatStore { messageIndex: number, updater: (message?: Message) => void, ) => void; + resetSession: () => void; getMessagesWithMemory: () => Message[]; getMemoryPrompt: () => Message; @@ -391,7 +394,11 @@ export const useChatStore = create()( const context = session.context.slice(); - if (session.memoryPrompt && session.memoryPrompt.length > 0) { + if ( + session.sendMemory && + session.memoryPrompt && + session.memoryPrompt.length > 0 + ) { const memoryPrompt = get().getMemoryPrompt(); context.push(memoryPrompt); } @@ -415,6 +422,13 @@ export const useChatStore = create()( set(() => ({ sessions })); }, + resetSession() { + get().updateCurrentSession((session) => { + session.messages = []; + session.memoryPrompt = ""; + }); + }, + summarizeSession() { const session = get().currentSession(); @@ -506,7 +520,7 @@ export const useChatStore = create()( }), { name: LOCAL_KEY, - version: 1.1, + version: 1.2, migrate(persistedState, version) { const state = persistedState as ChatStore; @@ -514,6 +528,10 @@ export const useChatStore = create()( state.sessions.forEach((s) => (s.context = [])); } + if (version < 1.2) { + state.sessions.forEach((s) => (s.sendMemory = true)); + } + return state; }, }, diff --git a/app/styles/globals.scss b/app/styles/globals.scss index 48f56995..6492b000 100644 --- a/app/styles/globals.scss +++ b/app/styles/globals.scss @@ -126,6 +126,10 @@ select { text-align: center; } +label { + cursor: pointer; +} + input { text-align: center; }