mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	feat: close #469 support reset session and do not send memory
This commit is contained in:
		@@ -62,7 +62,6 @@ One-Click to deploy your own ChatGPT web UI.
 | 
				
			|||||||
- 用户登录、账号管理、消息云同步
 | 
					- 用户登录、账号管理、消息云同步
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
## Get Started
 | 
					## Get Started
 | 
				
			||||||
> [简体中文 > 如何开始使用](./README_CN.md#开始使用)
 | 
					> [简体中文 > 如何开始使用](./README_CN.md#开始使用)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,6 +63,14 @@
 | 
				
			|||||||
    font-size: 12px;
 | 
					    font-size: 12px;
 | 
				
			||||||
    font-weight: bold;
 | 
					    font-weight: bold;
 | 
				
			||||||
    margin-bottom: 10px;
 | 
					    margin-bottom: 10px;
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    justify-content: space-between;
 | 
				
			||||||
 | 
					    align-items: center;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .memory-prompt-action {
 | 
				
			||||||
 | 
					      display: flex;
 | 
				
			||||||
 | 
					      align-items: center;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  .memory-prompt-content {
 | 
					  .memory-prompt-content {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -144,6 +144,16 @@ function PromptToast(props: {
 | 
				
			|||||||
            title={Locale.Context.Edit}
 | 
					            title={Locale.Context.Edit}
 | 
				
			||||||
            onClose={() => props.setShowModal(false)}
 | 
					            onClose={() => props.setShowModal(false)}
 | 
				
			||||||
            actions={[
 | 
					            actions={[
 | 
				
			||||||
 | 
					              <IconButton
 | 
				
			||||||
 | 
					                key="reset"
 | 
				
			||||||
 | 
					                icon={<CopyIcon />}
 | 
				
			||||||
 | 
					                bordered
 | 
				
			||||||
 | 
					                text={Locale.Memory.Reset}
 | 
				
			||||||
 | 
					                onClick={() =>
 | 
				
			||||||
 | 
					                  confirm(Locale.Memory.ResetConfirm) &&
 | 
				
			||||||
 | 
					                  chatStore.resetSession()
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					              />,
 | 
				
			||||||
              <IconButton
 | 
					              <IconButton
 | 
				
			||||||
                key="copy"
 | 
					                key="copy"
 | 
				
			||||||
                icon={<CopyIcon />}
 | 
					                icon={<CopyIcon />}
 | 
				
			||||||
@@ -212,8 +222,24 @@ function PromptToast(props: {
 | 
				
			|||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
              <div className={chatStyle["memory-prompt"]}>
 | 
					              <div className={chatStyle["memory-prompt"]}>
 | 
				
			||||||
                <div className={chatStyle["memory-prompt-title"]}>
 | 
					                <div className={chatStyle["memory-prompt-title"]}>
 | 
				
			||||||
                  {Locale.Memory.Title} ({session.lastSummarizeIndex} of{" "}
 | 
					                  <span>
 | 
				
			||||||
                  {session.messages.length})
 | 
					                    {Locale.Memory.Title} ({session.lastSummarizeIndex} of{" "}
 | 
				
			||||||
 | 
					                    {session.messages.length})
 | 
				
			||||||
 | 
					                  </span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                  <label className={chatStyle["memory-prompt-action"]}>
 | 
				
			||||||
 | 
					                    {Locale.Memory.Send}
 | 
				
			||||||
 | 
					                    <input
 | 
				
			||||||
 | 
					                      type="checkbox"
 | 
				
			||||||
 | 
					                      checked={session.sendMemory}
 | 
				
			||||||
 | 
					                      onChange={() =>
 | 
				
			||||||
 | 
					                        chatStore.updateCurrentSession(
 | 
				
			||||||
 | 
					                          (session) =>
 | 
				
			||||||
 | 
					                            (session.sendMemory = !session.sendMemory),
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
 | 
					                      }
 | 
				
			||||||
 | 
					                    ></input>
 | 
				
			||||||
 | 
					                  </label>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <div className={chatStyle["memory-prompt-content"]}>
 | 
					                <div className={chatStyle["memory-prompt-content"]}>
 | 
				
			||||||
                  {session.memoryPrompt || Locale.Memory.EmptyContent}
 | 
					                  {session.memoryPrompt || Locale.Memory.EmptyContent}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,10 @@ const cn = {
 | 
				
			|||||||
  Memory: {
 | 
					  Memory: {
 | 
				
			||||||
    Title: "历史记忆",
 | 
					    Title: "历史记忆",
 | 
				
			||||||
    EmptyContent: "尚未记忆",
 | 
					    EmptyContent: "尚未记忆",
 | 
				
			||||||
    Copy: "全部复制",
 | 
					    Send: "发送记忆",
 | 
				
			||||||
 | 
					    Copy: "复制记忆",
 | 
				
			||||||
 | 
					    Reset: "重置对话",
 | 
				
			||||||
 | 
					    ResetConfirm: "重置后将清空当前对话记录以及历史记忆,确认重置?",
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  Home: {
 | 
					  Home: {
 | 
				
			||||||
    NewChat: "新的聊天",
 | 
					    NewChat: "新的聊天",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,11 @@ const en: LocaleType = {
 | 
				
			|||||||
  Memory: {
 | 
					  Memory: {
 | 
				
			||||||
    Title: "Memory Prompt",
 | 
					    Title: "Memory Prompt",
 | 
				
			||||||
    EmptyContent: "Nothing yet.",
 | 
					    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: {
 | 
					  Home: {
 | 
				
			||||||
    NewChat: "New Chat",
 | 
					    NewChat: "New Chat",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,6 +42,10 @@ const es: LocaleType = {
 | 
				
			|||||||
    Title: "Historial de memoria",
 | 
					    Title: "Historial de memoria",
 | 
				
			||||||
    EmptyContent: "Aún no hay nada.",
 | 
					    EmptyContent: "Aún no hay nada.",
 | 
				
			||||||
    Copy: "Copiar todo",
 | 
					    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: {
 | 
					  Home: {
 | 
				
			||||||
    NewChat: "Nuevo chat",
 | 
					    NewChat: "Nuevo chat",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,6 +42,10 @@ const it: LocaleType = {
 | 
				
			|||||||
    Title: "Prompt di memoria",
 | 
					    Title: "Prompt di memoria",
 | 
				
			||||||
    EmptyContent: "Vuoto.",
 | 
					    EmptyContent: "Vuoto.",
 | 
				
			||||||
    Copy: "Copia tutto",
 | 
					    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: {
 | 
					  Home: {
 | 
				
			||||||
    NewChat: "Nuova Chat",
 | 
					    NewChat: "Nuova Chat",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,6 +41,9 @@ const tw: LocaleType = {
 | 
				
			|||||||
    Title: "上下文記憶 Prompt",
 | 
					    Title: "上下文記憶 Prompt",
 | 
				
			||||||
    EmptyContent: "尚未記憶",
 | 
					    EmptyContent: "尚未記憶",
 | 
				
			||||||
    Copy: "複製全部",
 | 
					    Copy: "複製全部",
 | 
				
			||||||
 | 
					    Send: "發送記憶",
 | 
				
			||||||
 | 
					    Reset: "重置對話",
 | 
				
			||||||
 | 
					    ResetConfirm: "重置後將清空當前對話記錄以及歷史記憶,確認重置?",
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  Home: {
 | 
					  Home: {
 | 
				
			||||||
    NewChat: "新的對話",
 | 
					    NewChat: "新的對話",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -149,6 +149,7 @@ export interface ChatStat {
 | 
				
			|||||||
export interface ChatSession {
 | 
					export interface ChatSession {
 | 
				
			||||||
  id: number;
 | 
					  id: number;
 | 
				
			||||||
  topic: string;
 | 
					  topic: string;
 | 
				
			||||||
 | 
					  sendMemory: boolean;
 | 
				
			||||||
  memoryPrompt: string;
 | 
					  memoryPrompt: string;
 | 
				
			||||||
  context: Message[];
 | 
					  context: Message[];
 | 
				
			||||||
  messages: Message[];
 | 
					  messages: Message[];
 | 
				
			||||||
@@ -170,6 +171,7 @@ function createEmptySession(): ChatSession {
 | 
				
			|||||||
  return {
 | 
					  return {
 | 
				
			||||||
    id: Date.now(),
 | 
					    id: Date.now(),
 | 
				
			||||||
    topic: DEFAULT_TOPIC,
 | 
					    topic: DEFAULT_TOPIC,
 | 
				
			||||||
 | 
					    sendMemory: true,
 | 
				
			||||||
    memoryPrompt: "",
 | 
					    memoryPrompt: "",
 | 
				
			||||||
    context: [],
 | 
					    context: [],
 | 
				
			||||||
    messages: [],
 | 
					    messages: [],
 | 
				
			||||||
@@ -202,6 +204,7 @@ interface ChatStore {
 | 
				
			|||||||
    messageIndex: number,
 | 
					    messageIndex: number,
 | 
				
			||||||
    updater: (message?: Message) => void,
 | 
					    updater: (message?: Message) => void,
 | 
				
			||||||
  ) => void;
 | 
					  ) => void;
 | 
				
			||||||
 | 
					  resetSession: () => void;
 | 
				
			||||||
  getMessagesWithMemory: () => Message[];
 | 
					  getMessagesWithMemory: () => Message[];
 | 
				
			||||||
  getMemoryPrompt: () => Message;
 | 
					  getMemoryPrompt: () => Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -391,7 +394,11 @@ export const useChatStore = create<ChatStore>()(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const context = session.context.slice();
 | 
					        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();
 | 
					          const memoryPrompt = get().getMemoryPrompt();
 | 
				
			||||||
          context.push(memoryPrompt);
 | 
					          context.push(memoryPrompt);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -415,6 +422,13 @@ export const useChatStore = create<ChatStore>()(
 | 
				
			|||||||
        set(() => ({ sessions }));
 | 
					        set(() => ({ sessions }));
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      resetSession() {
 | 
				
			||||||
 | 
					        get().updateCurrentSession((session) => {
 | 
				
			||||||
 | 
					          session.messages = [];
 | 
				
			||||||
 | 
					          session.memoryPrompt = "";
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      summarizeSession() {
 | 
					      summarizeSession() {
 | 
				
			||||||
        const session = get().currentSession();
 | 
					        const session = get().currentSession();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -506,7 +520,7 @@ export const useChatStore = create<ChatStore>()(
 | 
				
			|||||||
    }),
 | 
					    }),
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      name: LOCAL_KEY,
 | 
					      name: LOCAL_KEY,
 | 
				
			||||||
      version: 1.1,
 | 
					      version: 1.2,
 | 
				
			||||||
      migrate(persistedState, version) {
 | 
					      migrate(persistedState, version) {
 | 
				
			||||||
        const state = persistedState as ChatStore;
 | 
					        const state = persistedState as ChatStore;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -514,6 +528,10 @@ export const useChatStore = create<ChatStore>()(
 | 
				
			|||||||
          state.sessions.forEach((s) => (s.context = []));
 | 
					          state.sessions.forEach((s) => (s.context = []));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (version < 1.2) {
 | 
				
			||||||
 | 
					          state.sessions.forEach((s) => (s.sendMemory = true));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return state;
 | 
					        return state;
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -126,6 +126,10 @@ select {
 | 
				
			|||||||
  text-align: center;
 | 
					  text-align: center;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					label {
 | 
				
			||||||
 | 
					  cursor: pointer;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
input {
 | 
					input {
 | 
				
			||||||
  text-align: center;
 | 
					  text-align: center;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user