From 587d0ba57d469170e4e0ff559218d3f4acbcc025 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Tue, 15 Oct 2024 17:33:06 +0800 Subject: [PATCH] rename components --- .../{templates.tsx => Templates.tsx} | 0 .../{versionHint.tsx => VersionHint.tsx} | 2 +- src/pages/chatbox.tsx | 54 +++++++++---------- 3 files changed, 27 insertions(+), 29 deletions(-) rename src/components/{templates.tsx => Templates.tsx} (100%) rename src/components/{versionHint.tsx => VersionHint.tsx} (98%) diff --git a/src/components/templates.tsx b/src/components/Templates.tsx similarity index 100% rename from src/components/templates.tsx rename to src/components/Templates.tsx diff --git a/src/components/versionHint.tsx b/src/components/VersionHint.tsx similarity index 98% rename from src/components/versionHint.tsx rename to src/components/VersionHint.tsx index bcb5dcb..1421ab2 100644 --- a/src/components/versionHint.tsx +++ b/src/components/VersionHint.tsx @@ -46,4 +46,4 @@ const VersionHint = (props: { chatStore: ChatStore }) => { ); }; -export default VersionHint; \ No newline at end of file +export default VersionHint; diff --git a/src/pages/chatbox.tsx b/src/pages/chatbox.tsx index eb74eb7..aac467c 100644 --- a/src/pages/chatbox.tsx +++ b/src/pages/chatbox.tsx @@ -8,7 +8,6 @@ import { } from "@heroicons/react/24/outline"; import { IDBPDatabase } from "idb"; -import structuredClone from "@ungap/structured-clone"; import { createRef } from "preact"; import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks"; import { Tr, langCodeContext, LANG_OPTIONS } from "@/translate"; @@ -39,14 +38,13 @@ import { import Message from "@/message"; import { models } from "@/types/models"; import Settings from "@/settings"; -import { getDefaultParams } from "@/utils/getDefaultParam"; import { AddImage } from "@/addImage"; import { ListAPIs } from "@/listAPIs"; import { ListToolsTempaltes } from "@/listToolsTemplates"; import { autoHeight } from "@/textarea"; import Search from "@/search"; -import Templates from "@/components/templates"; -import VersionHint from "@/components/versionHint"; +import Templates from "@/components/Templates"; +import VersionHint from "@/components/VersionHint"; export default function ChatBOX(props: { db: Promise>; @@ -94,7 +92,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) @@ -150,7 +148,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) { @@ -165,7 +163,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); @@ -303,7 +301,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")) { @@ -373,33 +371,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)); @@ -408,35 +406,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); }; @@ -762,7 +760,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", )}

@@ -969,7 +967,7 @@ export default function ChatBOX(props: { } else { return content.map((c) => c?.text).join(" "); } - }) + }), ) .concat([inputMsg]) .join(" "); @@ -983,7 +981,7 @@ export default function ChatBOX(props: { await navigator.mediaDevices.getUserMedia({ audio: true, }), - { audioBitsPerSecond: 64 * 1000 } + { audioBitsPerSecond: 64 * 1000 }, ); // mount mediaRecorder to ref