From 795cb16ed4118da327dc4af9b8e39b7b169e223f Mon Sep 17 00:00:00 2001
From: heimoshuiyu
Date: Tue, 15 Oct 2024 17:32:33 +0800
Subject: [PATCH] refac: componets/versionHint.tsx
---
src/components/versionHint.tsx | 49 +++++++++++++++++++
src/pages/chatbox.tsx | 87 ++++++++++------------------------
2 files changed, 75 insertions(+), 61 deletions(-)
create mode 100644 src/components/versionHint.tsx
diff --git a/src/components/versionHint.tsx b/src/components/versionHint.tsx
new file mode 100644
index 0000000..bcb5dcb
--- /dev/null
+++ b/src/components/versionHint.tsx
@@ -0,0 +1,49 @@
+import { ChatStore } from "@/types/chatstore";
+import { Tr } from "@/translate";
+
+const VersionHint = (props: { chatStore: ChatStore }) => {
+ const { chatStore } = props;
+ return (
+ <>
+ {chatStore.chatgpt_api_web_version < "v1.3.0" && (
+
+
+ {Tr("Warning: current chatStore version")}:{" "}
+ {chatStore.chatgpt_api_web_version} {"< v1.3.0"}
+
+ v1.3.0
+ 引入与旧版不兼容的消息裁切算法。继续使用旧版可能会导致消息裁切过多或过少(表现为失去上下文或输出不完整)。
+
+ 请在左上角创建新会话:)
+
+ )}
+ {chatStore.chatgpt_api_web_version < "v1.4.0" && (
+
+
+ {Tr("Warning: current chatStore version")}:{" "}
+ {chatStore.chatgpt_api_web_version} {"< v1.4.0"}
+
+ v1.4.0 增加了更多参数,继续使用旧版可能因参数确实导致未定义的行为
+
+ 请在左上角创建新会话:)
+
+ )}
+ {chatStore.chatgpt_api_web_version < "v1.6.0" && (
+
+
+ 提示:当前会话版本 {chatStore.chatgpt_api_web_version}
+ {Tr("Warning: current chatStore version")}:{" "}
+ {chatStore.chatgpt_api_web_version} {"< v1.6.0"}
+ 。
+
+ v1.6.0 开始保存会话模板时会将 apiKey 和 apiEndpoint
+ 设置为空,继续使用旧版可能在保存读取模板时出现问题
+
+ 请在左上角创建新会话:)
+
+ )}
+ >
+ );
+};
+
+export default VersionHint;
\ No newline at end of file
diff --git a/src/pages/chatbox.tsx b/src/pages/chatbox.tsx
index 2ca3671..eb74eb7 100644
--- a/src/pages/chatbox.tsx
+++ b/src/pages/chatbox.tsx
@@ -46,6 +46,7 @@ import { ListToolsTempaltes } from "@/listToolsTemplates";
import { autoHeight } from "@/textarea";
import Search from "@/search";
import Templates from "@/components/templates";
+import VersionHint from "@/components/versionHint";
export default function ChatBOX(props: {
db: Promise>;
@@ -93,7 +94,7 @@ export default function ChatBOX(props: {
const update_total_tokens = () => {
// manually estimate token
client.total_tokens = calculate_token_length(
- chatStore.systemMessageContent,
+ chatStore.systemMessageContent
);
for (const msg of chatStore.history
.filter(({ hide }) => !hide)
@@ -149,7 +150,7 @@ export default function ChatBOX(props: {
// update tool call arguments
const tool = allChunkTool.find(
- (tool) => tool.index === tool_call.index,
+ (tool) => tool.index === tool_call.index
);
if (!tool) {
@@ -164,7 +165,7 @@ export default function ChatBOX(props: {
allChunkMessage.join("") +
allChunkTool.map((tool) => {
return `Tool Call ID: ${tool.id}\nType: ${tool.type}\nFunction: ${tool.function.name}\nArguments: ${tool.function.arguments}`;
- }),
+ })
);
}
setShowGenerating(false);
@@ -302,7 +303,7 @@ export default function ChatBOX(props: {
setShowGenerating(true);
const response = await client._fetch(
chatStore.streamMode,
- chatStore.logprobs,
+ chatStore.logprobs
);
const contentType = response.headers.get("content-type");
if (contentType?.startsWith("text/event-stream")) {
@@ -372,33 +373,33 @@ export default function ChatBOX(props: {
const [templates, _setTemplates] = useState(
JSON.parse(
- localStorage.getItem(STORAGE_NAME_TEMPLATE) || "[]",
- ) as TemplateChatStore[],
+ localStorage.getItem(STORAGE_NAME_TEMPLATE) || "[]"
+ ) as TemplateChatStore[]
);
const [templateAPIs, _setTemplateAPIs] = useState(
JSON.parse(
- localStorage.getItem(STORAGE_NAME_TEMPLATE_API) || "[]",
- ) as TemplateAPI[],
+ localStorage.getItem(STORAGE_NAME_TEMPLATE_API) || "[]"
+ ) as TemplateAPI[]
);
const [templateAPIsWhisper, _setTemplateAPIsWhisper] = useState(
JSON.parse(
- localStorage.getItem(STORAGE_NAME_TEMPLATE_API_WHISPER) || "[]",
- ) as TemplateAPI[],
+ localStorage.getItem(STORAGE_NAME_TEMPLATE_API_WHISPER) || "[]"
+ ) as TemplateAPI[]
);
const [templateAPIsTTS, _setTemplateAPIsTTS] = useState(
JSON.parse(
- localStorage.getItem(STORAGE_NAME_TEMPLATE_API_TTS) || "[]",
- ) as TemplateAPI[],
+ localStorage.getItem(STORAGE_NAME_TEMPLATE_API_TTS) || "[]"
+ ) as TemplateAPI[]
);
const [templateAPIsImageGen, _setTemplateAPIsImageGen] = useState(
JSON.parse(
- localStorage.getItem(STORAGE_NAME_TEMPLATE_API_IMAGE_GEN) || "[]",
- ) as TemplateAPI[],
+ localStorage.getItem(STORAGE_NAME_TEMPLATE_API_IMAGE_GEN) || "[]"
+ ) as TemplateAPI[]
);
const [toolsTemplates, _setToolsTemplates] = useState(
JSON.parse(
- localStorage.getItem(STORAGE_NAME_TEMPLATE_TOOLS) || "[]",
- ) as TemplateTools[],
+ localStorage.getItem(STORAGE_NAME_TEMPLATE_TOOLS) || "[]"
+ ) as TemplateTools[]
);
const setTemplates = (templates: TemplateChatStore[]) => {
localStorage.setItem(STORAGE_NAME_TEMPLATE, JSON.stringify(templates));
@@ -407,35 +408,35 @@ export default function ChatBOX(props: {
const setTemplateAPIs = (templateAPIs: TemplateAPI[]) => {
localStorage.setItem(
STORAGE_NAME_TEMPLATE_API,
- JSON.stringify(templateAPIs),
+ JSON.stringify(templateAPIs)
);
_setTemplateAPIs(templateAPIs);
};
const setTemplateAPIsWhisper = (templateAPIWhisper: TemplateAPI[]) => {
localStorage.setItem(
STORAGE_NAME_TEMPLATE_API_WHISPER,
- JSON.stringify(templateAPIWhisper),
+ JSON.stringify(templateAPIWhisper)
);
_setTemplateAPIsWhisper(templateAPIWhisper);
};
const setTemplateAPIsTTS = (templateAPITTS: TemplateAPI[]) => {
localStorage.setItem(
STORAGE_NAME_TEMPLATE_API_TTS,
- JSON.stringify(templateAPITTS),
+ JSON.stringify(templateAPITTS)
);
_setTemplateAPIsTTS(templateAPITTS);
};
const setTemplateAPIsImageGen = (templateAPIImageGen: TemplateAPI[]) => {
localStorage.setItem(
STORAGE_NAME_TEMPLATE_API_IMAGE_GEN,
- JSON.stringify(templateAPIImageGen),
+ JSON.stringify(templateAPIImageGen)
);
_setTemplateAPIsImageGen(templateAPIImageGen);
};
const setTemplateTools = (templateTools: TemplateTools[]) => {
localStorage.setItem(
STORAGE_NAME_TEMPLATE_TOOLS,
- JSON.stringify(templateTools),
+ JSON.stringify(templateTools)
);
_setToolsTemplates(templateTools);
};
@@ -761,7 +762,7 @@ export default function ChatBOX(props: {
↖{Tr("Click the conor to create a new chat")}
⚠
{Tr(
- "All chat history and settings are stored in the local browser",
+ "All chat history and settings are stored in the local browser"
)}
@@ -839,43 +840,7 @@ export default function ChatBOX(props: {
>
)}
- {chatStore.chatgpt_api_web_version < "v1.3.0" && (
-
-
- {Tr("Warning: current chatStore version")}:{" "}
- {chatStore.chatgpt_api_web_version} {"< v1.3.0"}
-
- v1.3.0
- 引入与旧版不兼容的消息裁切算法。继续使用旧版可能会导致消息裁切过多或过少(表现为失去上下文或输出不完整)。
-
- 请在左上角创建新会话:)
-
- )}
- {chatStore.chatgpt_api_web_version < "v1.4.0" && (
-
-
- {Tr("Warning: current chatStore version")}:{" "}
- {chatStore.chatgpt_api_web_version} {"< v1.4.0"}
-
- v1.4.0 增加了更多参数,继续使用旧版可能因参数确实导致未定义的行为
-
- 请在左上角创建新会话:)
-
- )}
- {chatStore.chatgpt_api_web_version < "v1.6.0" && (
-
-
- 提示:当前会话版本 {chatStore.chatgpt_api_web_version}
- {Tr("Warning: current chatStore version")}:{" "}
- {chatStore.chatgpt_api_web_version} {"< v1.6.0"}
- 。
-
- v1.6.0 开始保存会话模板时会将 apiKey 和 apiEndpoint
- 设置为空,继续使用旧版可能在保存读取模板时出现问题
-
- 请在左上角创建新会话:)
-
- )}
+
{showRetry && (