From 5cd4e8ea77449f73b5c30d0fecad91bc4080268c Mon Sep 17 00:00:00 2001 From: nick134 Date: Tue, 3 Jun 2025 10:14:27 +0200 Subject: [PATCH] chore: current system prompt to local storage --- app/context/ChatContext.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/context/ChatContext.tsx b/app/context/ChatContext.tsx index 52f2b1b..6952e56 100644 --- a/app/context/ChatContext.tsx +++ b/app/context/ChatContext.tsx @@ -14,6 +14,7 @@ import { Folder, useFolders } from '@/hooks/use-folders'; import { getAccessToken, storeAccessToken, processMessages } from '@/lib/utils'; const SELECTED_MODEL_KEY = 'selectedModel'; +const CURRENT_SYSTEM_PROMPT_KEY = 'currentSystemPrompt'; export interface ContextFile { id: string; @@ -112,13 +113,21 @@ export const ChatProvider: React.FC<{ children: React.ReactNode }> = ({ children return defaultModel; }; + const getSavedSystemPrompt = () => { + if (typeof window !== 'undefined') { + const savedPrompt = localStorage.getItem(CURRENT_SYSTEM_PROMPT_KEY); + return savedPrompt || DEFAULT_SYSTEM_PROMPT; + } + return DEFAULT_SYSTEM_PROMPT; + }; + const [modelSelection, setModelSelection] = useState(getSavedModel); const [availableModels, setAvailableModels] = useState(defaultModels); const [isLoadingModels, setIsLoadingModels] = useState(true); const [modelError, setModelError] = useState(null); // Config state - const [systemPrompt, setSystemPrompt] = useState(DEFAULT_SYSTEM_PROMPT); + const [systemPrompt, setSystemPrompt] = useState(getSavedSystemPrompt); const [temperature, setTemperature] = useState(0.7); const [topP, setTopP] = useState(0.95); const [isConfigOpen, setIsConfigOpen] = useState(false); @@ -182,6 +191,13 @@ export const ChatProvider: React.FC<{ children: React.ReactNode }> = ({ children } }, [modelSelection]); + // Save system prompt to localStorage + useEffect(() => { + if (typeof window !== 'undefined' && systemPrompt !== undefined) { + localStorage.setItem(CURRENT_SYSTEM_PROMPT_KEY, systemPrompt); + } + }, [systemPrompt]); + // Effect hooks useEffect(() => { const init = async () => {