'use client' import { useContext, useEffect, useState, useCallback, ChangeEvent, } from 'react' import { fs } from '@janhq/core' import { Switch, Button, Input } from '@janhq/uikit' import ShortcutModal from '@/containers/ShortcutModal' import { toaster } from '@/containers/Toast' import { FeatureToggleContext } from '@/context/FeatureToggle' import { useSettings } from '@/hooks/useSettings' import DataFolder from './DataFolder' import FactoryReset from './FactoryReset' const Advanced = () => { const { experimentalFeature, setExperimentalFeature, ignoreSSL, setIgnoreSSL, proxy, setProxy, } = useContext(FeatureToggleContext) const [partialProxy, setPartialProxy] = useState(proxy) const [gpuEnabled, setGpuEnabled] = useState(false) const [gpuList, setGpuList] = useState([ { id: 'none', vram: null, name: 'none' }, ]) const [gpusInUse, setGpusInUse] = useState([]) const { readSettings, saveSettings, validateSettings, setShowNotification } = useSettings() const onProxyChange = useCallback( (event: ChangeEvent) => { const value = event.target.value || '' setPartialProxy(value) if (value.trim().startsWith('http')) { setProxy(value.trim()) } else { setProxy('') } }, [setPartialProxy, setProxy] ) useEffect(() => { const setUseGpuIfPossible = async () => { const settings = await readSettings() setGpuEnabled(settings.run_mode === 'gpu') setGpusInUse(settings.gpus_in_use || []) if (settings.gpus) { setGpuList(settings.gpus) } } setUseGpuIfPossible() }, [readSettings]) const clearLogs = async () => { if (await fs.existsSync(`file://logs`)) { await fs.rmdirSync(`file://logs`, { recursive: true }) } toaster({ title: 'Logs cleared', description: 'All logs have been cleared.', type: 'success', }) } const handleGPUChange = (gpuId: string) => { let updatedGpusInUse = [...gpusInUse] if (updatedGpusInUse.includes(gpuId)) { updatedGpusInUse = updatedGpusInUse.filter((id) => id !== gpuId) if (gpuEnabled && updatedGpusInUse.length === 0) { updatedGpusInUse.push(gpuId) } } else { updatedGpusInUse.push(gpuId) } setGpusInUse(updatedGpusInUse) saveSettings({ gpusInUse: updatedGpusInUse }) } return (
{/* Keyboard shortcut */}
Keyboard Shortcuts

Shortcuts that you might find useful in Jan app.

{/* Experimental */}
Experimental Mode

Enable experimental features that may be unstable tested.

{/* CPU / GPU switching */} {!isMac && (
Nvidia GPU

Enable GPU acceleration for Nvidia GPUs.

{ if (e === true) { saveSettings({ runMode: 'gpu' }) setGpuEnabled(true) setShowNotification(false) setTimeout(() => { validateSettings() }, 300) } else { saveSettings({ runMode: 'cpu' }) setGpuEnabled(false) } }} />
)} {/* Directory */} {gpuEnabled && (
{gpuList.map((gpu) => (
handleGPUChange(gpu.id)} />
))}
)} {/* Warning message */} {gpuEnabled && gpusInUse.length > 1 && (

If enabling multi-GPU without the same GPU model or without NVLink, it may affect token speed.

)} {/* Proxy */}
HTTPS Proxy

Specify the HTTPS proxy or leave blank (proxy auto-configuration and SOCKS not supported).

:@:'} value={partialProxy} onChange={onProxyChange} />
{/* Ignore SSL certificates */}
Ignore SSL certificates

Allow self-signed or unverified certificates - may be required for certain proxies.

setIgnoreSSL(e)} />
{/* Clear log */}
Clear logs

Clear all logs from Jan app.

{/* Factory Reset */}
) } export default Advanced