diff --git a/src/app.tsx b/src/app.tsx index e961332..0e32477 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -35,7 +35,9 @@ export interface ChatStore { responseModelName: string; cost: number; temperature: number; + temperature_enabled: boolean; top_p: number; + top_p_enabled: boolean; presence_penalty: number; frequency_penalty: number; develop_mode: boolean; @@ -70,7 +72,9 @@ const newChatStore = ( responseModelName: "", cost: 0, temperature: getDefaultParams("temp", temperature), + temperature_enabled: true, top_p: 1, + top_p_enabled: false, presence_penalty: 0, frequency_penalty: 0, develop_mode: getDefaultParams("dev", dev), diff --git a/src/chatbox.tsx b/src/chatbox.tsx index 53e2986..5666431 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -158,7 +158,9 @@ export default function ChatBOX(props: { client.sysMessageContent = chatStore.systemMessageContent; client.tokens_margin = chatStore.tokenMargin; client.temperature = chatStore.temperature; + client.enable_temperature = chatStore.temperature_enabled; client.top_p = chatStore.top_p; + client.enable_top_p = chatStore.top_p_enabled client.frequency_penalty = chatStore.frequency_penalty; client.presence_penalty = chatStore.presence_penalty; client.messages = chatStore.history diff --git a/src/chatgpt.ts b/src/chatgpt.ts index 81a06eb..1a1fc33 100644 --- a/src/chatgpt.ts +++ b/src/chatgpt.ts @@ -47,7 +47,9 @@ class Chat { apiEndpoint: string; model: string; temperature: number; + enable_temperature: boolean; top_p: number; + enable_top_p: boolean; presence_penalty: number; frequency_penalty: number; @@ -60,7 +62,9 @@ class Chat { apiEndPoint = "https://api.openai.com/v1/chat/completions", model = "gpt-3.5-turbo", temperature = 0.7, + enable_temperature = true, top_p = 1, + enable_top_p = false, presence_penalty = 0, frequency_penalty = 0, } = {} @@ -77,7 +81,9 @@ class Chat { this.apiEndpoint = apiEndPoint; this.model = model; this.temperature = temperature; + this.enable_temperature = enable_temperature; this.top_p = top_p; + this.enable_top_p = enable_top_p; this.presence_penalty = presence_penalty; this.frequency_penalty = frequency_penalty; } @@ -111,21 +117,28 @@ class Chat { messages.push({ role: "system", content: this.sysMessageContent }); } messages.push(...this.messages); + + const body: any = { + model: this.model, + messages, + stream, + presence_penalty: this.presence_penalty, + frequency_penalty: this.frequency_penalty, + }; + if (this.enable_temperature) { + body["temperature"] = this.temperature; + } + if (this.enable_top_p) { + body["top_p"] = this.top_p; + } + return fetch(this.apiEndpoint, { method: "POST", headers: { Authorization: `Bearer ${this.OPENAI_API_KEY}`, "Content-Type": "application/json", }, - body: JSON.stringify({ - model: this.model, - messages, - stream, - temperature: this.temperature, - top_p: this.top_p, - presence_penalty: this.presence_penalty, - frequency_penalty: this.frequency_penalty, - }), + body: JSON.stringify(body), }); } diff --git a/src/settings.tsx b/src/settings.tsx index 42c29f4..2c7b07b 100644 --- a/src/settings.tsx +++ b/src/settings.tsx @@ -4,6 +4,7 @@ import { ChatStore, TemplateAPI, clearTotalCost, getTotalCost } from "./app"; import models from "./models"; import { TemplateChatStore } from "./chatbox"; import { tr, Tr, langCodeContext, LANG_OPTIONS } from "./translate"; +import p from "preact-markdown"; const Help = (props: { children: any; help: string }) => { return ( @@ -100,14 +101,42 @@ const Input = (props: { const Slicer = (props: { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; - field: "temperature"; + field: "temperature" | "top_p"; help: string; }) => { + const enable_filed_name: "temperature_enabled" | "top_p_enabled" = + `${props.field}_enabled` as any; + + const enabled = props.chatStore[enable_filed_name]; + + if (enabled === null || enabled === undefined) { + if (props.field === "temperature") { + props.chatStore[enable_filed_name] = true; + } + if (props.field === "top_p") { + props.chatStore[enable_filed_name] = false; + } + } + + const setEnabled = (state: boolean) => { + props.chatStore[enable_filed_name] = state; + props.setChatStore({ ...props.chatStore }); + }; return ( - + + + { + setEnabled(!enabled); + }} + /> + - +