From 7dea556a562562cc22e0f58442c5a86775f26512 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Fri, 7 Feb 2025 21:40:48 +0800 Subject: [PATCH] fix history --- src/components/ListAPI.tsx | 10 ++++++++-- src/types/newChatstore.ts | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/ListAPI.tsx b/src/components/ListAPI.tsx index b7efb82..9b096ca 100644 --- a/src/components/ListAPI.tsx +++ b/src/components/ListAPI.tsx @@ -259,11 +259,17 @@ const ChatTemplateItem = ({ if (chatStore.history.length > 0 || chatStore.systemMessageContent) { console.log("you clicked", t.name); const confirm = window.confirm( - "This will replace the current chat history. Are you sure?" + "This will replace the current chat history. Are you sure? " ); if (!confirm) return; } - setChatStore({ ...newChatStore({ ...chatStore, ...t }) }); + setChatStore({ + ...newChatStore({ + ...chatStore, + ...{ use_this_history: t.history ?? chatStore.history }, + ...t, + }), + }); }} > diff --git a/src/types/newChatstore.ts b/src/types/newChatstore.ts index 0501152..2bfbbe8 100644 --- a/src/types/newChatstore.ts +++ b/src/types/newChatstore.ts @@ -4,7 +4,7 @@ import { CHATGPT_API_WEB_VERSION, } from "@/const"; import { getDefaultParams } from "@/utils/getDefaultParam"; -import { ChatStore } from "@/types/chatstore"; +import { ChatStore, ChatStoreMessage } from "@/types/chatstore"; import { models } from "@/types/models"; interface NewChatStoreOptions { @@ -36,6 +36,7 @@ interface NewChatStoreOptions { json_mode?: boolean; logprobs?: boolean; maxTokens?: number; + use_this_history?: ChatStoreMessage[]; } export const newChatStore = (options: NewChatStoreOptions): ChatStore => { @@ -46,7 +47,7 @@ export const newChatStore = (options: NewChatStoreOptions): ChatStore => { options.systemMessageContent ?? "" ), toolsString: options.toolsString ?? "", - history: [], + history: options.use_this_history ?? [], postBeginIndex: 0, tokenMargin: 1024, totalTokens: 0,