From 6acf87807ff401224da0c9fb5ed3b4fbcd0b1710 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Thu, 20 Jul 2023 02:01:57 +0800 Subject: [PATCH] fix template default params --- src/chatbox.tsx | 17 ++++++++++++++++- src/settings.tsx | 7 +++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/chatbox.tsx b/src/chatbox.tsx index 684ce6a..3f1114e 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -9,6 +9,7 @@ import ChatGPT, { import Message from "./message"; import models from "./models"; import Settings from "./settings"; +import getDefaultParams from "./getDefaultParam"; export interface TemplateChatStore extends ChatStore { name: string; @@ -354,8 +355,22 @@ export default function ChatBOX(props: {
{ - const newChatStore: any = { ...t }; + const newChatStore: ChatStore = structuredClone(t); + // @ts-ignore delete newChatStore.name; + if (!newChatStore.apiEndpoint) { + newChatStore.apiEndpoint = getDefaultParams( + "api", + chatStore.apiEndpoint + ); + } + if (!newChatStore.apiKey) { + newChatStore.apiKey = getDefaultParams( + "key", + chatStore.apiKey + ); + } + newChatStore.cost = 0; setChatStore({ ...newChatStore }); }} > diff --git a/src/settings.tsx b/src/settings.tsx index 888f40e..c25637f 100644 --- a/src/settings.tsx +++ b/src/settings.tsx @@ -342,8 +342,11 @@ export default (props: { alert("No template name specified"); return; } - const tmp: TemplateChatStore = { name, ...props.chatStore }; - props.templates.push(tmp); + const tmp: ChatStore = structuredClone(props.chatStore); + tmp.history = tmp.history.filter((h) => h.example); + // @ts-ignore + tmp.name = name; + props.templates.push(tmp as TemplateChatStore); props.setTemplates([...props.templates]); }} >