diff --git a/src/CHATGPT_API_WEB_VERSION.ts b/src/CHATGPT_API_WEB_VERSION.ts index 451d8f5..79ca382 100644 --- a/src/CHATGPT_API_WEB_VERSION.ts +++ b/src/CHATGPT_API_WEB_VERSION.ts @@ -1,3 +1,3 @@ -const CHATGPT_API_WEB_VERSION = "v1.5.0"; +const CHATGPT_API_WEB_VERSION = "v1.6.0"; export default CHATGPT_API_WEB_VERSION; diff --git a/src/app.tsx b/src/app.tsx index 7252a73..39e5c80 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -14,6 +14,11 @@ export interface ChatStoreMessage extends Message { example: boolean; } +export interface TemplateAPI { + name: string; + key: string; + endpoint: string; +} export interface ChatStore { chatgpt_api_web_version: string; systemMessageContent: string; @@ -78,6 +83,7 @@ const STORAGE_NAME_SELECTED = `${STORAGE_NAME}-selected`; const STORAGE_NAME_INDEXES = `${STORAGE_NAME}-indexes`; const STORAGE_NAME_TOTALCOST = `${STORAGE_NAME}-totalcost`; export const STORAGE_NAME_TEMPLATE = `${STORAGE_NAME}-template`; +export const STORAGE_NAME_TEMPLATE_API = `${STORAGE_NAME_TEMPLATE}-api`; export function addTotalCost(cost: number) { let totalCost = getTotalCost(); diff --git a/src/chatbox.tsx b/src/chatbox.tsx index 90632be..905be02 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -1,7 +1,13 @@ import structuredClone from "@ungap/structured-clone"; import { createRef } from "preact"; import { StateUpdater, useEffect, useState } from "preact/hooks"; -import { ChatStore, STORAGE_NAME_TEMPLATE, addTotalCost } from "./app"; +import { + ChatStore, + STORAGE_NAME_TEMPLATE, + STORAGE_NAME_TEMPLATE_API, + TemplateAPI, + addTotalCost, +} from "./app"; import ChatGPT, { calculate_token_length, ChunkMessage, @@ -233,10 +239,22 @@ export default function ChatBOX(props: { localStorage.getItem(STORAGE_NAME_TEMPLATE) || "[]" ) as TemplateChatStore[] ); + const [templateAPIs, _setTemplateAPIs] = useState( + JSON.parse( + localStorage.getItem(STORAGE_NAME_TEMPLATE_API) || "[]" + ) as TemplateAPI[] + ); const setTemplates = (templates: TemplateChatStore[]) => { localStorage.setItem(STORAGE_NAME_TEMPLATE, JSON.stringify(templates)); _setTemplates(templates); }; + const setTemplateAPIs = (templateAPIs: TemplateAPI[]) => { + localStorage.setItem( + STORAGE_NAME_TEMPLATE_API, + JSON.stringify(templateAPIs) + ); + _setTemplateAPIs(templateAPIs); + }; return (
)} + {(chatStore.history.filter((msg) => !msg.example).length == 0 || + !chatStore.apiEndpoint || + !chatStore.apiKey) && ( +
+
@@ -465,6 +542,18 @@ export default function ChatBOX(props: { 请在左上角创建新会话:)
)} + {chatStore.chatgpt_api_web_version < "v1.6.0" && ( +
+
+ 提示:当前会话版本 {chatStore.chatgpt_api_web_version} {"< v1.6.0"}
+ 。
+
+ v1.6.0 开始保存会话模板时会将 apiKey 和 apiEndpoint
+ 设置为空,继续使用旧版可能在保存读取模板时出现问题
+
+ 请在左上角创建新会话:)
+
+