From d8d84d0b5e60afc122d3f0ee4786bb581a0fc7ec Mon Sep 17 00:00:00 2001 From: eks <37926645+iRedScarf@users.noreply.github.com> Date: Sat, 16 Sep 2023 14:19:17 +0800 Subject: [PATCH] fix: Set the max history messages to 9 (#438) --- .env.example | 2 ++ src/components/Generator.tsx | 3 ++- src/env.d.ts | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index a69ae47f0..b98ff44cd 100644 --- a/.env.example +++ b/.env.example @@ -12,3 +12,5 @@ PUBLIC_SECRET_KEY= SITE_PASSWORD= # ID of the model to use. https://platform.openai.com/docs/api-reference/models/list OPENAI_API_MODEL= +# Set the maximum number of historical messages used for contextual contact +PUBLIC_MAX_HISTORY_MESSAGES= diff --git a/src/components/Generator.tsx b/src/components/Generator.tsx index a0437af1f..936473caa 100644 --- a/src/components/Generator.tsx +++ b/src/components/Generator.tsx @@ -19,6 +19,7 @@ export default () => { const [isStick, setStick] = createSignal(false) const [temperature, setTemperature] = createSignal(0.6); const temperatureSetting = (value: number) => { setTemperature(value) } + const maxHistoryMessages = parseInt(import.meta.env.PUBLIC_MAX_HISTORY_MESSAGES || '9') createEffect(() => (isStick() && smoothToBottom())) @@ -89,7 +90,7 @@ export default () => { try { const controller = new AbortController() setController(controller) - const requestMessageList = [...messageList()] + const requestMessageList = messageList().slice(-maxHistoryMessages) if (currentSystemRoleSettings()) { requestMessageList.unshift({ role: 'system', diff --git a/src/env.d.ts b/src/env.d.ts index 4d60ac788..c6cf12c55 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -8,6 +8,7 @@ interface ImportMetaEnv { readonly PUBLIC_SECRET_KEY: string readonly SITE_PASSWORD: string readonly OPENAI_API_MODEL: string + readonly PUBLIC_MAX_HISTORY_MESSAGES: string; } interface ImportMeta {