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 {