import { useState } from 'react'; import { useAppContext } from '../utils/app.context'; import { CONFIG_DEFAULT, CONFIG_INFO } from '../Config'; import { isDev } from '../Config'; import StorageUtils from '../utils/storage'; type SettKey = keyof typeof CONFIG_DEFAULT; const COMMON_SAMPLER_KEYS: SettKey[] = [ 'temperature', 'top_k', 'top_p', 'min_p', 'max_tokens', ]; const OTHER_SAMPLER_KEYS: SettKey[] = [ 'dynatemp_range', 'dynatemp_exponent', 'typical_p', 'xtc_probability', 'xtc_threshold', ]; const PENALTY_KEYS: SettKey[] = [ 'repeat_last_n', 'repeat_penalty', 'presence_penalty', 'frequency_penalty', 'dry_multiplier', 'dry_base', 'dry_allowed_length', 'dry_penalty_last_n', ]; export default function SettingDialog({ show, onClose, }: { show: boolean; onClose: () => void; }) { const { config, saveConfig } = useAppContext(); // clone the config object to prevent direct mutation const [localConfig, setLocalConfig] = useState( JSON.parse(JSON.stringify(config)) ); const resetConfig = () => { if (window.confirm('Are you sure to reset all settings?')) { setLocalConfig(CONFIG_DEFAULT); } }; const handleSave = () => { saveConfig(localConfig); onClose(); }; const debugImportDemoConv = async () => { const res = await fetch('/demo-conversation.json'); const demoConv = await res.json(); StorageUtils.remove(demoConv.id); for (const msg of demoConv.messages) { StorageUtils.appendMsg(demoConv.id, msg); } onClose(); }; return (

Settings

Settings below are saved in browser's localStorage

setLocalConfig({ ...localConfig, apiKey: value }) } />