fix history

This commit is contained in:
2025-02-07 21:40:48 +08:00
parent 79d5ded088
commit 7dea556a56
2 changed files with 11 additions and 4 deletions

View File

@@ -259,11 +259,17 @@ const ChatTemplateItem = ({
if (chatStore.history.length > 0 || chatStore.systemMessageContent) { if (chatStore.history.length > 0 || chatStore.systemMessageContent) {
console.log("you clicked", t.name); console.log("you clicked", t.name);
const confirm = window.confirm( 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; if (!confirm) return;
} }
setChatStore({ ...newChatStore({ ...chatStore, ...t }) }); setChatStore({
...newChatStore({
...chatStore,
...{ use_this_history: t.history ?? chatStore.history },
...t,
}),
});
}} }}
> >
<NavigationMenuLink asChild> <NavigationMenuLink asChild>

View File

@@ -4,7 +4,7 @@ import {
CHATGPT_API_WEB_VERSION, CHATGPT_API_WEB_VERSION,
} from "@/const"; } from "@/const";
import { getDefaultParams } from "@/utils/getDefaultParam"; import { getDefaultParams } from "@/utils/getDefaultParam";
import { ChatStore } from "@/types/chatstore"; import { ChatStore, ChatStoreMessage } from "@/types/chatstore";
import { models } from "@/types/models"; import { models } from "@/types/models";
interface NewChatStoreOptions { interface NewChatStoreOptions {
@@ -36,6 +36,7 @@ interface NewChatStoreOptions {
json_mode?: boolean; json_mode?: boolean;
logprobs?: boolean; logprobs?: boolean;
maxTokens?: number; maxTokens?: number;
use_this_history?: ChatStoreMessage[];
} }
export const newChatStore = (options: NewChatStoreOptions): ChatStore => { export const newChatStore = (options: NewChatStoreOptions): ChatStore => {
@@ -46,7 +47,7 @@ export const newChatStore = (options: NewChatStoreOptions): ChatStore => {
options.systemMessageContent ?? "" options.systemMessageContent ?? ""
), ),
toolsString: options.toolsString ?? "", toolsString: options.toolsString ?? "",
history: [], history: options.use_this_history ?? [],
postBeginIndex: 0, postBeginIndex: 0,
tokenMargin: 1024, tokenMargin: 1024,
totalTokens: 0, totalTokens: 0,