From ac307f55510ac459439d0b92744b111a6c56bed0 Mon Sep 17 00:00:00 2001 From: ecwu Date: Fri, 20 Dec 2024 16:10:07 +0800 Subject: [PATCH] Refactor import path for Settings component to improve code organization --- src/components/Settings.tsx | 1164 ++++++++++++++++++++++++++++++++++ src/pages/Chatbox.tsx | 2 +- src/settings.tsx | 1177 ----------------------------------- 3 files changed, 1165 insertions(+), 1178 deletions(-) delete mode 100644 src/settings.tsx diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index 5dd8a92..9ca3510 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -1,3 +1,27 @@ +import { themeChange } from "theme-change"; + +import { createRef } from "preact"; +import { + StateUpdater, + useContext, + useEffect, + useState, + Dispatch, +} from "preact/hooks"; +import { clearTotalCost, getTotalCost } from "@/utils/totalCost"; +import { + ChatStore, + TemplateChatStore, + TemplateAPI, + TemplateTools, +} from "@/types/chatstore"; +import { models } from "@/types/models"; +import { tr, Tr, langCodeContext, LANG_OPTIONS } from "@/translate"; +import { isVailedJSON } from "@/message"; +import { SetAPIsTemplate } from "@/setAPIsTemplate"; +import { autoHeight } from "@/textarea"; +import { getDefaultParams } from "@/utils/getDefaultParam"; + import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; @@ -11,3 +35,1143 @@ import { SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Textarea } from "@/components/ui/textarea"; +import { + BanIcon, + CheckIcon, + CircleEllipsisIcon, + CogIcon, + Ellipsis, + EyeIcon, + InfoIcon, + KeyIcon, + ListIcon, + MoveHorizontalIcon, +} from "lucide-react"; +import { Separator } from "@/components/ui/separator"; +import { Slider } from "@/components/ui/slider"; + +const TTS_VOICES: string[] = [ + "alloy", + "echo", + "fable", + "onyx", + "nova", + "shimmer", +]; +const TTS_FORMAT: string[] = ["mp3", "opus", "aac", "flac"]; + +const Help = (props: { children: any; help: string; field: string }) => { + return ( +
+ +
+ ); +}; + +const SelectModel = (props: { + chatStore: ChatStore; + setChatStore: (cs: ChatStore) => void; + help: string; +}) => { + let shouldIUseCustomModel: boolean = true; + for (const model in models) { + if (props.chatStore.model === model) { + shouldIUseCustomModel = false; + } + } + const [useCustomModel, setUseCustomModel] = useState(shouldIUseCustomModel); + return ( +
+
+ + +
+ + setUseCustomModel(!useCustomModel)} + /> +
+
+ + {useCustomModel ? ( + ) => { + props.chatStore.model = e.target.value; + props.setChatStore({ ...props.chatStore }); + }} + /> + ) : ( + + )} +
+ ); +}; + +const LongInput = (props: { + chatStore: ChatStore; + setChatStore: (cs: ChatStore) => void; + field: "systemMessageContent" | "toolsString"; + label: string; + help: string; +}) => { + return ( +
+ + +