import { createRef } from "preact"; import { StateUpdater, useState } from "preact/hooks"; import { ChatStore, clearTotalCost, getTotalCost } from "./app"; import models from "./models"; import { TemplateChatStore } from "./chatbox"; const Help = (props: { children: any; help: string }) => { return (

{props.children}

); }; const SelectModel = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; help: string; }) => { return ( ); }; const LongInput = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; field: "systemMessageContent"; help: string; }) => { return ( ); }; const Input = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; field: "apiKey" | "apiEndpoint"; help: string; }) => { const [hideInput, setHideInput] = useState(false); return ( setHideInput(!hideInput)} > { props.chatStore[props.field] = event.target.value; props.setChatStore({ ...props.chatStore }); }} > ); }; const Number = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; field: | "totalTokens" | "maxTokens" | "tokenMargin" | "postBeginIndex" | "temperature" | "top_p" | "presence_penalty" | "frequency_penalty"; readOnly: boolean; help: string; }) => { return ( { console.log("type", typeof event.target.value); let newNumber = parseFloat(event.target.value); if (newNumber < 0) newNumber = 0; props.chatStore[props.field] = newNumber; props.setChatStore({ ...props.chatStore }); }} > ); }; const Choice = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; field: "streamMode" | "develop_mode"; help: string; }) => { return ( { props.chatStore[props.field] = event.target.checked; props.setChatStore({ ...props.chatStore }); }} > ); }; export default (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; setShow: StateUpdater; selectedChatStoreIndex: number; templates: TemplateChatStore[]; setTemplates: (templates: TemplateChatStore[]) => void; }) => { let link = location.protocol + "//" + location.host + location.pathname + `?key=${encodeURIComponent( props.chatStore.apiKey )}&api=${encodeURIComponent(props.chatStore.apiEndpoint)}&mode=${ props.chatStore.streamMode ? "stream" : "fetch" }&model=${props.chatStore.model}&sys=${encodeURIComponent( props.chatStore.systemMessageContent )}`; if (props.chatStore.develop_mode) { link = link + `&dev=true`; } const importFileRef = createRef(); const [totalCost, setTotalCost] = useState(getTotalCost()); return (
props.setShow(false)} className="left-0 top-0 overflow-scroll flex justify-center absolute w-screen h-full bg-black bg-opacity-50 z-10" >
{ event.stopPropagation(); }} className="m-2 p-2 bg-white rounded-lg h-fit lg:w-2/3 z-20" >

Settings


Total cost in this session ${props.chatStore.cost.toFixed(4)}


Accumulated cost in all sessions ${totalCost.toFixed(4)}

{ const file = importFileRef.current.files[0]; console.log("file to import", file); if (!file || file.type !== "application/json") { alert("Please select a json file"); return; } const reader = new FileReader(); reader.onload = () => { console.log("import content", reader.result); if (!reader) { alert("Empty file"); return; } try { const newChatStore: ChatStore = JSON.parse( reader.result as string ); if (!newChatStore.chatgpt_api_web_version) { throw "This is not an exported chatgpt-api-web chatstore file. The key 'chatgpt_api_web_version' is missing!"; } props.setChatStore({ ...newChatStore }); } catch (e) { alert(`Import error on parsing json: ${e}`); } }; reader.readAsText(file); }} />

chatgpt-api-web ChatStore Version{" "} {props.chatStore.chatgpt_api_web_version}


); };