diff --git a/src/CHATGPT_API_WEB_VERSION.ts b/src/CHATGPT_API_WEB_VERSION.ts index ec86328..a7d5d37 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.3.0"; +const CHATGPT_API_WEB_VERSION = "v1.4.0"; export default CHATGPT_API_WEB_VERSION; diff --git a/src/app.tsx b/src/app.tsx index 9aa7ff8..f97be86 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -27,6 +27,11 @@ export interface ChatStore { model: string; responseModelName: string; cost: number; + temperature: number; + top_p: number; + presence_penalty: number; + frequency_penalty: number; + develop_mode: boolean; } const _defaultAPIEndpoint = "https://api.openai.com/v1/chat/completions"; @@ -35,7 +40,9 @@ const newChatStore = ( systemMessageContent = "Follow my instructions carefully", apiEndpoint = _defaultAPIEndpoint, streamMode = true, - model = "gpt-3.5-turbo-0613" + model = "gpt-3.5-turbo-0613", + temperature = 1.0, + dev = false ): ChatStore => { return { chatgpt_api_web_version: CHATGPT_API_WEB_VERSION, @@ -51,6 +58,11 @@ const newChatStore = ( model: getDefaultParams("model", model), responseModelName: "", cost: 0, + temperature: getDefaultParams("temp", temperature), + top_p: 1, + presence_penalty: 0, + frequency_penalty: 0, + develop_mode: getDefaultParams("dev", dev), }; }; diff --git a/src/chatbox.tsx b/src/chatbox.tsx index ceebe02..47c93e9 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -32,6 +32,19 @@ export default function ChatBOX(props: { const client = new ChatGPT(chatStore.apiKey); + const update_total_tokens = () => { + // manually estimate token + client.total_tokens = calculate_token_length( + chatStore.systemMessageContent + ); + for (const msg of chatStore.history + .filter(({ hide }) => !hide) + .slice(chatStore.postBeginIndex)) { + client.total_tokens += msg.token; + } + chatStore.totalTokens = client.total_tokens; + }; + const _completeWithStreamMode = async (response: Response) => { chatStore.streamMode = true; // call api, return reponse text @@ -121,14 +134,7 @@ export default function ChatBOX(props: { // manually copy status from client to chatStore chatStore.maxTokens = client.max_tokens; chatStore.tokenMargin = client.tokens_margin; - // manually estimate token - client.total_tokens = 0; - for (const msg of chatStore.history - .filter(({ hide }) => !hide) - .slice(chatStore.postBeginIndex)) { - client.total_tokens += msg.token; - } - chatStore.totalTokens = client.total_tokens; + update_total_tokens(); setChatStore({ ...chatStore }); setGeneratingMessage(""); setShowGenerating(false); @@ -407,6 +413,42 @@ export default function ChatBOX(props: { > Send + {chatStore.develop_mode && ( + + )} + {chatStore.develop_mode && ( + + )} ); diff --git a/src/getDefaultParam.ts b/src/getDefaultParam.ts index 789bdb7..2f5ff89 100644 --- a/src/getDefaultParam.ts +++ b/src/getDefaultParam.ts @@ -7,10 +7,12 @@ function getDefaultParams(param: any, val: any) { if (typeof val === "string") { return get ?? val; } else if (typeof val === "number") { - return parseInt(get ?? `${val}`); + return parseFloat(get ?? `${val}`); } else if (typeof val === "boolean") { if (get === "stream") return true; if (get === "fetch") return false; + if (get === "true") return true; + if (get === "false") return false; return val; } } diff --git a/src/message.tsx b/src/message.tsx index b3e15e5..7c38f07 100644 --- a/src/message.tsx +++ b/src/message.tsx @@ -51,19 +51,59 @@ export default function Message(props: Props) { chat.role === "assistant" ? "justify-start" : "justify-end" }`} > -
-

- {chat.hide - ? chat.content.split("\n")[0].slice(0, 16) + "... (deleted)" - : chat.content} -

- +
+
+ {chatStore.develop_mode ? ( + + ) : ( +

+ {chat.hide + ? chat.content.split("\n")[0].slice(0, 16) + "... (deleted)" + : chat.content} +

+ )} + +
+
+ token {chatStore.history[messageIndex].token} + +
diff --git a/src/settings.tsx b/src/settings.tsx index 5df646f..88c286e 100644 --- a/src/settings.tsx +++ b/src/settings.tsx @@ -45,10 +45,30 @@ const SelectModel = (props: { ); }; +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" | "systemMessageContent" | "apiEndpoint"; + field: "apiKey" | "apiEndpoint"; help: string; }) => { return ( @@ -68,7 +88,15 @@ const Input = (props: { const Number = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; - field: "totalTokens" | "maxTokens" | "tokenMargin" | "postBeginIndex"; + field: + | "totalTokens" + | "maxTokens" + | "tokenMargin" + | "postBeginIndex" + | "temperature" + | "top_p" + | "presence_penalty" + | "frequency_penalty"; readOnly: boolean; help: string; }) => { @@ -82,7 +110,7 @@ const Number = (props: { value={props.chatStore[props.field]} onChange={(event: any) => { console.log("type", typeof event.target.value); - let newNumber = parseInt(event.target.value); + let newNumber = parseFloat(event.target.value); if (newNumber < 0) newNumber = 0; props.chatStore[props.field] = newNumber; props.setChatStore({ ...props.chatStore }); @@ -94,7 +122,7 @@ const Number = (props: { const Choice = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; - field: "streamMode"; + field: "streamMode" | "develop_mode"; help: string; }) => { return ( @@ -119,7 +147,7 @@ export default (props: { setShow: StateUpdater; selectedChatStoreIndex: number; }) => { - const link = + let link = location.protocol + "//" + location.host + @@ -131,6 +159,9 @@ export default (props: { }&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()); @@ -157,7 +188,7 @@ export default (props: { Total cost in this session ${props.chatStore.cost.toFixed(4)}

- + + + + +